Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

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

Open
tritemio opened this issue Jun 11, 2021 · 131 comments
Open

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

tritemio opened this issue Jun 11, 2021 · 131 comments
Assignees
Labels
bug Issue identified by VS Code Team member as probable bug chromium Issues and items related to Chromium papercut 🩸 A particularly annoying issue impacting someone on the team upstream Issue identified as 'upstream' component related (exists outside of VS Code) webview Webview issues
Milestone

Comments

@tritemio
Copy link

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..
@vscodebot
Copy link

vscodebot bot commented 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
Copy link

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 @mjbvz - Are you able to provide some assistance?

@tritemio tritemio changed the title VS code 1.57.0 breaks gitgraph extension 1.30.0 Webview Service Worker Error (Linux) Jun 11, 2021
@tritemio
Copy link
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.

@sketchbuch
Copy link

sketchbuch commented Jun 11, 2021

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

Update: Rebooting fixed the issue, thanks @tritemio

@eamodio eamodio assigned mjbvz and unassigned eamodio Jun 11, 2021
@joyceerhl
Copy link
Contributor

joyceerhl commented Jun 11, 2021

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

image

@mjbvz
Copy link
Collaborator

mjbvz commented Jun 11, 2021

Duplicate of #122951

@grandrew
Copy link

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
Copy link

eduncan911 commented Jul 21, 2021

@mjbvz please reopen this issue. @deepak1556 just stated in #122951 that Linux users are a separate issue, even though it still has the Linux tag.

@eduncan911
Copy link

Copying my comment from the "Windows" thread...

Running vscode 1.58.1 on Linux.

Multiple extensions that use WebView all error with:

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

code --no-sandbox does not help, same errors.

However, changing my --user-data-dir (that forced a re-install of all extensions) did make it work!

Obviously, that is not preferred due to many years of customizing - that I do not want to start all over with.

