Error loading webview provided by 'anthropic.claude-code': Error: Could not register service worker: InvalidStateError: Failed to register a ServiceWorker: The document is in an invalid state..
The message
Error loading webview provided by 'anthropic.claude-code': Error: Could not register service worker: InvalidStateError: Failed to register a ServiceWorker: The document is in an invalid state..What it means
VS Code couldn't start the background helper that every extension panel needs, so the panel stays blank. The extension named in the message is just the one you opened; it isn't the cause.
What to do
Quit every VS Code window and start it again. If the panel is still blank, quit, delete the Service Worker folder in VS Code's user data folder, and reopen.
VS Code shows this as an error notification when you open an extension's panel and it stays empty. The name in quotes is whichever extension owns that panel:
Error loading webview provided by 'anthropic.claude-code': Error: Could not register service worker: InvalidStateError: Failed to register a ServiceWorker: The document is in an invalid state..
That one is the Claude Code extension. People search the same line with 'openai.chatgpt' (the Codex extension), 'vscode.markdown-language-features' (VS Code's own Markdown preview) and Cline's 'saoudrizwan.claude-dev'. It's the same error in every case. The doubled full stop at the end is real, too (VS Code adds one after the browser's message, which already ends in one).
Why the extension's name is in it now
Until September 2026 the line just read Error loading webview: Error: Could not register service worker: .... VS Code 1.139, released September 23, started naming the extension whose panel failed. We went through the source release by release, and it turns out the plain wording is in each one we checked between 1.128 and 1.138, and both forms are in 1.141.0 (October 7), where the extension name is used whenever VS Code knows the panel's owner.
The name helps with one thing (and it's a useful one): it tells you this isn't the extension's bug. Reinstalling Claude Code or Codex won't fix it, because the part that failed belongs to VS Code.
What actually broke
A webview is the small embedded web page an extension uses to draw its own interface (the Claude Code chat panel is one). Each relies on a service worker to load its files, and VS Code registers one every time a webview opens. Sometimes, for no reason anyone has pinned down, the browser engine inside VS Code refuses with InvalidStateError, and the panel gives up.
Nobody has found the root cause. The main VS Code issue was opened in June 2021 and was still open on October 8, 2026, with 140 comments. A contributor summed it up on a report in August: it "has occasionally been reported over many years without the root cause being traced. Restarting VS Code typically cures it."
The clearest clue so far came after an automatic update in September. A Markdown preview report drew a VS Code team member who'd hit it himself on an Insiders build (Insiders is Microsoft's daily preview release). Every webview from several unrelated extensions was broken in the same way, and he found an older VS Code process and the newly updated one both running against the same profile. He called an update and restart problem "plausible" but couldn't prove it. The original reporter fixed it by closing VS Code and starting it again the next day.
How to clear it
- Quit VS Code completely, every window, and make sure no Code process is left running before you reopen it. A Microsoft engineer wrote back in 2022 that when this happens "it is for all webviews" and they "have to close all instances" to get out of it, so reloading one window won't do it.
- If it survives that, quit again and delete the
Service Workerfolder from VS Code's user data folder, then start VS Code. That folder sits next toUser:%APPDATA%\Code\Service Workeron Windows,~/Library/Application Support/Code/Service Workeron a Mac and~/.config/Code/Service Workeron Linux. A VS Code maintainer suggested it in 2021, and a user in the same thread reported it working in 2022. - If VS Code has just updated itself, the September reports point at a leftover process from before the update, so a clean restart is the thing to try first.
Your settings aren't in that folder (they live in User beside it), and VS Code registers a fresh service worker the next time a panel opens.
The browser version
In VS Code for the Web (vscode.dev, or a Codespace in a browser tab) there's a second form, Could not register service worker. Please make sure third party cookies are enabled:. VS Code prints it when the browser denies permission to register the worker, and the message names the fix itself: allow third-party cookies for the site.
In Cursor
Cursor is built on VS Code and inherits the same code, so the same message appears there with the same fixes. Its user data folder is different, though, and our Cursor version of this page has the path and what Cursor's own staff said.
Other lines the same feature prints
Match yours against these if the one at the top of the page is not quite it. They come from the same code and mean related things.
Error loading webview: Error: Could not register service worker: InvalidStateError: Failed to register a ServiceWorker: The document is in an invalid state..Error loading webview provided by 'openai.chatgpt': Error: Could not register service worker: InvalidStateError: Failed to register a ServiceWorker: The document is in an invalid state..Error loading webview provided by 'vscode.markdown-language-features': Error: Could not register service worker: InvalidStateError: Failed to register a ServiceWorker: The document is in an invalid state..Error loading webview provided by 'saoudrizwan.claude-dev': Error: Could not register service worker: InvalidStateError: Failed to register a ServiceWorker: The document is in an invalid state..Could not register service worker. Please make sure third party cookies are enabled: