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
Webview Service Worker Error in registration due to invalid document state #125993
bugIssue identified by VS Code Team member as probable bugchromiumIssues and items related to Chromiumpapercut 🩸A particularly annoying issue impacting someone on the teamupstreamIssue identified as 'upstream' component related (exists outside of VS Code)webviewWebview issues
Error loading webview: Error: Could not register service workers: InvalidStateError: Failed to register a ServiceWorker: The document is in an invalid state..
Reacted by Stephen Bungert, Roberto Obando, Martin Troiber, Andrew Gree, NightRare, Sweidan Omár, Krushna Joshi, avin-shum, Sean Colsen, Neal Fennimore and 129 more
Reacted by mrariful786, Bora Keçeci, Tony Li and Torge Rosendahl
I'm the author of Git Graph, which is one of the extensions that is affected by this (as my extension leverages Visual Studio Code Webview's for it's core user interface). This Service Worker error occurs within Visual Studio Code's Webview implementation, so it affects all extensions that use Webviews. It prevents the Webview from loading, for all the affected users.
This bug first appeared in Visual Studio Code 1.56.0, and only occurred for numerous Linux users (but definitely not all). Reports of this issue lasted about a week or so, so I assumed it had been fixed in one of the 1.56.x patches. However, with the release of Visual Studio Code 1.57.0, I've now had reports that this issue is occurring again.
Reacted by Antonino Ingargiola, Stephen Bungert, Murat YAPICI, Roberto Obando, Andrew Gree, deef, avin-shum, Sean Colsen, Kun Ren, Eric.yue and 47 more
For information: restarting the PC solved the issue for me ATM.
So, it may be related to some sort of cache that is cleared after reboot?
This issue appeared for me twice, every time after a vs code update. The first time updating from 1.55 to 1.56 and now updating from 1.56 to 1.57. I don't know if the fix on 1.56 happened after a reboot as well.
Reacted by Murat YAPICI, heartnheart, kuisong zheng, Ivan Fedorusov, Jun Wu, Casey, Bestyo, Thom Ives, pjboro, Carlos Natalino and 24 more
Reacted by Stephen Bungert, Marijn, Ivan Fedorusov, Luca Bertelli, Bianca Lujan, Daniel Byrne, rztz, Lubomir and Kristopher Johnson
Reacted by Edith Puclla, Ivan Fedorusov, sabaimran, André Goulart Nogueira, Sgilgen, Carlos Arce, Jan Groth, Thom Ives, pjboro, Victor Ferreira da Silva and 14 more
Reacted by Mátyás Komáromi, Henrik Feldt, John Palmer, ferencdg, Gu Wang, Mike Hilgendorf, António Cruz Júnior, Tamado Ramot Sitohang, Henry Johnson, Orestis Ousoultzoglou and 34 more
Rebooting is not an option for me, and I love the Git Graph extension. As well as ability to view images and other neats within vscode tabs. Please consider re-opening and fixing. Thanks
Had the same issue today with the latest VSCode version.
Note that you really need to kill all VSCode processes as a workaround.
Even though I am on Linux and run VSCode in a systemd cgroup (service), killing that was not enough, since apparently there's some bug now in using code -w <file>, and a zombie code process outside the cgroup had hung (requiring SIGKILL).
This provides a controlled before/after comparison: resetting VS Code's shared Service Worker state was the only relevant change.
Recurrence and retained artifacts
This has happened at least twice. I retained two Service Worker directories from separate recoveries, sized 84 KB and 60 KB.
The small sizes suggest this is not simply caused by unbounded cache growth. The latest saved database contains registrations for VS Code webview origins, but its LevelDB logs contain no explicit corruption message.
I did not capture the webview Developer Tools console before recovery, so I cannot confirm the exact InvalidStateError string.
I retained the failing Service Worker directory locally and can extract additional non-sensitive metadata if useful.
Maybe this helps to narrow it down: the stuck state seems to be scoped to individual webview origins, not something that clears globally when VS Code updates.
Each webview's origin is derived from base32(sha256({parentOrigin, salt})), where salt is a UUID minted once per (extensionId, viewType) and stored in memento/mainThreadWebviewPanel.origins. I decoded that against the local Service Worker/Database/*.log on a real machine (1.135.0, so the current service-worker.js is VERSION = 6), and some origins were cleanly on v=6, while others from the same extension were still on v=4 or v=5 and just never moved forward. That lines up with what people keep describing here: some extensions/views work fine while others don't, or something that worked breaks again after a later update.
I also tried to see if a webview could just unregister and re-register itself, but getRegistration()/getRegistrations() hit the same guard that register() does, so a document sitting on a wedged origin cannot list its own registrations. The only thing that actually works is fully quitting VS Code and wiping the whole Service Worker folder, which is a pretty blunt instrument since it throws away every origin's state, not just the broken one.
Given the problem looks per-origin, and session.clearStorageData({storages: ['serviceworkers','cachestorage']}) already exists, would something like a Developer: Reset Webview Service Worker command be doable? Clear just the current webview's origin and reload it. That'd give people an actual recovery path instead of "delete a folder and hope."
Have the same problem - i bet would be reasonable to create at-least some retry mechanism with cache cleanup until the normal solution is found, beacause it eats up TOO MUCH time from all people around the globe using VSCode, so something should be done immediately.
Here's what i have: "Error loading webview: Error: Could not register service worker: InvalidStateError: Failed to register a ServiceWorker: The document is in an invalid state.."
Sandbox attributes: two places, neither mutates a live frame.
webviewElement.ts:417-423 - _createElement() does element.sandbox.add('allow-scripts', 'allow-same-origin', ...). It builds a fresh iframe, and as a method it is called from exactly one place: the constructor
(webviewElement.ts:203). So it runs before the element is inserted or given a src.
That matches what you found in 2021 - nothing re-runs it.
index.html:1029-1042 - the inner content frame. A new iframe (newFrame) is
created per content update and gets setAttribute('sandbox', ...) before it is
appended. Also a fresh frame, not a mutation of one that already loaded.
But there is a path that navigates an existing frame, which I think is closer to your
case 1 ("the page loading the service worker is being navigated away during the
registration step"):
webviewElement.ts:477-511 - mountTo() re-uses the element built in the constructor:
webviewElement.ts:483 mints a new _mountId
webviewElement.ts:487 calls _initElement(), which does this.element!.setAttribute('src', ...) (webviewElement.ts:474) - that is a navigation of the already-live iframe
webviewElement.ts:511 then does element.appendChild(this.element), i.e. a re-parent - and the codebase itself notes that re-parenting destroys an iframe's
contents (overlayWebview.ts:123)
mountId is passed as a URL parameter (webviewElement.ts:453), so each re-mount
produces a distinct shell document.
What I have not established. I can't show that any of this runs while a registration
is in flight for an ordinary extension webview. The mountTo callers I can find are
built-in webviews plus one chat path:
gettingStarted.ts:599, 602, 605
imageCarouselEditor.ts:438
mainThreadCodeInsets.ts:47
webviewElement.ts:657 (reinitializeAfterDismount; only production caller is chatMcpAppModel.ts:203)
So this is not a proposed cause - it is only an answer to the question you asked, listing
where the code can navigate or re-parent a live webview iframe. I have not reproduced the
failure locally (Windows, VS Code 1.134.0), so please read this as a map of the code
rather than a diagnosis.
Several earlier comments observed that the old window keeps working while new windows fail after an update (e.g. #125993 (comment)). I tracked down the mechanism for one Linux case.
On NixOS 26.11, VS Code 1.139.1 (Electron 43.6.0) remained running after a Home Manager update to 1.140.0 (Electron 43.7.3); both use Chromium 150.0.7871.250. The two main processes used the same user-data directory but different version-scoped IPC sockets, so the new one did not detect the old instance. The old process held the POSIX write lock on Service Worker/Database/LOCK.
Controlled test with a separate copy of the Service Worker data and webview origin state:
1.139.1 alone: Git Graph 1.30.0 and built-in Markdown Preview both work.
Start 1.140.0 against that same copy while 1.139.1 remains running: both webviews fail in 1.140.0 with this issue's InvalidStateError and still work in 1.139.1. Before either webview is opened, the new process logs service_worker_storage.cc:1814 Failed to delete the database: Database IO error.
Exit both test processes and start 1.140.0 alone against the same data, without deleting Service Worker state: both webviews work.
This is the cross-version session-data overlap described in #335216. That PR was closed in favor of #336253, but #336253 checks the Inno Setup update mutex, which only runs on Windows. Package-manager updates on Linux that leave the old process running don't go through that path, so this trigger still appears to be unaddressed there.
On macOS/Linux the main IPC socket name only uses version.substr(0, 4) (createStaticIPCHandle), so this overlap happens when an update crosses a boundary like 1.139 → 1.140, but not 1.140 → 1.141. That may explain why it appears intermittently after updates.
After all VS Code processes (old and new) had exited, restarting 1.140.0 was enough; deleting the Service Worker directory was not needed.
bugIssue identified by VS Code Team member as probable bugchromiumIssues and items related to Chromiumpapercut 🩸A particularly annoying issue impacting someone on the teamupstreamIssue identified as 'upstream' component related (exists outside of VS Code)webviewWebview issues
Activity
vscodebot commentedon Jun 11, 2021
(Experimental duplicate detection)
Thanks for submitting this issue. Please also check if it is already covered by an existing one, like:
mhutchie commentedon Jun 11, 2021
I'm the author of Git Graph, which is one of the extensions that is affected by this (as my extension leverages Visual Studio Code Webview's for it's core user interface). This Service Worker error occurs within Visual Studio Code's Webview implementation, so it affects all extensions that use Webviews. It prevents the Webview from loading, for all the affected users.
mhutchie/vscode-git-graph#508 includes an image of a stack trace of this error in the first comment.
This bug first appeared in Visual Studio Code 1.56.0, and only occurred for numerous Linux users (but definitely not all). Reports of this issue lasted about a week or so, so I assumed it had been fixed in one of the 1.56.x patches. However, with the release of Visual Studio Code 1.57.0, I've now had reports that this issue is occurring again.
Looping in Matt Bierner (@mjbvz) - Are you able to provide some assistance?
[-]VS code 1.57.0 breaks gitgraph extension 1.30.0[/-][+]Webview Service Worker Error (Linux)[/+]tritemio commentedon Jun 11, 2021
For information: restarting the PC solved the issue for me ATM.
So, it may be related to some sort of cache that is cleared after reboot?
This issue appeared for me twice, every time after a vs code update. The first time updating from 1.55 to 1.56 and now updating from 1.56 to 1.57. I don't know if the fix on 1.56 happened after a reboot as well.
sketchbuch commentedon Jun 11, 2021
I also have this issue on Linux, be good to get a fix soon.
Update: Rebooting fixed the issue, thanks Antonino Ingargiola (@tritemio)
joyceerhl commentedon Jun 11, 2021
I'm on Windows and can repro this error in a new blank Jupyter notebook.
mjbvz commentedon Jun 11, 2021
Duplicate of #122951
grandrew commentedon Jul 14, 2021
Rebooting is not an option for me, and I love the Git Graph extension. As well as ability to view images and other neats within vscode tabs. Please consider re-opening and fixing. Thanks
eduncan911 commentedon Jul 21, 2021
Matt Bierner (@mjbvz) please reopen this issue. Robo (@deepak1556) just stated in #122951 that Linux users are a separate issue, even though it still has the Linux tag.
171 remaining items
jaens commentedon Jan 31, 2026
Had the same issue today with the latest VSCode version.
Note that you really need to kill all VSCode processes as a workaround.
Even though I am on Linux and run VSCode in a systemd cgroup (service), killing that was not enough, since apparently there's some bug now in using
code -w <file>, and a zombiecodeprocess outside the cgroup had hung (requiring SIGKILL).(process tree:)
fix(vscode): enhance SW InvalidState retry with 30s deadline and expo…
MaddyGuthridge commentedon Mar 29, 2026
This issue is incredibly frustrating. God forbid I want to preview a markdown document.
fix(vscode): retry webview load on service worker failure
AlexanderZagaynov commentedon Jul 10, 2026
Additional Linux case: VS Code 1.128.0, webview recovers only after resetting Service Worker state
I am seeing a recurring blank Codex webview on Linux. The activity-bar icon blinks when selected, but the panel never renders.
Environment
fc3def6774c76082adf699d366f31a557ce5573fopenai.chatgpt26.707.31428Broken startup
The extension host and its backend initialized normally:
However, the webview never logged either of its normal renderer-startup markers:
There was no extension reinstall, authentication change, configuration change, or modification to
~/.codex.Controlled recovery
I fully stopped all VS Code processes and moved only:
to a backup. I then restarted the same VS Code build, extension build, profile, and workspace.
The webview immediately initialized successfully:
This provides a controlled before/after comparison: resetting VS Code's shared Service Worker state was the only relevant change.
Recurrence and retained artifacts
This has happened at least twice. I retained two Service Worker directories from separate recoveries, sized 84 KB and 60 KB.
The small sizes suggest this is not simply caused by unbounded cache growth. The latest saved database contains registrations for VS Code webview origins, but its LevelDB logs contain no explicit corruption message.
I did not capture the webview Developer Tools console before recovery, so I cannot confirm the exact
InvalidStateErrorstring.I retained the failing Service Worker directory locally and can extract additional non-sensitive metadata if useful.
szarnekow commentedon Aug 30, 2026
Maybe this helps to narrow it down: the stuck state seems to be scoped to individual webview origins, not something that clears globally when VS Code updates.
Each webview's origin is derived from
base32(sha256({parentOrigin, salt})), where salt is a UUID minted once per (extensionId, viewType) and stored in memento/mainThreadWebviewPanel.origins. I decoded that against the local Service Worker/Database/*.log on a real machine (1.135.0, so the current service-worker.js is VERSION = 6), and some origins were cleanly on v=6, while others from the same extension were still on v=4 or v=5 and just never moved forward. That lines up with what people keep describing here: some extensions/views work fine while others don't, or something that worked breaks again after a later update.I also tried to see if a webview could just unregister and re-register itself, but getRegistration()/getRegistrations() hit the same guard that register() does, so a document sitting on a wedged origin cannot list its own registrations. The only thing that actually works is fully quitting VS Code and wiping the whole Service Worker folder, which is a pretty blunt instrument since it throws away every origin's state, not just the broken one.
Given the problem looks per-origin, and session.clearStorageData({storages: ['serviceworkers','cachestorage']}) already exists, would something like a
Developer: Reset Webview Service Worker commandbe doable? Clear just the current webview's origin and reload it. That'd give people an actual recovery path instead of "delete a folder and hope."dnch13 commentedon Aug 31, 2026
Have the same problem - i bet would be reasonable to create at-least some retry mechanism with cache cleanup until the normal solution is found, beacause it eats up TOO MUCH time from all people around the globe using VSCode, so something should be done immediately.
Here's what i have: "Error loading webview: Error: Could not register service worker: InvalidStateError: Failed to register a ServiceWorker: The document is in an invalid state.."
Markdown in the transcript, and a panel that lands where the work is
new-tonAA commentedon Oct 8, 2026
Answering Robo (@deepak1556)'s question in this issue -
#125993 (comment) - "Are there
other places where we edit the sandbox properties?"
Line numbers are for VS Code 1.134.0 @ 110a328.
Sandbox attributes: two places, neither mutates a live frame.
webviewElement.ts:417-423-_createElement()doeselement.sandbox.add('allow-scripts', 'allow-same-origin', ...). It builds a freshiframe, and as a method it is called from exactly one place: the constructor(
webviewElement.ts:203). So it runs before the element is inserted or given asrc.That matches what you found in 2021 - nothing re-runs it.
index.html:1029-1042- the inner content frame. A newiframe(newFrame) iscreated per content update and gets
setAttribute('sandbox', ...)before it isappended. Also a fresh frame, not a mutation of one that already loaded.
But there is a path that navigates an existing frame, which I think is closer to your
case 1 ("the page loading the service worker is being navigated away during the
registration step"):
webviewElement.ts:477-511-mountTo()re-uses the element built in the constructor:webviewElement.ts:483mints a new_mountIdwebviewElement.ts:487calls_initElement(), which doesthis.element!.setAttribute('src', ...)(webviewElement.ts:474) - that is anavigation of the already-live iframe
webviewElement.ts:511then doeselement.appendChild(this.element), i.e. are-parent - and the codebase itself notes that re-parenting destroys an iframe's
contents (
overlayWebview.ts:123)mountIdis passed as a URL parameter (webviewElement.ts:453), so each re-mountproduces a distinct shell document.
What I have not established. I can't show that any of this runs while a registration
is in flight for an ordinary extension webview. The
mountTocallers I can find arebuilt-in webviews plus one chat path:
So this is not a proposed cause - it is only an answer to the question you asked, listing
where the code can navigate or re-parent a live webview iframe. I have not reproduced the
failure locally (Windows, VS Code 1.134.0), so please read this as a map of the code
rather than a diagnosis.
hal1278 commentedon Oct 16, 2026
Several earlier comments observed that the old window keeps working while new windows fail after an update (e.g. #125993 (comment)). I tracked down the mechanism for one Linux case.
On NixOS 26.11, VS Code 1.139.1 (Electron 43.6.0) remained running after a Home Manager update to 1.140.0 (Electron 43.7.3); both use Chromium 150.0.7871.250. The two main processes used the same user-data directory but different version-scoped IPC sockets, so the new one did not detect the old instance. The old process held the POSIX write lock on
Service Worker/Database/LOCK.Controlled test with a separate copy of the Service Worker data and webview origin state:
InvalidStateErrorand still work in 1.139.1. Before either webview is opened, the new process logsservice_worker_storage.cc:1814 Failed to delete the database: Database IO error.This is the cross-version session-data overlap described in #335216. That PR was closed in favor of #336253, but #336253 checks the Inno Setup update mutex, which only runs on Windows. Package-manager updates on Linux that leave the old process running don't go through that path, so this trigger still appears to be unaddressed there.
On macOS/Linux the main IPC socket name only uses
version.substr(0, 4)(createStaticIPCHandle), so this overlap happens when an update crosses a boundary like 1.139 → 1.140, but not 1.140 → 1.141. That may explain why it appears intermittently after updates.After all VS Code processes (old and new) had exited, restarting 1.140.0 was enough; deleting the
Service Workerdirectory was not needed.fix(webview): reduce service-worker registration races