Skip to content

Webview Service Worker Error in registration due to invalid document state #125993

Open

Description

Does this issue occur when all extensions are disabled?: No

  • VS Code Version:
Version: 1.57.0
Commit: b4c1bd0a9b03c749ea011b06c6d2676c8091a70c
Date: 2021-06-09T17:18:42.895Z
Electron: 12.0.9
Chrome: 89.0.4389.128
Node.js: 14.16.0
V8: 8.9.255.25-electron.0
OS: Linux x64 5.11.0-18-generic snap
  • OS Version: Ubuntu 21.04

Steps to Reproduce:

  1. Update to 1.57
  2. GitGraph extension stops working

The gitgraph extension shows this error:

Error loading webview: Error: Could not register service workers: InvalidStateError: Failed to register a ServiceWorker: The document is in an invalid state..

Activity

  1. vscodebot commented on Jun 11, 2021

    @vscodebot

    (Experimental duplicate detection)
    Thanks for submitting this issue. Please also check if it is already covered by an existing one, like:

  2. mhutchie commented on Jun 11, 2021

    @mhutchie

    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?

  3. changed the title [-]VS code 1.57.0 breaks gitgraph extension 1.30.0[/-] [+]Webview Service Worker Error (Linux)[/+] on Jun 11, 2021
  4. tritemio commented on Jun 11, 2021

    @tritemio
    Author

    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.

  5. sketchbuch commented on Jun 11, 2021

    @sketchbuch

    I also have this issue on Linux, be good to get a fix soon.

    Update: Rebooting fixed the issue, thanks Antonino Ingargiola (@tritemio)

  6. joyceerhl commented on Jun 11, 2021

    @joyceerhl
    Contributor

    I'm on Windows and can repro this error in a new blank Jupyter notebook.

    image

  7. mjbvz commented on Jun 11, 2021

    @mjbvz
    Contributor

    Duplicate of #122951

  8. added
    *duplicate
    on Jun 11, 2021
  9. grandrew commented on Jul 14, 2021

    @grandrew

    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

  10. eduncan911 commented on Jul 21, 2021

    @eduncan911

    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.

  11. 171 remaining items

  12. jaens commented on Jan 31, 2026

    @jaens

    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).

    (process tree:)

    \_ /usr/share/code/code -w --waitMarkerFilePath /tmp/U6r5u4r5
    |   \_ [code] <defunct>
    |   \_ [code] <defunct>
    |   \_ [code] <defunct>
    |   \_ [code] <defunct>
    |   \_ [code] <defunct>
    
  13. MaddyGuthridge commented on Mar 29, 2026

    @MaddyGuthridge

    This issue is incredibly frustrating. God forbid I want to preview a markdown document.

    Image
  14. AlexanderZagaynov commented on Jul 10, 2026

    @AlexanderZagaynov

    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

    • Fedora Silverblue 44
    • Kernel 7.1.3-200.fc44.x86_64
    • VS Code 1.128.0
    • Commit fc3def6774c76082adf699d366f31a557ce5573f
    • Architecture: x64
    • Webview provider: openai.chatgpt 26.707.31428

    Broken startup

    The extension host and its backend initialized normally:

    Activating Codex extension
    Spawning codex app-server
    Initialize received id=1
    

    However, the webview never logged either of its normal renderer-startup markers:

    React root render requested
    app routes mounted
    

    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:

    ~/.config/Code/Service Worker
    

    to a backup. I then restarted the same VS Code build, extension build, profile, and workspace.

    The webview immediately initialized successfully:

    Activating Codex extension
    Initialize received id=1
    React root render requested windowType=extension
    app routes mounted
    

    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.

  15. szarnekow commented on Aug 30, 2026

    @szarnekow

    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."

  16. dnch13 commented on Aug 31, 2026

    @dnch13

    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.."

  17. new-tonAA commented on Oct 8, 2026

    @new-tonAA

    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() 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.

  18. hal1278 commented on Oct 16, 2026

    @hal1278

    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. 1.139.1 alone: Git Graph 1.30.0 and built-in Markdown Preview both work.
    2. 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.
    3. 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.

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment

Metadata

Metadata

Labels

bugchromiumpapercut 🩸upstreamwebview

Type

No type

Projects

No projects

    Relationships

    None yet

    Development

    No branches or pull requests

    Issue actions