Error loading webview: Error: Could not register service workers: TypeError: Failed to register a ServiceWorker for scope

Visual Studio-Code

Visual Studio-Code Problem Overview


When I update my VSCode to v1.56.2 and open webview, I get these messages:

> Error loading webview: Error: Could not register service workers: > TypeError: Failed to register a ServiceWorker for scope > ('vscode-webview://867f875b-c5a3-4504-8de2-2e8614bdc0f8/') with script > ('vscode-webview://867f875b-c5a3-4504-8de2-2e8614bdc0f8/service-worker.js?platform=electron&id=867f875b-c5a3-4504-8de2-2e8614bdc0f8&vscode-resource-origin=https%3A%2F%2F867f875b-c5a3-4504-8de2-2e8614bdc0f8.vscode-webview-test.com'): > ServiceWorker cannot be started.

How can I solve this issue?

Visual Studio-Code Solutions


Solution 1 - Visual Studio-Code

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

Try killall code.

Solution 2 - Visual Studio-Code

I encountered this issue and am not a Windows user, so this is my resolution:

I found that there was an instance of VS Code open that was erroneously not shown on my dock. I closed this instance and opened a new instance. The problem was gone.

I think the issue happened because I had a VS Code instance open, allowed a software update to run in the background, postponed the restart, opened a new and updated VS Code instance, and the old instance remained open causing conflicts.

OS: Ubuntu 20.04.2 LTS

Solution 3 - Visual Studio-Code

In Windows, you can simply fix this error by clearing the cache for VSCode. Please follow the steps below:

  1. Close VSCode and also kill any background processes running in the task manager. Task Manager screenshot

  2. Go to the file explorer and to the path C:\Users\<user_name>\AppData\Roaming\Code and clear the contents of the folders Cache, CachedData, CachedExtensions, CachedExtensionVSIXs (if this folder exists) and Code Cache.

  3. Open VSCode and you are good to go.

Solution 4 - Visual Studio-Code

This is a known bug in VS Code 1.56. It happens for some Windows users when running VS Code as an administrator

As a workaround, you can try launching VS Code with the --no-sandbox command line flag:

$ code --no-sandbox

Solution 5 - Visual Studio-Code

@tritemio on GitHub has a great answer:

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

in short, delete cache folder:

rm -rf ~/.config/Code/Cache

Solution 6 - Visual Studio-Code

The simplest solution for this problem in any version of Linux is simply to close other instances of VS code and use only one instance of VS code. OS: Linux 20.04.3 LTS

Solution 7 - Visual Studio-Code

@tritemio, thanks for sharing.

This also seemed to solve my issues on Windows for "Extensions - Details View", "VS Code Release Notes View", "Gitlab integrated Interactive Rebase Editor", etc.

I followed your suggestion and deleted the following folders;

  • %appdata%\Code - Insiders\Cache
  • %appdata%\Code - Insiders\Code Cache

Solution 8 - Visual Studio-Code

I've also encountered the same "Error loading web view" Error. I've solved this issue by moving "vscode.app" into "Application folder" instead of "Download folder" on macOS.

I'll describe my "symptom" here.

  1. OS: macOS 12.0.1
  2. Installed 2 versions of vscode somehow, 1 under "Application folder", another under "download folder"
  3. Run both vscode at the same time, the "download folder" version has no error display plugin pages, the "Application folder" version has the "Error loading webview" error
  4. Checked and see 2 vscode instances running in the background

What I tried to solve this issue:

  1. Tried to kill "download folder" instance, and the error remains for "application folder" instance
  2. Moved "download folder" to "application folder" and both vscode works correctly on plugin page!

What I suspect on what the problem is?

Maybe these 2 vscode are sharing the same resource(could be some shared file), however they have different permissions since one is under application folder and another is under download folder.

Solution 9 - Visual Studio-Code

Happened to me when started code in windows cmd. Closed vs code and opened it from my taskbar shortcut instead, and the error was gone

Attributions

All content for this solution is sourced from the original question on Stackoverflow.

The content on this page is licensed under the Attribution-ShareAlike 4.0 International (CC BY-SA 4.0) license.

Content TypeOriginal AuthorOriginal Content on Stackoverflow
QuestionyiwanmianView Question on Stackoverflow
Solution 1 - Visual Studio-CodeyavorbelView Answer on Stackoverflow
Solution 2 - Visual Studio-CodeSydney YView Answer on Stackoverflow
Solution 3 - Visual Studio-CodeKshitij AgarwalView Answer on Stackoverflow
Solution 4 - Visual Studio-CodeMatt BiernerView Answer on Stackoverflow
Solution 5 - Visual Studio-CodeDarius ZiView Answer on Stackoverflow
Solution 6 - Visual Studio-CodeShreyash PandeyView Answer on Stackoverflow
Solution 7 - Visual Studio-CodeThomas GeensView Answer on Stackoverflow
Solution 8 - Visual Studio-CodeCoconutsjellyView Answer on Stackoverflow
Solution 9 - Visual Studio-CodeAli AnwarView Answer on Stackoverflow