fix(chromium): emit serviceworker event on MV3 SW stop/restart lifecycle#39476
Open
shairoth12 wants to merge 5 commits intomicrosoft:mainfrom
Open
fix(chromium): emit serviceworker event on MV3 SW stop/restart lifecycle#39476shairoth12 wants to merge 5 commits intomicrosoft:mainfrom
shairoth12 wants to merge 5 commits intomicrosoft:mainfrom
Conversation
Author
|
@microsoft-github-policy-service agree |
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.
Fixes #39475
Problem
When a Manifest V3 extension's service worker stops and restarts, Chrome reuses the same CDP target ID. This means no
Target.attachedToTargetevent is fired, so Playwright never creates a newCRServiceWorkerinstance and the'serviceworker'event is never emitted on theBrowserContext. The original Worker reference remains incontext.serviceWorkers()with a stale execution context, causing any subsequentevaluate()to throw.Fix
Restart detection is now handled at the execution-context level inside
CRServiceWorker, which already holds the CDP session for the reused target.Two new fields track the current context lifecycle:
_currentContextId— the execution context ID currently in use_currentContextDestroyed— set totruebyRuntime.executionContextDestroyedorRuntime.executionContextsClearedThe
Runtime.executionContextCreatedlistener (previouslysession.once) is now persistent. When a new context arrives after the previous one was destroyed,_handleRestart()is called:Worker.Events.Close, closes its scope, removes it frombrowser._serviceWorkers) — without disposing the CDP session, since the new worker reuses itCRServiceWorkeris created with the same session and target ID'serviceworker'event is emitted on theBrowserContextA same-ID re-send from
Runtime.enable(context still alive) is correctly ignored via the_currentContextDestroyedflag.Changes
packages/playwright-core/src/server/chromium/crServiceWorker.ts— restart detection and handlingpackages/playwright-core/src/server/chromium/crBrowser.ts— passtargetIdtoCRServiceWorkerconstructortests/library/chromium/extensions.spec.ts— new test for stop/restart lifecycle; timing fix to registerwaitForEventbefore triggering the cycledocs/src/chrome-extensions-js-python.md— new "Testing extension reload" sectiondocs/src/api/class-browsercontext.md— updatedserviceworkerevent docs with timing guidance