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