fix(extension): inject the content script into documents that were already open
why
Chrome adds manifest content scripts only to documents created after an extension loads. When the extension was loaded into a browser with pages already open, every locator operation timed out on those pages until reloaded. Removing or disabling the extension also leaves the old copy's worlds in open tabs. Some still passed the readiness check, and chrome.runtime.onInstalled does not fire when the extension is enabled again.
what changed
- Whenever the service worker starts, it injects the content script into every frame of each open http(s) or file tab. Worker start covers install, reload, update and re-enable. A second run in the same world does nothing.
- Injection failures go to the worker console through
onError. - The readiness check also requires
chrome.runtime.id, which Chrome removes from leftover worlds; the timeout error reports whether it is present. - A build test checks that the built worker calls the injection at worker start.
test plan
- Unit tests for the injection and its errors, the readiness check against a leftover world, and a second content-script run.
- Real Chrome with pages opened before the load: navigation, evaluation, screenshots, snapshots, filling and typing, and clicks (by coordinates, in iframes, in open and closed shadow roots) all pass 10/10 on existing pages, after reload, in a new tab, after uninstall then load, after a worker restart, and after disable then enable.
Summary by cubic
Fixes locator operations timing out on pages that were already open when the extension was loaded into a running browser, including after remove/reload and disable/enable cycles.
Chrome adds manifest content scripts only to documents created after the extension loads, so every worker start now injects the content script into every frame of each open http(s) or file tab. Worker start covers install, reload, update, and re-enable (which onInstalled misses); rerunning the content script in a live world is a no-op, and injection failures are logged to the worker console. The readiness check also requires chrome.runtime.id, which Chrome removes from worlds left behind by an unloaded or disabled copy of the extension, and the readiness timeout error now reports it.