microsoft / vscode

Visual Studio Code
https://code.visualstudio.com
MIT License
161.76k stars 28.44k 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..
danielpenagos commented 2 years ago

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

eleach commented 2 years ago

I'm on Ubuntu 20.04, vsCode 1.62.2, installed with snap.

The tritemio steps work very briefly for me and then the same error happens over and over again. Is there any chance this will ever be fixed? Sorry I'm not very helpful here. This is completely ruining my vscode experience. (I wanted to try copilot.) I'm going to try downgrading to 1.55.2 and see what happens.

flavianojs commented 2 years ago

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
strowk commented 2 years ago

I am getting this error after running git rebase -i, because I have set git config --global core.editor "code --wait" , but now I have to switch back to vim. This is so annoying. Issues like this make me want to disable autoupdates, vscode is so unstable lately. Ubuntu 20.04, vscode 1.62.3

Restarting vscode seems to help sometimes, but after some time, error is back again.

mjunior commented 2 years ago

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

salouri commented 2 years ago

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

Update: Rebooting fixed the issue, thanks @tritemio

rebooteed what? vscode or OS ?

sketchbuch commented 2 years ago

OS

sketchbuch commented 2 years ago

Still having this issue: v1.63.2

rjmsilveira commented 2 years ago

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

GuillaumeAmat commented 2 years ago

On my end, the issue was that I had it installed from both the repo package (Fedora 35) and the Flathub one. I guess they have a common library path (or service port) but expect different versions of them.

Removing one of them and restarting the remaining VSCode fixes it for good :ok_hand:

bmh129 commented 2 years ago

I had same problem as the OP (Webview Service Worker Error...), but on a 2012 Mac Mini running macOS 10.15.7, running the following VSCode from the official website:

Version: 1.63.2 (Universal) Commit: 899d46d82c4c95423fb7e10e68eba52050e30ba3 Date: 2021-12-15T09:37:28.172Z Electron: 13.5.2 Chromium: 91.0.4472.164 Node.js: 14.16.0 V8: 9.1.269.39-electron.0 OS: Darwin x64 19.6.0

This problem persisted for my setup for all VSCode versions since 1.58.2. For me, the problem only existed when VSCode was run without elevated privileges. To restate, the problem did not present if I ran VSCode under sudo.

I was able to resolve my issue by doing the following:

Drag the VSCode app to the trash, empty the trash, then, from the terminal, remove the entire folder at ~/Library/Application Support/Code, followed by a reboot, then installation of the latest VSCode.

avarayr commented 2 years ago

Easy repro for Intel Macbook (MacOS 12.1), please try with your OS with appropriate hotkeys.

  1. Quit all instances of vscode
  2. Open terminal
  3. code-insiders test.ipynb
  4. Wait for VSCode to load completely (~15 seconds)
  5. Cmd+Q to quit vscode
  6. Quickly back to terminal, up arrow, Enter to run the same command again

It only works when you're quick on step 4 and 5. Waiting after step 4 will not repro.

agileVtalal commented 2 years ago

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

LucienMP commented 2 years ago

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

RovoMe commented 2 years ago

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

thelumiereguy commented 2 years ago

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

Same here! Thanks!

zeroxia commented 2 years ago

I have never encountered this issue on macOS or Windows before. But with Linux Ubuntu 18.04, this issue is not rare. Just had this problem when requesting Markdown: open preview to the side (Ctrl+K V), then quit all VSCode instances and start again the preview is rendered.

VSCode version:

Version: 1.64.2
Commit: f80445acd5a3dadef24aa209168452a3d97cc326
Date: 2022-02-09T22:02:29.527Z
Electron: 13.5.2
Chromium: 91.0.4472.164
Node.js: 14.16.0
V8: 9.1.269.39-electron.0
OS: Linux x64 5.4.0-100-generic

I believe this should be the "standard version":

$ cat /etc/apt/sources.list.d/vscode.list 
### THIS FILE IS AUTOMATICALLY CONFIGURED ###
# You may comment out this entry, but any other modifications may be lost.
deb [arch=amd64,arm64,armhf] http://packages.microsoft.com/repos/code stable main
$ code --list-extensions
alefragnani.Bookmarks
azemoh.one-monokai
BazelBuild.vscode-bazel
cschlosser.doxdocgen
dbaeumer.vscode-eslint
eamodio.gitlens
GitHub.copilot
golang.go
jebbs.plantuml
jeff-hykin.better-cpp-syntax
llvm-vs-code-extensions.vscode-clangd
mark-wiemer.vscode-autohotkey-plus-plus
mjohns.clang-format
ms-python.python
ms-python.vscode-pylance
ms-toolsai.jupyter
ms-toolsai.jupyter-keymap
ms-vscode-remote.remote-containers
ms-vscode-remote.remote-ssh
ms-vscode-remote.remote-ssh-edit
ms-vscode-remote.remote-wsl
ms-vscode.cmake-tools
ms-vscode.cpptools
ms-vscode.cpptools-themes
ms-vscode.powershell
streetsidesoftware.code-spell-checker
twxs.cmake
vadimcn.vscode-lldb
vscodevim.vim
zero-plusplus.vscode-autohotkey-debug
zxh404.vscode-proto3
viluon commented 2 years ago

Just updated to 1.64.2 and was getting this issue with any webview (release notes, UI settings, extensions pages, ...). pkill code and starting again fixed this.

V0XNIHILI commented 2 years ago

Just had this on Ubuntu 20.04:

Commit: b5205cc8eb4fbaa726835538cd82372cc0222d43
Date: 2022-03-02T11:12:36.248Z
Electron: 13.5.2
Chromium: 91.0.4472.164
Node.js: 14.16.0
V8: 9.1.269.39-electron.0
OS: Linux x64 5.13.0-30-generic snap

For me (for now at least) restarting my computer worked.

jpaddeo commented 2 years ago

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!

fede-r1c0 commented 2 years ago

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

this has worked for me on manjaro linux

elmarsto commented 2 years ago

Worked for me as well. Ubuntu 20.04. Which, ironically, I am just now able to use again for work

duaneking commented 2 years ago

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

xbbkok commented 2 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.

Thanks, it works

liubomyr123 commented 2 years ago

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

BreezeShane commented 2 years ago

I meet this issue on Arco Linux by accident recently. It works well formerly. The version of VScode is 1.66.0-1. And the image source is arcolinux_repo_xlarge.

arcolinux_repo_xlarge/visual-studio-code-bin 1.66.0-1 (94.7 MiB 281.1 MiB) (Installed)
    Visual Studio Code (vscode): Editor for building and debugging modern web and cloud applications (official binary version)

Anyway, I also found that VScode would have no response from time to time while I was pressing Backspace or Enter Key. I found it even more obvious when I tried to enter the path to my picture using ![xxx](...).

When I opened Preview Card, I found the log updated. Here is the new log:

