You signed in with another tab or window. Reload to refresh your session.You signed out in another tab or window. Reload to refresh your session.You switched accounts on another tab or window. Reload to refresh your session.Dismiss alert
{{ message }}
Repository navigation
[Bug]: serviceworker event never emitted when a Manifest V3 extension's service worker stops and restarts #39475
Clone the repo and follow the README to install and run
The test launches a persistent context with a simple MV3 extension
It grabs the initial service worker and records a startTime global from the SW's scope
It forces a stop → start cycle via the ServiceWorker CDP domain
It waits for a new serviceworker event (registered before the stop/start)
It evaluates startTime in the new worker to confirm a fresh context
Expected behavior
context.waitForEvent('serviceworker') resolves with a new Worker object after the stop/start cycle, and evaluating in it returns a startTime greater than the original.
Actual behavior
waitForEvent('serviceworker') times out — the event is never emitted. The original Worker reference is still in context.serviceWorkers() but its execution context is stale; any evaluate() call throws.
Additional context
Chrome reuses the same CDP target ID when a Manifest V3 service worker restarts, so no Target.attachedToTarget event is fired and Playwright never learns a new worker exists. This is reproducible with an explicit CDP stop/start cycle as well as with chrome.runtime.reload().
What's the actual usecase for this? I don't think we expect anyone to restart a service worker through custom CDP commands. I'd assume you have some other usecase that does not involve it?
About the fix: why would you prefer waitForEvent('serviceworker') to trigger, and resolve with a new Worker instance? I think it would be easier to preserve the Worker object and just make sure evaluate() is stalling while the service worker is being reloaded. WDYT?
The actual use case is MV3's natural lifecycle - Chrome suspends the background service worker after ~30s of inactivity and restarts it when an event comes in (navigation, message, alarm, etc.). After a restart, the old worker handle is stale and no new 'serviceworker' event arrives, so there's no way to get a live one. This was reported a couple of times before (#26958, #27015).
The CDP commands in the test are just to reproduce it fast - there's no Chromium flag to shorten the 30s timeout. I used ServiceWorker.stopWorker specifically (not Target.closeTarget) because it keeps the same target alive, which is what Chrome does during natural idle suspension. Target.closeTarget closes the target entirely and Chrome issues a new Target.attachedToTarget on restart, which Playwright already handles fine.
On the fix - you're right, stalling evaluate() and keeping the same Worker object makes much more sense. Should I go ahead and update the PR to make it work that way?
Activity
dgozman commentedon Mar 2, 2026
Shai Roth (@shairoth12) Thank you for the issue and the PR!
What's the actual usecase for this? I don't think we expect anyone to restart a service worker through custom CDP commands. I'd assume you have some other usecase that does not involve it?
About the fix: why would you prefer
waitForEvent('serviceworker')to trigger, and resolve with a newWorkerinstance? I think it would be easier to preserve theWorkerobject and just make sureevaluate()is stalling while the service worker is being reloaded. WDYT?shairoth12 commentedon Mar 2, 2026
Dmitry Gozman (@dgozman) Thank you for the quick response 🙂
The actual use case is MV3's natural lifecycle - Chrome suspends the background service worker after ~30s of inactivity and restarts it when an event comes in (navigation, message, alarm, etc.). After a restart, the old worker handle is stale and no new
'serviceworker'event arrives, so there's no way to get a live one. This was reported a couple of times before (#26958, #27015).The CDP commands in the test are just to reproduce it fast - there's no Chromium flag to shorten the 30s timeout. I used
ServiceWorker.stopWorkerspecifically (notTarget.closeTarget) because it keeps the same target alive, which is what Chrome does during natural idle suspension.Target.closeTargetcloses the target entirely and Chrome issues a newTarget.attachedToTargeton restart, which Playwright already handles fine.On the fix - you're right, stalling
evaluate()and keeping the sameWorkerobject makes much more sense. Should I go ahead and update the PR to make it work that way?dgozman commentedon Mar 3, 2026
Shai Roth (@shairoth12) Thank you for the explanation, that makes sense.
Yep, that would be great.
shairoth12 commentedon Mar 5, 2026
Dmitry Gozman (@dgozman) I've updated the PR with same-
Worker/ stalling approach (also updated the PR description).