review: apply external consultant editorial fixes and update audit tracker to 74/91 approved
Deploy / build (push) Successful in 28s
Deploy / build (push) Successful in 28s
This commit is contained in:
1 parent
4e64bfc9ae
commit
a7e683100b
56 files changed
+14496
-23169
No files matched your search
@@ -7,6 +7,7 @@ tags: [docker, chrome, cdp, persistence, synology, self-hosting]
|
||||
ogImage: /og/zh-why-chrome-forgets-its-tabs-in-a-container.jpg
|
||||
banner: /banners/why-chrome-forgets-its-tabs-in-a-container.jpg
|
||||
draft: false
|
||||
dynamicCta: true
|
||||
---
|
||||
|
||||
我在 NAS 上的 Docker 容器里跑着一个真正的 Google Chrome。它不是爬虫实例,也不是截图服务 —— 是我真的在用的浏览器:登录着那些绝不该交给无头机器人的账号,可以从任何设备通过网页桌面看着它操作,需要自动化的时候还能用 Chrome DevTools Protocol (CDP) 驱动它。
|
||||
@@ -119,6 +120,9 @@ Chrome 确实退出了 —— 然后桌面会话在几秒内又把它拉了起
|
||||
|
||||
这就是一段从镜像的容器初始化钩子拉起的后台脚本。我实际在跑的版本,去掉无关部分后是这样:
|
||||
|
||||
<details>
|
||||
<summary>tabs_keeper.py — 标签页恢复与定时快照脚本(42 行)</summary>
|
||||
|
||||
```python
|
||||
#!/usr/bin/env python3
|
||||
"""Restore last session's tabs on start, then snapshot open tabs every 60s."""
|
||||
@@ -163,6 +167,8 @@ while True:
|
||||
os.replace(tmp, STORE) # atomic; a kill can't truncate it
|
||||
```
|
||||
|
||||
</details>
|
||||
|
||||
两个设计选择值得抄走:
|
||||
|
||||
- **只在浏览器确实空空如也时才恢复。** 万一将来某个 Chrome 版本自己会恢复标签页,这段脚本就会让路,而不是把每个标签页再复制一遍。
|
||||
@@ -217,7 +223,7 @@ chrome-relay:
|
||||
docker restart chrome && docker restart chrome-relay # order matters
|
||||
```
|
||||
|
||||
上面那条健康检查的作用,就是把这种静默故障变成一个看得见的 `unhealthy`。如果你打算自己驱动容器里的浏览器,客户端那一侧我单独写过一篇:[Scraping a Bot-Walled Marketplace With a Warm Browser Session](/posts/scraping-bot-walled-marketplace-warm-browser-session/)。
|
||||
上面那条健康检查的作用,就是把这种静默故障变成一个看得见的 `unhealthy`。如果你打算自己驱动容器里的浏览器,客户端那一侧我单独写过一篇:[《用预热的浏览器会话抓取带反爬的交易平台》](/posts/zh/scraping-bot-walled-marketplace-warm-browser-session/)。
|
||||
|
||||
## 如果重来一次
|
||||
|
||||
|
||||
Reference in new issue
Block a user