microsoft / vscode

Visual Studio Code
https://code.visualstudio.com
MIT License
164.81k stars 29.49k forks source link

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

Open tritemio opened 3 years ago

tritemio commented 3 years ago

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

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[bot] commented 3 years ago

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

mhutchie commented 3 years ago

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?

tritemio commented 3 years ago

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 commented 3 years ago

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

Update: Rebooting fixed the issue, thanks @tritemio

joyceerhl commented 3 years ago

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

image

mjbvz commented 3 years ago

Duplicate of #122951

grandrew commented 3 years ago

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 commented 3 years ago

@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 commented 3 years ago

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 commented 3 years ago

Please provide the trace following the steps below:

tamuratak commented 3 years ago

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 commented 3 years ago

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 commented 3 years ago

I think that's incorrect.

Thank you for your correction.

eduncan911 commented 3 years ago

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

deepak1556 commented 3 years ago

Thanks for the log, you can ignore the warning. They just mean the flags are not respected by the application but will be sent to the underlying runtime.

The log you have captured does not include any loading data, can you attach a gif recording of the steps that you performed. It should be something like the following where a simple launch of the application should generate a good amount of data.

recording.gif.zip

eduncan911 commented 3 years ago

Before doing the recording, I went through the steps again - and this time the log file seems to be much larger. Open vscode, open the file that produces the error, close vscode. Not sure why the first log was so small.

chrometrace.log

deepak1556 commented 3 years ago

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: ""}

2) Next we get a resource request for "vscode-webview://{{uuid}}/host.js" which also gets completed for both scenarios

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

eduncan911 commented 3 years ago

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.

deepak1556 commented 3 years ago

@eduncan911 can you try the following and see if you still get the webview error in each case.

1) Disable all extensions except for draw-io 2) Remove ~/.config/Code/Code Cache 3) Remove ~/.config/Code/Service Worker

eduncan911 commented 3 years ago

Disabling all extensions, and only enabling Draw-io worked. Went to re-enable everything and it continues to work. However, several of my preferences were reverted.

I have not switched to use MS sync yet - I am still using an old gist-sync method for my settings. Therefore, I can see everything that changes - and roll back.

I cannot see anything that would have caused this bug to happen. Just a few workbench.iconTheme and workbench.colorTheme changes, and several extensions.json metadata remove/add back (of usually the same).

At this time, my editor seems to be fixed and I am unable to reproduce it now.

If I find the time, I can roll back my extensions.json and settings.json to see if i can isolate it down further.

deepak1556 commented 3 years ago

Thanks, appreciate it! any additional debug info helps.

mjbvz commented 3 years ago

@deepak1556 Thanks for investigating!

I agree that we should not be modifying the sandbox attribute or navigating the webview host page while the service worker is loading. We also wait for the the service worker to be registered before loading the extension provided webview content: https://github.com/microsoft/vscode/blob/99c8e788d46c935aecb16129919c6041eed92250/src/vs/workbench/contrib/webview/browser/pre/main.js#L724

eduncan911 commented 3 years ago

Closed automatically after 7 days of inactivity?

That seems ... A bit excessive.

Is there a label we could add to prevent it from being closed?

It's obviously a problem with people upgrading their VSCode over time that it "breaks".

And so far, only a reinstall of all extensions seems to fix it. That doesn't seem like a viable solution, especially when the cause is unknown and could happen yet again with another corruption.

deepak1556 commented 3 years ago

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

Omcsesz commented 3 years ago

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

eduncan911 commented 3 years ago

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

@deepak1556 Well, it's happened to me again as well.

It was fixed for about a week; but, vscode just updated to 1.59. Now broken.

Version: 1.59.0
Commit: 379476f0e13988d90fab105c5c19e7abc8b1dea8
Date: 2021-08-04T23:13:20.182Z
Electron: 13.1.7
Chrome: 91.0.4472.124
Node.js: 14.16.0
V8: 9.1.269.36-electron.0
OS: Linux x64 5.11.0-7620-generic snap

@Omcsesz The previous fix was to disable all extensions, and re-enable them. (I also had a few restarts of vscode in the middle of all that)

c0ppelius commented 3 years ago

I had been squatting 1.53 for about a month because of this error but was forced to upgrade to install a new extension. I found the following.

What didn't work:

What did work:

OS: Ubuntu 20.04.2 VS Code: 1.59

sam-dehority commented 3 years ago

@c0ppelius thismethod also worked for me, under the variation

snap remove --purge code && rm -r ~/.config/Code

OS: Ubuntu 21.04 Code: 1.59.1

grandrew commented 3 years ago

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.

garretth9 commented 3 years ago

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.

