vscode: Webview Service Worker Error in registration due to invalid document state

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

About this issue

  • Original URL
  • State: open
  • Created 3 years ago
  • Reactions: 101
  • Comments: 126 (17 by maintainers)

Most upvoted comments

For me, what worked was to delete the folder Service Worker under ~/.config/Code and re-opening my Visual Studio and it started working as expected. Hope it helps someone 😃

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.

https://github.com/mhutchie/vscode-git-graph/issues/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?

Exiting vscode manually, running pkill code and starting vscode again resolved the issue for me

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.

Duplicate of #122951

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

I found that the problem ca be fixed without rebooting by removing all the cache folders used by vscode:

  • close vscode (make sure no process is running)
  • rm -rf ~/.config/Code/*Cache*
  • open vs code

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

Update: Rebooting fixed the issue, thanks @tritemio

pkill code works for me. Thanks

Version: 1.62.1 Commit: f4af3cbf5a99787542e2a30fe1fd37cd644cc31f Date: 2021-11-05T10:56:50.217Z Electron: 13.5.2 Chrome: 91.0.4472.164 Node.js: 14.16.0 V8: 9.1.269.39-electron.0 OS: Linux x64 5.11.0-40-generic snap

I found that the problem ca be fixed without rebooting by removing all the cache folders used by vscode:

* close vscode (make sure no process is running)

* `rm -rf ~/.config/Code/*Cache*`

* open vs code

Worked for me.Thanks

this is still an issue in 1.70 on ubuntu 20.4

Exiting vscode manually, running pkill code and starting vscode again resolved the issue for me

Same here! Thanks!

pkill code from @lubomir-brindza combined with rm -rf ~/.config/Code/*Cache* from @tritemio worked for me.

Version: 1.60.2
Commit: 7f6ab5485bbc008386c4386d08766667e155244e
Date: 2021-09-22T12:01:43.795Z
Electron: 13.1.8
Chrome: 91.0.4472.164
Node.js: 14.16.0
V8: 9.1.269.39-electron.0
OS: Linux x64 5.11.0-34-generic snap (Ubuntu 20.04)

Since yesterday, I encountered the same issue for all webviews, tried with: the one in Walkthrough, Quarkus welcome page, Kaoto UI.

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

I am on Fedora 36 VS Code 1.73.1

I tried restating VS Code, restarting OS. Still same behavior. I tried with another fresh instance of VS Code.

Workaround for me (based on previous comments): deleting the ~/.config/Code/Service Worker then restart VS Code

note it doesn’t work for all the webviews when developing an extension in the Extension development host , there is surely another cache to clean somewhere else (not found yet)

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

worked like a charm.

@eduncan911 The problem persists in version 1.60.

Was hit by this issue again, on a completely different machine and setup but was able to resolve without rebooting.

There where stale ā€œcodeā€ processes running in the background even though I explicitly clicked ā€œexitā€ from menu. I just killed them from htop one by one, and the problem was gone.

I suspect this happened due to a previous crash (-es?) - I periodically open my laptop and see no vscode windows open, so I just click the icon again and the window re-appears. Looks like the old processes get orphaned.

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

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!

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.

https://github.com/microsoft/vscode/issues/125993#issuecomment-999715355

For me, what worked was to delete the folder Service Worker under ~/.config/Code and re-opening my Visual Studio and it started working as expected. Hope it helps someone 😃

It works for me! I’m under Ubuntu 20.04.4 LTS …thanks!

You can kill all running vscode processes with pkill code.

Ran into this just now; the cause was probably that I was still running ā€˜old’ code instances alongside new ones (updating a snap will cause the Ubuntu launcher icon to indicate no instances are running, since the path to the executable has changed). I have no idea whether the ā€˜old’ code instance was responsible for a stray headless process, or I just didn’t notice an open window in one of my workspaces; but killing them made the issue go away.

I have anecdote to support this. I accidentally left my computer on last night with VSCode running. I log in to find the icon showing there are no windows open. This has happened to a different computer along with the webview error. So I left the windows open just in case. Opening a new window causes the webview error to pop up. Here is a screenshot showing the webview markdown preview working on the old process:

image

Clicking on the icon to opens a new window that has the webview error:

image

Using alt + tab to see all open VSCode windows (even the ones that are no longer associated with a tray icon), and closing them normally worked for me. This might be better than using pkill to shutdown vscode ungracefully. I have not needed to clear any cache files when shutting down VSCode this way!

I can confirm that an update to VSCode was partially the cause. The old window had the following version info:

Version: 1.61.2
Commit: 6cba118ac49a1b88332f312a8f67186f7f3c1643
Date: 2021-10-19T14:58:13.605Z
Electron: 13.5.1
Chrome: 91.0.4472.164
Node.js: 14.16.0
V8: 9.1.269.39-electron.0
OS: Linux x64 5.4.0-89-generic snap

The new window has this version info:

Version: 1.62.0
Commit: b3318bc0524af3d74034b8bb8a64df0ccf35549a
Date: 2021-11-03T15:18:44.904Z
Electron: 13.5.1
Chrome: 91.0.4472.164
Node.js: 14.16.0
V8: 9.1.269.39-electron.0
OS: Linux x64 5.4.0-89-generic snap

@deepak1556 I have been able to reproduce this bug with the following:

  1. run sudo snap revert code (this causes the tray icon to show no windows open)
  2. click the icon to open a new window (or via command line code <path>)
  3. The new window should have the webview error
  4. If all windows are closed (checking with alt + tab then the issue goes away)
  5. reintroduce it again with sudo snap revert code --revision <number> to force the upgrade again with an existing code instance running.

Hope this helps!

Was hit by this issue again, on a completely different machine and setup but was able to resolve without rebooting.

There where stale ā€œcodeā€ processes running in the background even though I explicitly clicked ā€œexitā€ from menu. I just killed them from htop one by one, and the problem was gone.

You can kill all running vscode processes with pkill code.

Ran into this just now; the cause was probably that I was still running ā€˜old’ code instances alongside new ones (updating a snap will cause the Ubuntu launcher icon to indicate no instances are running, since the path to the executable has changed). I have no idea whether the ā€˜old’ code instance was responsible for a stray headless process, or I just didn’t notice an open window in one of my workspaces; but killing them made the issue go away.

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

Issue still persist on latest version

image

I had the same issue with Mac OS 13.0.1 running VS Code 1.73.1 . Putting my resolution out here for anyone how needs it. sudo pkill code and then force close any VS Code instances. Thanks @milnomada

I also have this issue on Linux. (Version VScode: 1.66.0) Rebooting of computer fixed the issue, thanks!

pkill code works for me

Version: 1.60.2
Commit: 7f6ab5485bbc008386c4386d08766667e155244e
Date: 2021-09-22T12:01:43.795Z
Electron: 13.1.8
Chrome: 91.0.4472.164
Node.js: 14.16.0
V8: 9.1.269.39-electron.0
OS: Linux x64 4.15.0-156-generic snap

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

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

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

I am using Fedora and I had the same problem, and believe or not, the problem was because of Brave, do not ask me why. I tried get copilot working and I got this error.

What I did was that:

  • disabled VSCode all extensions;
  • pkill code
  • pkill brave-browser
  • deleted all folders that has ā€œcacheā€ within ~/.config/Code
  • reboot

Done. VSCode working again as well as copilot.

I have a known solution on Ubuntu 22.04

  • From analysis, this issue is definitely caused by the ~/.config/Code folder contents. I deleted all of my extensions, and still experienced the issue with Core Markdown Preview Functionality

I deleted my ā€œ~/.config/Codeā€ folder and was able to restore functionality. Its going to be a pain installing all my extensions again, but I’ve narrowed down the error ( at least in my system )

You can probably fix the issue by clearing the Code folder, or by clearing your ā€œsettingsā€. What I suspect is that VS code has some older config-settings which break when updating the version, or become corrupted by some other process.

Note: I did try using the --no-sandbox option with no effect, and had some effect with --user-data-dir ~/fakeFolder, pointing me to the ~/.config/Code deletion solution.

I’m facing the same error for the internal Markdown preview as well as the Markdown Enhanced extension and the Code Whisperer Reference Log on Windows using 1.74.2.

Exiting vscode manually, running pkill code and starting vscode again resolved the issue for me

this has worked for me on manjaro linux

Using just pure pkill code fixed this on ubuntu for me just now. Clearly there is a defect here.

` ~$ cat /etc/lsb-release

DISTRIB_ID=Ubuntu DISTRIB_RELEASE=20.04 DISTRIB_CODENAME=focal DISTRIB_DESCRIPTION=ā€œUbuntu 20.04.4 LTSā€ `

Exiting vscode manually, running pkill code and starting vscode again resolved the issue for me

this has worked for me on manjaro linux

For me, what worked was to delete the folder Service Worker under ~/.config/Code and re-opening my Visual Studio and it started working as expected. Hope it helps someone 😃

This is still a problem with 1.64 just released, CentOS8/RHEL8, and moving from 1.61 to 1.64 but the ~/.config/Code folder is much older.

This solution worked for me

pkill code works for me. Thanks

Version: 1.62.1 Commit: f4af3cb Date: 2021-11-05T10:56:50.217Z Electron: 13.5.2 Chrome: 91.0.4472.164 Node.js: 14.16.0 V8: 9.1.269.39-electron.0 OS: Linux x64 5.11.0-40-generic snap

Only pkill works for me.

Version: 1.62.3 Commit: ccbaa2d27e38e5afa3e5c21c1c7bef4657064247 Date: 2021-11-17T08:00:36.721Z Electron: 13.5.2 Chrome: 91.0.4472.164 Node.js: 14.16.0 V8: 9.1.269.39-electron.0 OS: Linux x64 5.11.0-38-generic snap

I just found out that killing all vscode jobs through the activity monitor also solves the problem. In this way, one does not need to restart the machine like I was doing before.

Ubuntu 18.04.6 LTS

Version: 1.62.3
Commit: ccbaa2d27e38e5afa3e5c21c1c7bef4657064247
Date: 2021-11-17T08:00:36.721Z
Electron: 13.5.2
Chrome: 91.0.4472.164
Node.js: 14.16.0
V8: 9.1.269.39-electron.0
OS: Linux x64 5.4.0-90-generic snap

I experience the same issue on Ubuntu 21.04., with the latest official VSCode version.

If anyone finds a reliable way to repro the issue it would help with further debugging, thanks!

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

image

rm -rf .config/Code/Service\ Worker/{CacheStorage,ScriptCache}

pkill code rm -rf .config/Code/Service\ Worker/{CacheStorage,ScriptCache}

Obrigado, essa solução funcionou para mim, estou usando a versão 23.x do ubuntu

On windows that’s %AppData%\Code\Cache

I’m not sure why #178834 was closed, because this issue is happening when updating to 1.77, and 1.76.2 worked perfectly. I have been checking and this change should have caused the issue:

https://github.com/microsoft/vscode/pull/177716/commits/f71995e0b16ec2429cbbd221714984197ff5259d#diff-2f29d5590142a69ba7b8500a64b19f6bffb00b3b6bace7329976f6e5fea88649

My extension is totally broken because the webview cannot show my web app and it’s kind of difficult to send you a reproducible test case.

I am seeing this when trying to view the latest Release Notes:

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

If anyone is using Brave, please turn off the brave shields as well.

Restarting worked for me, I also re-installed jupyter notebook extension!

I also get this on windows easily, using the VSCode Lean4 extension which also has a webview - by simply running ā€œcode .ā€ too quickly. If I let the previous VS code fully shutdown then the next ā€œcode .ā€ works fine. But I have to give it 10 seconds or so. It would be nice if vscode would fix this as it is very annoying.

I just run into this issue while working on a new extension after updating vscode to the most recent version. So far I haven’t experienced this issue and the code was more or less unmodified since yesterday where I extensively tested all changes.

vscode-version

I’ve updated vs-code today via the .deb package provided on the official site. Before I had it installed via snap but I found multiple comments that mentioned to use the official .deb package in favor of the snap one on Ubuntu systems.

What I figured out is that when I run the extension via the Run Extension debug option, every second restart of vscode (not the child environment started via the Run Extension command but the actual development editor!) all Webviews work as expected within the child editor, but every odd restart they do not. To me this sounds like something in regards to Webviews is cached here and not fully restorable on a reload which is then removed and hence works on every 2nd restart

Still having this issue: v1.63.2

Thanks @mattangus, those steps are really helpful. I can confirm the issue on my end now.

Anecdote: This appeared after vscode update to 1.16.0 x64 for me today, but after trying reboot as suggested above, which didn’t help, Chrome Google Chrome 94.0.4606.81 update came along through auto updates. I took it, and without reboot and only restart of vscode, the problem is gone. This is on Ubuntu 20.04 with snap vscode.

As a reminder from my earlier debugging, when using --user-data-dir for a new empty directory (and vscode re-downloads all extensions), it works fine. Removing the --user-data-dir and going back to my original setup, it’s broken again.

However, with so many reports out there, this is not an isolated case. So we appreciate the additional debugging.

Thanks for the logs, @mjbvz here is what we know from it. The following is the loading trace comparison of draw-io extension from my machine and from the issue reporter. I will skip to the part which starts loading the webview container.

  1. The navigation to vscode-webview://{{uuid}}/index.html?id=3d61c755-1203-4a27-8874-30a8c77cc9c2&swVersion=2&extensionId=hediet.vscode-drawio&platform=electron&vscode-resource-base-authority=vscode-resource.vscode-webview.net gets committed on both these traces, which means there is successful navigation to the container startpoint and the render process is locked to this origin.

Working device:

Title | RenderFrameHostImpl::DidCommitProvisionalLoadĀ 
-- | --
Category | navigation
User Friendly Category | other
Start | 15,992.164 ms
Wall Duration | 0.793 ms
CPU Duration | 0.793 ms
Self Time | 0.483 ms
CPU Self Time | 0.482 ms
ā–¶Args | Ā 
params | {contents_mime_type:Ā "", did_create_new_entry:Ā false, document_sequence_number:Ā -1642300397, embedding_token:Ā "5672A309BEE3D95750DCA8866CD6EF0B", has_potentially_trustworthy_unique_origin:Ā false, history_list_was_cleared:Ā false, http_status_code:Ā 200, intended_as_new_entry:Ā false, is_overriding_user_agent:Ā false, item_sequence_number:Ā -1642300398, method:Ā "GET", navigation_token:Ā "4ED2F51C423A27DA45E06C18CC2A46A8", origin:Ā "vscode-webview://a3475ae9-bbd7-4d29-97a1-c162a7e22d3f", original_request_url:Ā "", post_id:Ā -1, process lock:Ā "{ vscode-webview://a3475ae9-bbd7-4d29-97a1-c162a7e22d3f/ }", referrer: {policy:Ā 6,            url:Ā ""}, request_id:Ā 80005, should_replace_current_entry:Ā true, should_update_history:Ā true, transition:Ā 3, url:Ā "vscode-webview://a3475ae9-bbd7-4d29-97a1-c162a7e22d3f/index.html?id=a3475ae9-bbd7-4d29-97a1-c162a7e22d3f&swVersion=2&extensionId=hediet.vscode-drawio&platform=electron&vscode-resource-base-authority=vscode-resource.vscode-webview.net", url_is_unreachable:Ā false}
rfh | {browsing_instance_id:Ā 2, frame_tree_node_id:Ā 3, lifecycle_state:Ā "Speculative", origin:Ā "null [internally: (43163F393B9C82B24A1737DE519B042C) anonymous]", parent: {browsing_instance_id:Ā 2,          frame_tree_node_id:Ā 1,          lifecycle_state:Ā "Active",          origin:Ā "vscode-file://vscode-app",          process_id:Ā 6,          render_frame_id:Ā 1,          site_instance_id:Ā 3,          this:Ā "0x1d6376a5a000",          url:Ā "vscode-file://vscode-app/snap/code/70/usr/share/code/resources/app/out/vs/code/electron-browser/workbench/workbench.html"}, process_id:Ā 9, render_frame_id:Ā 5, site_instance_id:Ā 6, this:Ā "0x1d6377e1f000",

Error device:

Title | RenderFrameHostImpl::DidCommitProvisionalLoad
-- | --
Category | navigation
User Friendly Category | other
Start | 5,114.595 ms
Wall Duration | 3.906 ms
CPU Duration | 0.770 ms
Self Time | 3.607 ms
CPU Self Time | 0.462 ms
ā–¶Args | Ā 
params | {contents_mime_type:Ā "", did_create_new_entry:Ā false, document_sequence_number:Ā -25912278, embedding_token:Ā "A9A1236A1CB9944CF3D18EB533A211CD", has_potentially_trustworthy_unique_origin:Ā false, history_list_was_cleared:Ā false, http_status_code:Ā 200, intended_as_new_entry:Ā false, is_overriding_user_agent:Ā false, item_sequence_number:Ā -25912279, method:Ā "GET", navigation_token:Ā "57F47682D127BEC4D9865DBD5B003000", origin:Ā "vscode-webview://3d61c755-1203-4a27-8874-30a8c77cc9c2", original_request_url:Ā "", post_id:Ā -1, process lock:Ā "{ vscode-webview://3d61c755-1203-4a27-8874-30a8c77cc9c2/ }", referrer: {policy:Ā 6,            url:Ā ""}, request_id:Ā 853431, should_replace_current_entry:Ā true, should_update_history:Ā true, transition:Ā 3, url:Ā "vscode-webview://3d61c755-1203-4a27-8874-30a8c77cc9c2/index.html?id=3d61c755-1203-4a27-8874-30a8c77cc9c2&swVersion=2&extensionId=hediet.vscode-drawio&platform=electron&vscode-resource-base-authority=vscode-resource.vscode-webview.net", url_is_unreachable:Ā false}
rfh | {browsing_instance_id:Ā 2, frame_tree_node_id:Ā 3, lifecycle_state:Ā "Speculative", origin:Ā "null [internally: (196D83E2E26DCF81313630615C6AFFF6) anonymous]", parent: {browsing_instance_id:Ā 2,          frame_tree_node_id:Ā 1,          lifecycle_state:Ā "Active",          origin:Ā "vscode-file://vscode-app",          process_id:Ā 7,          render_frame_id:Ā 1,          site_instance_id:Ā 3,          this:Ā "0x3ec986f27200",          url:Ā "vscode-file://vscode-app/snap/code/70/usr/share/code/resources/app/out/vs/code/electron-browser/workbench/workbench.html"}, process_id:Ā 10, render_frame_id:Ā 5, site_instance_id:Ā 6, this:Ā "0x3ec9870b1400", url:Ā ""}
  1. Next we get a resource request for "vscode-webview://{{uuid}}/host.js" which also gets completed for both scenarios

  2. After which get resource request for "vscode-webview://{{uuid}}/main.js", this is the file which tries to register the service worker https://github.com/microsoft/vscode/blob/c1b4cf00b93a83f810055b52ba2ceb08be1432a1/src/vs/workbench/contrib/webview/browser/pre/main.js#L207-L240

The resource request to main.js completes for both scenarios, but the difference comes in the navigator.serviceWorker.register call. For the successful scenario we pass the security checks in blink and continue with service worker loading as you can see below

Screen Shot 2021-07-23 at 11 55 11 AM

But for the failure case we are hitting this condition https://source.chromium.org/chromium/chromium/src/+/main:third_party/blink/renderer/modules/service_worker/service_worker_container.cc;l=312-319 which is the DOM exception the user receives in the end.

Based on some early debugging the provider can be empty under the following conditions:

  1. If the page loading the service worker is being navigated away during the registration step
  2. If the service worker is registered inside an iframe then the provider can be empty if the sandbox property of the frame is changed dynamically.

From the trace we are definitely not hitting 1) and based on https://github.com/microsoft/vscode/blob/c1b4cf00b93a83f810055b52ba2ceb08be1432a1/src/vs/workbench/contrib/webview/browser/webviewElement.ts#L357-L376 we only edit the sandbox properties during the webview container creation and not after that, and this steps happens way before the main.js file gets requested. Are there other places where we edit the sandbox properties ?

So we are hitting some other edge case that is not covered above, will ping the chromium team to understand further or if we can get better debug logs.

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

Looks like some warnings for --enable-tracing and --trace-startup-file as valid options.

$ code --enable-tracing="navigation,net,loading,rail,ServiceWorker,disabled-by-default-loading" --trace-startup-file="/tmp/chrometrace.log" .
Warning: 'enable-tracing' is not in the list of known options, but still passed to Electron/Chromium.
Warning: 'trace-startup-file' is not in the list of known options, but still passed to Electron/Chromium.

However, there does seem to be something in the log file (see attached).

chrometrace.log