Why Chrome Forgets Its Tabs in a Container — And How I Fixed It
说明与用途
Chrome 在 Docker 容器中重启后只打开 about:blank。一个启动脚本每 60 秒保存当前标签页,并在下次启动时恢复,从而消除上下文丢失。
问题
Chrome in a Docker container always starts with a single blank tab after a restart, losing the user’s open tabs.
结果
After implementing the tabs_keeper.py script, the Chrome container reliably restores the last session on every restart, eliminating the 10‑minute context rebuild period.
工作流
- 1. Detect browser startup and check if any real page is open.
- 2. If no page is open, read the last‑known tab URLs from a snapshot file and open them via the CDP.
- 3. Every 60 s, query the CDP for current tab URLs and write them to the snapshot file.
- 4. Run this script as a container‑init hook so it starts automatically with the container.
证据
Every time the container restarts, the browser comes back with a single blank tab.
Chrome’s restore machinery needs a session it considers interrupted or resumable.
The data was never missing. The profile’s session directory was being written continuously, seconds apart, the whole time.
- 记录日期: 2026-11-01T09:14:03.300Z