[2022-04-10 16:34:33.495] [exthost] [error] [yzhang.markdown-all-in-one] provider FAILED
[2022-04-10 16:34:33.495] [exthost] [error] TypeError: Cannot read properties of undefined (reading 'document')
    at f (/home/user/.vscode/extensions/yzhang.markdown-all-in-one-3.4.0/dist/extension.js:1:296467)
    at p (/home/user/.vscode/extensions/yzhang.markdown-all-in-one-3.4.0/dist/extension.js:1:293567)
    at g (/home/user/.vscode/extensions/yzhang.markdown-all-in-one-3.4.0/dist/extension.js:1:295259)
    at v.provideCodeLenses (/home/user/.vscode/extensions/yzhang.markdown-all-in-one-3.4.0/dist/extension.js:1:298023)
    at o.provideCodeLenses (/opt/visual-studio-code/resources/app/out/vs/workbench/api/node/extensionHostProcess.js:85:96644)
    at /opt/visual-studio-code/resources/app/out/vs/workbench/api/node/extensionHostProcess.js:85:124517
    at Q._withAdapter (/opt/visual-studio-code/resources/app/out/vs/workbench/api/node/extensionHostProcess.js:85:123100)
    at Q.$provideCodeLenses (/opt/visual-studio-code/resources/app/out/vs/workbench/api/node/extensionHostProcess.js:85:124495)
    at i._doInvokeHandler (/opt/visual-studio-code/resources/app/out/vs/workbench/api/node/extensionHostProcess.js:89:13826)
    at i._invokeHandler (/opt/visual-studio-code/resources/app/out/vs/workbench/api/node/extensionHostProcess.js:89:13510)
    at i._receiveRequest (/opt/visual-studio-code/resources/app/out/vs/workbench/api/node/extensionHostProcess.js:89:12119)
    at i._receiveOneMessage (/opt/visual-studio-code/resources/app/out/vs/workbench/api/node/extensionHostProcess.js:89:10841)
    at /opt/visual-studio-code/resources/app/out/vs/workbench/api/node/extensionHostProcess.js:89:8947
    at u.invoke (/opt/visual-studio-code/resources/app/out/vs/workbench/api/node/extensionHostProcess.js:58:145)
    at v.fire (/opt/visual-studio-code/resources/app/out/vs/workbench/api/node/extensionHostProcess.js:58:1856)
    at d.fire (/opt/visual-studio-code/resources/app/out/vs/workbench/api/node/extensionHostProcess.js:66:19034)
    at /opt/visual-studio-code/resources/app/out/vs/workbench/api/node/extensionHostProcess.js:104:34275
    at u.invoke (/opt/visual-studio-code/resources/app/out/vs/workbench/api/node/extensionHostProcess.js:58:145)
    at v.fire (/opt/visual-studio-code/resources/app/out/vs/workbench/api/node/extensionHostProcess.js:58:1856)
    at d.fire (/opt/visual-studio-code/resources/app/out/vs/workbench/api/node/extensionHostProcess.js:66:19034)
    at o._receiveMessage (/opt/visual-studio-code/resources/app/out/vs/workbench/api/node/extensionHostProcess.js:66:23615)
    at /opt/visual-studio-code/resources/app/out/vs/workbench/api/node/extensionHostProcess.js:66:21149
    at u.invoke (/opt/visual-studio-code/resources/app/out/vs/workbench/api/node/extensionHostProcess.js:58:145)
    at v.fire (/opt/visual-studio-code/resources/app/out/vs/workbench/api/node/extensionHostProcess.js:58:1856)
    at v.acceptChunk (/opt/visual-studio-code/resources/app/out/vs/workbench/api/node/extensionHostProcess.js:66:15865)
    at /opt/visual-studio-code/resources/app/out/vs/workbench/api/node/extensionHostProcess.js:66:14995
    at Socket.P (/opt/visual-studio-code/resources/app/out/vs/workbench/api/node/extensionHostProcess.js:104:13797)
    at Socket.emit (node:events:390:28)
    at addChunk (node:internal/streams/readable:315:12)
    at readableAddChunk (node:internal/streams/readable:289:9)
    at Socket.Readable.push (node:internal/streams/readable:228:10)
    at Pipe.onStreamRead (node:internal/stream_base_commons:199:23)

Finally, my system info:

OS: ArcoLinux 
Kernel: 5.17.1-arch1-1 
Uptime: 28 mins 
Packages: 1580 (pacman) 
Shell: zsh 5.8.1 
Resolution: 1920x1080, 1920x1080, 1080x1920 
WM: awesome 
Theme: Arc-Dark [GTK2/3] 
Icons: Sardi-Arc [GTK2/3] 
Terminal: urxvt 
Terminal Font: MesloLGS NF-20 
CPU: Intel i5-10210U (8) @ 4.200GHz 
GPU: Intel CometLake-U GT2 [UHD Graphics] 
GPU: NVIDIA GeForce MX350 
Memory: 5637MiB / 15742MiB (35%) 

It would be kind of you to finish my issue, thank you very much!

jafarijason commented 2 years ago

If you close and re open vs code it will solve

milnomada commented 2 years ago

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

This the only one that fixed it for Osx 10.13.6

nosratullah commented 2 years ago

I'm using a Linux system and after upgrading to Vscode v 1.67 I faced the problem. Fortunately, rebooting solved my problem as mentioned in most of the comments!

jramsay commented 2 years ago

Hi @mjbvz : a few of us on the Live Share team have been reproing this quite a bit on Windows recently too.

Version: 1.67.2 (user setup) Commit: c3511e6c69bb39013c4a4b7b9566ec1ca73fc4d5 Date: 2022-05-17T18:15:52.058Z Electron: 17.4.1 Chromium: 98.0.4758.141 Node.js: 16.13.0 V8: 9.8.177.13-electron.0 OS: Windows_NT x64 10.0.18363

We use a webview for our session chat and started to see this intermittently when we attempt to open the Live Share Chat window. Verified that when this occurs it is for all webviews. Even if we disable Live Share they are broken. As others have mentioned we have to close all instances of VS Code to get out of this state.

Is there any additional info we can collect for you the next time it occurs?

image

renato-bohler commented 2 years ago

Just FYI, this happened to me on Linux (pkill code solved it for me), but I also managed to reproduce this on a bare VSCode for the web:

