Repository navigation
fix(contexts): detach nested service worker sessions so Chrome can stop them - #666
Merged
Merged
Conversation
…op them A page's service worker is auto-attached twice, at the browser level and under the page session. The nested session was detached on the browser client, Chrome answered "No session with given id", so it stayed attached. Detach on the parent session, after the resume is acknowledged. Chrome only acknowledges it once every session that paused the worker resumed it, so this runs on its own thread to not block the other attach event.
route
force-pushed
the
fix/service-worker-detach
branch
from
October 21, 2026 17:13
f494889 to
5bfcba1
Compare
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment
Add this suggestion to a batch that can be applied as a single commit.This suggestion is invalid because no changes were made to the code.Suggestions cannot be applied while the pull request is closed.Suggestions cannot be applied while viewing a subset of changes.Only one suggestion per line can be applied in a batch.Add this suggestion to a batch that can be applied as a single commit.Applying suggestions on deleted lines is not supported.You must change the existing code in this line in order to create a valid suggestion.Outdated suggestions cannot be applied.This suggestion has been applied or marked resolved.Suggestions cannot be applied from pending reviews.Suggestions cannot be applied on multi-line comments.Suggestions cannot be applied while the pull request is queued to merge.Suggestion cannot be applied right now. Please check back later.
When a page registers a service worker, Chrome auto-attaches it twice: once at the browser level and once nested under the page session, because every page session re-arms
Target.setAutoAttach. Ferrum detaches service workers so Chrome can terminate them, but it sentTarget.detachFromTargetfor the nested session on the browser client. Chrome answered "No session with given id", the error was rescued, and the worker stayed attached and alive for the browser's lifetime.Fix
parent), like Puppeteer's#silentDetachand Playwright'sCRSession#detachdo.Runtime.runIfWaitingForDebuggerreply before detaching. Otherwise the detach overtakes the resume and the worker stays paused forever, sonavigator.serviceWorker.register()hangs.silent_detachruns resume and detach on a short-lived thread instead.Test
spec/worker_spec.rb: "detaches from them so Chrome can terminate them" registers a service worker and waits untilTarget.getTargetsreports it as not attached. It fails without the fix.