Ubuntu 21.04
---
Version: 1.58.1
Commit: 2aeda6b18e13c4f4f9edf6667158a6b8d408874b
Date: 2021-07-13T06:20:02.397Z
Electron: 12.0.13
Chrome: 89.0.4389.128
Node.js: 14.16.0
V8: 8.9.255.25-electron.0
OS: Linux x64 5.11.0-7620-generic snap
$ code --verbose .
[1580288:0721/131142.013405:ERROR:appcenter_api.cc(55)] expecting appcenter url prefix
/snap/core/current/lib/x86_64-linux-gnu/libc.so.6: version `GLIBC_2.33' not found (required by /usr/lib/x86_64-linux-gnu/gio/modules/libgvfsdbus.so)
Failed to load module: /usr/lib/x86_64-linux-gnu/gio/modules/libgvfsdbus.so
(code:1580288): Gtk-WARNING **: 13:11:42.028: Failed to parse /home/eric/.config/gtk-3.0/settings.ini: Key file does not start with a group
[main 2021-07-21T17:11:42.256Z] Sending env to running instance...
[main 2021-07-21T17:11:42.345Z] Sent env to running instance. Terminating...
[main 2021-07-21T17:11:42.345Z] Lifecycle#kill()

(it's installed via Snap)

Developer Tools before opening a file that uses webview has this error:

(node:1580425) [DEP0005] DeprecationWarning: Buffer() is deprecated due to security and usability issues. 
Please use the Buffer.alloc(), Buffer.allocUnsafe(), or Buffer.from() methods instead.(Use `code --trace-deprecation ...` 
to show where the warning was created) (at writeOut (internal/process/warning.js:43:3))
m @ console.ts:137

Developer Tools after I open a file that fails webview:

Webview fatal error: Error: Could not register service workers: InvalidStateError: Failed to register a ServiceWorker: The document is in an invalid state..
(anonymous) @ main.js:631
async function (async)
(anonymous) @ main.js:629
(anonymous) @ host.js:27
notificationsAlerts.ts:40 

Error loading webview: Error: Could not register service workers: InvalidStateError: Failed to register a ServiceWorker: The document is in an invalid state..
onDidChangeNotification @ notificationsAlerts.ts:40
(anonymous) @ notificationsAlerts.ts:26
fire @ event.ts:583
addNotification @ notifications.ts:206
error @ notificationService.ts:92
(anonymous) @ baseWebviewElement.ts:210
(anonymous) @ webviewElement.ts:168

Additional info:

$ code --list-extensions
austin.code-gnu-global
be5invis.vscode-icontheme-nomo-dark
budparr.language-hugo-vscode
cssho.vscode-svgviewer
DavidAnson.vscode-markdownlint
dbaeumer.vscode-eslint
DigitalBrainstem.javascript-ejs-support
DotJoshJohnson.xml
dphans.micropython-ide-vscode
eg2.vscode-npm-script
equinusocio.vsc-material-theme-icons
esbenp.prettier-vscode
fivethree.vscode-hugo-snippets
golang.go
hediet.vscode-drawio
jamesmaj.easy-icons
janisdd.vscode-edit-csv
jdinhlife.gruvbox
jebbs.plantuml
JuanBlanco.solidity
magicstack.MagicPython
minhthai.vscode-todo-parser
mitaki28.vscode-clang
ms-azuretools.vscode-docker
ms-python.python
ms-python.vscode-pylance
ms-toolsai.jupyter
ms-vscode.cpptools
ms-vscode.Theme-MarkdownKit
ms-vsliveshare.vsliveshare
ms-vsliveshare.vsliveshare-audio
ms-vsliveshare.vsliveshare-pack
mushan.vscode-paste-image
mutantdino.resourcemonitor
nopeslide.vscode-drawio-plugin-mermaid
phplasma.csv-to-table
PKief.material-icon-theme
platformio.platformio-ide
redhat.vscode-yaml
rid9.datetime
Shan.code-settings-sync
smlombardi.theme-tesla
Stephanvs.dot
streetsidesoftware.code-spell-checker
vsciot-vscode.vscode-arduino
yzhang.markdown-all-in-one

Here's my settings.json that has been scrubbed from sensitive information:

// Place your settings in this file to overwrite the default settings
{
  "workbench.colorTheme": "Gruvbox Dark Soft",
  "workbench.activityBar.visible": true,
  //"workbench.iconTheme": "vscode-icons",
  //"workbench.iconTheme": null,
  "editor.cursorBlinking": "solid",
  //"editor.fontFamily": "'Go Mono'",
  "editor.fontLigatures": true,
  "editor.renderIndentGuides": false,
  "editor.minimap.enabled": false,
  "editor.tabSize": 2,
  "editor.stickyTabStops": true,
  "editor.formatOnSave": true,
  "editor.defaultFormatter": null,
  "[javascript]": {
    "editor.defaultFormatter": "esbenp.prettier-vscode"
  },
  "[jsonc]": {
    "editor.defaultFormatter": "esbenp.prettier-vscode"
  },
  "[json]": {
    "editor.defaultFormatter": "esbenp.prettier-vscode"
  },
  "editor.codeActionsOnSave": {
    "source.fixAll": true
  },
  "files.insertFinalNewline": true,
  "files.trimFinalNewlines": true,
  "files.trimTrailingWhitespace": true,
  "explorer.openEditors.visible": 0,
  "explorer.confirmDelete": false,
  "explorer.confirmDragAndDrop": false,
  "extensions.autoUpdate": false,
  //"terminal.integrated.fontFamily": "Go Mono, Inconsolata-dz for Powerline",
  "terminal.integrated.lineHeight": 0,
  "window.openFilesInNewWindow": "off",
  "extensions.ignoreRecommendations": true,
  "explorer.compactFolders": false,
  "vim.enableNeovim": true,
  "vim.disableAnnoyingNeovimMessage": true,
  "go.testOnSave": true,
  "go.coverOnSave": true,
  "go.useCodeSnippetsOnFunctionSuggest": true,
  "go.autocompleteUnimportedPackages": true,
  "go.useLanguageServer": true,
  "C_Cpp.intelliSenseEngine": "Default",
  "sync.gist": "(snip)",
  "sync.lastUpload": "2018-07-02T18:38:38.162Z",
  "sync.autoDownload": true,
  "sync.autoUpload": true,
  "sync.lastDownload": "2018-02-19T15:13:34.109Z",
  "sync.forceDownload": false,
  "sync.anonymousGist": false,
  "sync.host": "",
  "sync.pathPrefix": "",
  "sync.quietSync": true,
  "sync.askGistName": false,
  "vsicons.dontShowNewVersionMessage": true,
  "python.pythonPath": "",
  "workbench.startupEditor": "newUntitledFile",
  "python.linting.enabled": true,
  "python.linting.pylintEnabled": true,
  "python.linting.pylamaEnabled": false,
  "python.linting.pycodestyleEnabled": false,
  "python.linting.flake8Enabled": false,
  "sync.removeExtensions": true,
  "sync.syncExtensions": true,
  "extensions.autoCheckUpdates": false,
  "update.showReleaseNotes": false,
  "telemetry.enableCrashReporter": false,
  "telemetry.enableTelemetry": true,
  "npm.fetchOnlinePackageInfo": true,
  "workbench.enableExperiments": false,
  "workbench.settings.enableNaturalLanguageSearch": false,
  "sync.forceUpload": true,
  "zenMode.hideTabs": false,
  "dateTime.use24HourClock": false,
  "dateTime.showAMPM": true,
  "resmon.show.cpufreq": false,
  "resmon.show.cputemp": true,
  "resmon.show.cpuusage": false,
  "resmon.show.mem": false,
  "debug.console.fontSize": 12.5,
  "markdown.preview.fontSize": 12.5,
  "editor.fontSize": 12.5,
  "terminal.integrated.fontSize": 12.5,
  "workbench.colorCustomizations": {
    "[Tesla]": {
      "activityBar.background": "#232323EE",
      "editor.inactiveSelectionBackground": "#3d3d3d",
      "editor.selectionBackground": "#636363",
      "editor.selectionHighlightBackground": "#505050",
      "scrollbar.shadow": "#23232300",
      "sideBar.background": "#232323EE",
      "statusBar.background": "#23232300",
      //"statusBar.background": "#000000FF",
      //"statusBar.border": "#3B3B3B",
      "statusBar.foreground": "#969696",
      "statusBar.debuggingBackground": "#511f1f",
      "statusBar.debuggingBorder": "#8b1818",
      "statusBar.debuggingForeground": "#FFFFFF",
      "tab.activeBorderTop": "#3d3d3d"
    },
    "terminal.background": "#282828",
    "terminal.foreground": "#D5C4A1",
    "terminalCursor.background": "#D5C4A1",
    "terminalCursor.foreground": "#D5C4A1",
    "terminal.ansiBlack": "#282828",
    "terminal.ansiBlue": "#83A598",
    "terminal.ansiBrightBlack": "#665C54",
    "terminal.ansiBrightBlue": "#83A598",
    "terminal.ansiBrightCyan": "#8EC07C",
    "terminal.ansiBrightGreen": "#B8BB26",
    "terminal.ansiBrightMagenta": "#D3869B",
    "terminal.ansiBrightRed": "#FB4934",
    "terminal.ansiBrightWhite": "#FBF1C7",
    "terminal.ansiBrightYellow": "#FABD2F",
    "terminal.ansiCyan": "#8EC07C",
    "terminal.ansiGreen": "#B8BB26",
    "terminal.ansiMagenta": "#D3869B",
    "terminal.ansiRed": "#FB4934",
    "terminal.ansiWhite": "#D5C4A1",
    "terminal.ansiYellow": "#FABD2F"
  },
  "editor.suggest.showIcons": false,
  "workbench.editor.showIcons": true,
  //"workbench.iconTheme": "material-icon-theme",
  //"workbench.iconTheme": null,
  "breadcrumbs.enabled": false,
  "window.menuBarVisibility": "toggle",
  "cSpell.userWords": [
    "snipped"
  ],
  "files.associations": {
    "**/*.yml": "ansible"
  },
  "go.formatTool": "gofmt",
  "go.coverageOptions": "showUncoveredCodeOnly",
  "go.coverOnSingleTest": true,
  "go.coverOnSingleTestFile": true,
  "go.coverShowCounts": true,
  "terminal.integrated.tabs.enabled": true,
  "javascript.updateImportsOnFileMove.enabled": "always",
  "window.zoomLevel": 1,
  "hediet.vscode-drawio.customFonts": [
    "Go",
    "Go Medium",
    "Go Mono",
    "Go, Bold",
    "Go Mono, Bold",
    "Go Medium, Bold"
  ],
  "hediet.vscode-drawio.local-storage": "(snip)",
  "TodoParser": {
    "folderExclude": ["node_modules", ".vscode"],
    "showInProblems": true,
    "markers": [
      ["TODO", "Warning"],
      ["FIXME", "Warning"]
    ],
    "autoDefaultMarkers": true
  },
  "hediet.vscode-drawio.theme": "min",
  "hediet.vscode-drawio.codeLinkActivated": false,
  "docker.showStartPage": false,
  "[markdown]": {
    "editor.defaultFormatter": "esbenp.prettier-vscode"
  },
  "emmet.includeLanguages": {
    "ejs": "html"
  },
  "workbench.editorAssociations": {
    "*.ipynb": "jupyter.notebook.ipynb"
  },
  "workbench.iconTheme": "eq-material-theme-icons-darker",
  "typescript.updateImportsOnFileMove.enabled": "always",
  "files.exclude": {
    "**/node_modules": true
  },
  "redhat.telemetry.enabled": false
}

I tried to downgrade to VSCode 1.55; but, when opening a file now for webview, it doesn't seem to trigger the extensions any longer (something broke).

@deepak1556 deepak1556 reopened this Jul 21, 2021
@deepak1556 deepak1556 added linux Issues with VS Code on Linux webview Webview issues and removed *duplicate Issue identified as a duplicate of another issue(s) labels Jul 21, 2021
@deepak1556
Copy link
Collaborator

Please provide the trace following the steps below:

  • Open vscode like code --enable-tracing="navigation,net,loading,rail,ServiceWorker,disabled-by-default-loading" --trace-startup-file="/tmp/chrometrace.log"
  • Perform the steps that leads to the the service worker error
  • Quit the application
  • Attach the chrometrace.log file generated at /tmp

@deepak1556 deepak1556 added the info-needed Issue requires more information from poster label Jul 21, 2021
@deepak1556 deepak1556 self-assigned this Jul 21, 2021
@tamuratak
Copy link
Contributor

tamuratak commented Jul 22, 2021

OS: Linux x64 5.11.0-18-generic snap

We can see that all the reported issues happen with the snap version of VS Code. It is an unofficial build. It would be a fix to install the official build of VS Code.

@eduncan911
Copy link

eduncan911 commented Jul 22, 2021

OS: Linux x64 5.11.0-18-generic snap

We can see that all the reported issues happen with the snap version of VS Code. It is an unofficial build. It would be a fix to install the official build of VS Code.

I think that's incorrect.

Right at the top of the Installation page, it says it's the official distribution method for VSCode:

Snap#
Visual Studio Code is officially distributed as a Snap package in the Snap Store

https://code.visualstudio.com/docs/setup/linux

image

Snap is highly preferred over Deb packages because it is sandboxed, isolated from corrupting the system.

@tamuratak
Copy link
Contributor

I think that's incorrect.

Thank you for your correction.

@enkeyz
Copy link

enkeyz commented Sep 30, 2023

For me it occurs anytime I install an extension, which opens up their setting page right after. Restarting vscode fixes the issue for some time.

@tp1050
Copy link

tp1050 commented Oct 11, 2023

rm -rf .config/Code/Service\ Worker/{CacheStorage,ScriptCache} followed by pkill code worked for me without restarting my whole machine.

worked like a charm.

@wafflemakr
Copy link

I just hit this issue with the latest release trying to display the Release Notes. I deleted ~/.config/Code/Service Worker (+ all directories with Cache in the name) and now it's working again.

This worked like a charm for me in Ubuntu, remember to refresh VSCode! thanks a lot!

@mjbvz mjbvz added this to the On Deck milestone Dec 6, 2023
@joaomoreno joaomoreno added the snap Issues related to the snap package label Dec 14, 2023
@joaomoreno joaomoreno changed the title Webview Service Worker Error in registration due to invalid document state (Linux) Snap: Webview Service Worker Error in registration due to invalid document state Dec 14, 2023
@Tyriar Tyriar removed linux Issues with VS Code on Linux snap Issues related to the snap package labels Feb 1, 2024
@Tyriar
Copy link
Member

Tyriar commented Feb 1, 2024

This isn't a linux/snap issue, I've seen it plenty of times on Windows.

@Tyriar Tyriar changed the title Snap: Webview Service Worker Error in registration due to invalid document state Webview Service Worker Error in registration due to invalid document state Feb 1, 2024
@QuentinSc
Copy link

Get it on windows, on a fresh install

@saadazghour
Copy link

If you are using Ubuntu, there is probably another (maybe hidden) vscode process, which is causing the problem.

Close the vs code first and in terminal try: killall code

@mminot-yseop
Copy link

mminot-yseop commented Mar 8, 2024

Got that all of a sudden on 1.87.0. OK after reboot but I hope it won’t come back too often. 😆
(Xubuntu 20, .deb package install)

@fabriceleal
Copy link

@juanma-avio
Copy link

Easy workaround on Linux:

  1. exit vs code
  2. in the console write: "killall code"
  3. start vs code again

@caiqichang
Copy link

i got this problem when i open second vscode windows.
only first vscode window can work well, webview in the other windows broken down.

vscode version: 1.89.0
pc: windows 11

@yan-pi
Copy link

yan-pi commented Jun 1, 2024

Same issue Here!!

Does this issue occur when all extensions are disabled?: No, sice i need to install the markdown extension to occur

VS Code Version: 1.89.1 dc96b83 x64
OS Version: linux fedora 40 linux kernel 6.8.9-300.fc40.x86_64
Steps to Reproduce:

Install markdown preview or other Rxtension that uses webview
Run the command to show webview

@BMourguesFieldbox
Copy link

rm -rf .config/Code/Service\ Worker/{CacheStorage,ScriptCache} followed by pkill code worked for me without restarting my whole machine.

worked like a charm.

Same, worked perfectly, quote replying for future readers

@Doc-Tiebeau
Copy link

rm -rf .config/Code/Service\ Worker/{CacheStorage,ScriptCache} followed by pkill code worked for me without restarting my whole machine.

worked like a charm.

Works for same issue when displaying markdown and png files.

OS: Debian Bookworm 12.6
VScodium : 1.91.1
Release : 24193
Context : ~/.config/VSCodium synchronized using rsync from previous machine (Ubuntu + Snap)

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
bug Issue identified by VS Code Team member as probable bug chromium Issues and items related to Chromium papercut 🩸 A particularly annoying issue impacting someone on the team upstream Issue identified as 'upstream' component related (exists outside of VS Code) webview Webview issues
Projects
None yet
Development

No branches or pull requests