Just wanted to confirm that this also worked for me on VSCode 1.59.1 running on macOS Big Sur 11.5.1 . Somehow an instance of Code was stuck running in the background even though I had Quit it previously. Killing all instances of Code and the Code Helper app through the activity monitor and then restarting resolved the problem for me.

tritemio commented 3 years ago

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

Omcsesz commented 3 years ago

@eduncan911 The problem persists in version 1.60.

eduncan911 commented 3 years ago

@eduncan911 The problem persists in version 1.60.

Yeah, a 2nd comment I made later said it's still an issue. Doh.

PaluMacil commented 3 years ago

Ubuntu 20.04, snap install, Code 1.60.0: confirming it is still a problem. I opened Code which loaded release notes--I assume from an update last I used it, and I have exactly the same issue. From reading through this, I killed the 31 processes related to Code and then as able to successfully load the release notes on next launch from the help menu.

eduncan911 commented 3 years ago

Ah yes, we forgot to report that as an issue as well:

This error also prevents the Release Notes from displaying after an upgrade.

On Sat, Sep 4, 2021, 11:36 AM Dan Wolf @.***> wrote:

Ubuntu 20.04, snap install, Code 1.60.0: confirming it is still a problem. I opened Code which loaded release notes--I assume from an update last I used it, and I have exactly the same issue. From reading through this, I killed the 31 processes related to Code and then as able to successfully load the release notes on next launch from the help menu.

— You are receiving this because you were mentioned. Reply to this email directly, view it on GitHub https://github.com/microsoft/vscode/issues/125993#issuecomment-912993126, or unsubscribe https://github.com/notifications/unsubscribe-auth/AAAZUFHQNWWZAHX4ZHERW6TUAI4JDANCNFSM46P5GTIA . Triage notifications on the go with GitHub Mobile for iOS https://apps.apple.com/app/apple-store/id1477376905?ct=notification-email&mt=8&pt=524675 or Android https://play.google.com/store/apps/details?id=com.github.android&referrer=utm_campaign%3Dnotification-email%26utm_medium%3Demail%26utm_source%3Dgithub.

cernec1999 commented 3 years ago

I'm on Ubuntu 20.04 with code 1.60.1. I attempted to update the include path for a C++ project. My VSCode was installed through snap. Here is the error:

Error loading webview: Error: Could not register service workers: InvalidStateError: Failed to register a ServiceWorker: The document is in an invalid state..
lubomir-brindza commented 3 years ago

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.

xscd commented 3 years ago

Some extensions (which depends on webview I assume) don't work. Details of extenions also don't load. Not sure if its related to this issue since they start to work when --no-sandbox flag is passed some comments here say they don't work even with that flag passed.

Fedora Linux 35. Visual Studio Code 1.60.1

bstivers commented 3 years ago

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)
zouyonghao commented 3 years ago

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
jimsnab commented 3 years ago

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.

Fdawgs commented 3 years ago

Running into this on Windows 10 after updating VS Code from v1.60 to v1.61 (x64).

8bitmp3 commented 3 years ago

@karasowles @dynamicwebpaige Codespaces has been affected too, can't use notebooks. PTAL 🙏

after updating VS Code from v1.60 to v1.61 (x64).

This appeared after vscode update to 1.16.0 x64 for me today

Likely because of ⬆️ ?

Similar issues: https://github.com/microsoft/vscode/issues/122951 and https://github.community/t/the-user-denied-permission-to-use-service-worker-when-using-codespaces/195324

[Update] Make sure 3rd party 🍪 are allowed in your browser, then clean the 🍪, and restart ✅

klequis commented 3 years ago

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.

Same here. I was having this error with the Git Lens extension of Ubuntu 20.04.

There were 10 or so processes that said "code". Once killed I was able to activate Git Lens without issue.

rajasekhar911 commented 3 years ago

Facing the issue with Git History (0.6.18) extension on VSCode (1.61.2) on Ubnutu 21.04 Error loading webview: Error: Could not register service workers: InvalidStateError: Failed to register a ServiceWorker: The document is in an invalid state.

joshxyzhimself commented 3 years ago

If restarting VSCode doesn't work, maybe try restarting your OS?

https://github.com/microsoft/vscode/issues/122951#issuecomment-947484995

ruionwriting commented 3 years ago

In my case using Code OSS (Manjaro Linux) the solution from @tritemio worked like a charm. The only difference was the cache folder location:

rm -rf ~/.config/Code\ -\ OSS/*Cache*
Version: 1.61.0
Commit: ee8c7def80afc00dd6e593ef12f37756d8f504ea
Date: 2021-10-10T18:20:55.439Z
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.13.19-2-MANJARO
spinicist commented 3 years ago

I've also used the solution from @tritemio successfully. I'm using VS Code on a Linux cluster, I have no ability to reboot the machine. So big thanks to them.

mattangus commented 3 years ago

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!

deepak1556 commented 3 years ago

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