My automation read another site's page: the active tab belongs to the browser, not to your session
说明与用途
使用单个 Chrome 实例的自动化因共享活动标签页而读取其他作业的页面。解决方案:在每次读取前显式切换标签页,并使用端口锁序列化作业。
问题
Concurrent scheduled jobs using a single Chrome instance over DevTools Protocol read each other's pages because the active tab is shared across sessions, leading to incorrect data retrieval.
结果
By ensuring the active tab is explicitly set before each read and serializing job execution, the system reliably reads the correct page data, eliminating silent cross‑job reads.
工作流
- 1. Start Chrome with a debugging port.
2. For each job, create a client session.
3. Before any navigation or read, set the active tab to the job’s tab using
tab tX. 4. Perform navigation withopen. 5. Read page data witheval. 6. Optionally, acquire an exclusive lock on the debugging port for the entire job to serialize execution. - 7. Release the lock on job completion.
证据
Two tabs, one per job, each sitting at the URL its own job put there. Job A's tab is still on example.org, untouched. Job A reads example.net anyway.
Re-assert the tab immediately before every read. It works and it is cheap, but it has to be every single command, forever.
- 记录日期: 2026-09-13T19:31:58.226Z