https://user-images.githubusercontent.com/25781956/173086228-babde1ab-a29c-4115-8cf6-0e4a68d3714d.mp4

lovettchris commented 2 years ago

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.

DuncanFaulkner commented 2 years ago

this is still an issue in 1.70 on ubuntu 20.4

c3-lukelewis commented 1 year ago

Confirming that this is still an issue in version 1.71. Running MacOS Monterey 12.3.1

We are developing our own extension, and this is consistently happen after we install our extension vsix, then restarting vscode. Our extension loads a webview shortly after activation, where we will see this error.

Repro for our case: Installing our extension, quitting vscode, then opening using code . right after will produce the error.

As previous users mentioned, completely killing code processes then starting up resolves the issue for us.

Some interesting behavior:

Denovocto commented 1 year ago

Still an Issue in 1.71 under Fedora 36

Extensions:

Graphviz Interactive Preview Version: 0.3.2 VS Marketplace Link: https://marketplace.visualstudio.com/items?itemName=tintinweb.graphviz-interactive-preview

Name: Graphviz (dot) language support for Visual Studio Code Version: 0.0.6 VS Marketplace Link: https://marketplace.visualstudio.com/items?itemName=joaompinto.vscode-graphviz

Tested both extensions individually and getting same error message.

vscode info

Version: 1.71.0 Commit: 784b0177c56c607789f9638da7b6bf3230d47a8c Date: 2022-09-01T07:25:10.472Z Electron: 19.0.12 Chromium: 102.0.5005.167 Node.js: 16.14.2 V8: 10.2.154.15-electron.0 OS: Linux x64 5.19.4-200.fc36.x86_64

shaperilio commented 1 year ago

I get this in Windows when opening Jupyter notebooks. It's intermittent, and closing VSCode and reopening "fixes" it. Once you hit the error, though, no notebook will open until you restart.

Restarting is not really a fix since that can kill active kernels...

Version: 1.71.0 (user setup) Commit: 784b0177c56c607789f9638da7b6bf3230d47a8c Date: 2022-09-01T07:36:10.600Z Electron: 19.0.12 Chromium: 102.0.5005.167 Node.js: 16.14.2 V8: 10.2.154.15-electron.0 OS: Windows_NT x64 10.0.19043 Sandboxed: No

wrouesnel commented 1 year ago

Also encountering this with the git-graph plugin on Ubuntu 22.04:

Version: 1.71.2 Commit: 74b1f979648cc44d385a2286793c226e611f59e7 Date: 2022-09-14T21:12:14.256Z Electron: 19.0.12 Chromium: 102.0.5005.167 Node.js: 16.14.2 V8: 10.2.154.15-electron.0 OS: Linux x64 5.15.0-27-generic Sandboxed: No

andresmitre commented 1 year ago

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

Productivix commented 1 year ago

same problem : no display of jpg images on Linux $ code --version 1.73.1 6261075646f055b99068d3688932416f2346dd3b x64 $ cat /etc/*release PRETTY_NAME="Debian GNU/Linux 11 (bullseye)" NAME="Debian GNU/Linux" VERSION_ID="11" VERSION="11 (bullseye)"

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

apupier commented 1 year ago

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)

beyond9thousand commented 1 year ago

bruh, is no one ever going to fix this?

tonescones commented 1 year ago

Please fix this <3

drexler commented 1 year ago

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

binarycache commented 1 year ago

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

rutvik-simformsolutions commented 1 year ago

i am getting the same issue for Laravel Artisan Extension image

AlexZeitler commented 1 year ago

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.

hummerdi commented 1 year ago

It is still here. Sad...

Version: 1.74.2
Commit: e8a3071ea4344d9d48ef8a4df2c097372b0c5161
Date: 2022-12-20T10:27:19.253Z
Electron: 19.1.8
Chromium: 102.0.5005.167
Node.js: 16.14.2
V8: 10.2.154.15-electron.0
OS: Linux x64 5.15.0-56-generic
Sandboxed: No
tkossak commented 1 year ago

Same here on Manjaro Linux and vscode 1.74.2-1 installed from AUR. Killing all code processes is a workaround meantime.

adizhol commented 1 year ago

This happens after every update from Snap on Ubuntu 20.04 please fix this...

A404coder commented 1 year ago

It really bothers me, so many features rely on this. I even can't see release Notes locally.🤯 MacOS 12.5.1 VS code 1.74.2