chrome-extension-tools icon indicating copy to clipboard operation
chrome-extension-tools copied to clipboard

Service worker has not loaded fully

Open rahulbansal16 opened this issue 1 year ago • 5 comments

Build tool

Vite

Where do you see the problem?

  • [X] In the browser
  • [ ] In the terminal

Describe the bug

Hi everyone,

I was following the CRXJS tutorial https://crxjs.dev/vite-plugin/getting-started/react/create-project for creating an extension using react.

I was successfully able to create the extension. It was working perfectly and I let the extension stay in my browser without changing anything.

After 3-4 days I got an error on clicking the extension icon "Service worker has not loaded fully."

Screenshot 2022-07-09 at 12 40 33 PM

The service worker related to the extension is not shown in the chrome://inspect/#service-workers

Screenshot 2022-07-09 at 12 56 19 PM Screenshot 2022-07-09 at 12 57 13 PM

Reproduction

  1. Follow the tutorial https://crxjs.dev/vite-plugin/getting-started/react/create-project
  2. Let the extension in your browser for sometime without clicking it etc.

Logs

No response

System Info

npx: installed 1 in 1.516s

  System:
    OS: macOS 12.3.1
    CPU: (12) x64 Intel(R) Core(TM) i7-9750H CPU @ 2.60GHz
    Memory: 68.94 MB / 16.00 GB
    Shell: 5.8 - /bin/zsh
  Binaries:
    Node: 14.17.4 - ~/.nvm/versions/node/v14.17.4/bin/node
    Yarn: 1.22.19 - ~/.nvm/versions/node/v14.17.4/bin/yarn
    npm: 6.14.14 - ~/.nvm/versions/node/v14.17.4/bin/npm
  Browsers:
    Brave Browser: 101.1.38.119
    Chrome: 103.0.5060.114
    Chrome Canary: 105.0.5168.0
    Safari: 15.4
  npmPackages:
    @crxjs/vite-plugin: 1.0.12 => 1.0.12 
    vite: ^2.9.9 => 2.9.13

Severity

blocking all usage of RPCE

rahulbansal16 avatar Jul 09 '22 07:07 rahulbansal16

Hi. Try to reload your extension

in chrome://extensions

It work for me

Have a nice day :)

Kazdan1994 avatar Jul 13 '22 12:07 Kazdan1994

I did reloading it did not work for me. I am worried How to deal with this if it happens at the production extension at some user browser?

rahulbansal16 avatar Jul 13 '22 13:07 rahulbansal16

If you are seeing "Waiting for service worker", it means that the extension is the development build. During development, Vite serves the background and extension page files from localhost, so Vite must be running in the terminal.

@rahulbansal16 When you run the build command, the production version of the extension will include the background files, so everything will work.

jacksteamdev avatar Jul 14 '22 01:07 jacksteamdev

We should change the "Waiting..." message to guide the developer to either start Vite or run the build command.

This is a great first issue, anyone who is interested in contributing can start here: https://github.com/crxjs/chrome-extension-tools/blob/a8d567092f0cb4e27ce781d009e8e856cdae33b1/packages/vite-plugin/src/client/html/precontroller.html

jacksteamdev avatar Jul 14 '22 01:07 jacksteamdev

@jacksteamdev I just started the npm run dev and it started working. Thanks for your help.

rahulbansal16 avatar Jul 24 '22 11:07 rahulbansal16

Hello! I wanted to ask, why not wait for the service worker to be ready, and then reload the page?

This logic seems to be attempted here: https://github.com/crxjs/chrome-extension-tools/blob/a8d567092f0cb4e27ce781d009e8e856cdae33b1/packages/vite-plugin/src/client/es/page-precontroller-script.ts (close enough)

But for some reason it doesn't work?

erezsh avatar Jan 30 '23 13:01 erezsh

Hi, I had get same error, and fixed like below....

  1. make cert with mkcert
  2. add cert configuraton to vite.config like this.
server: {
    https: {
      key: fs.readFileSync('./localhost-key.pem'),
      cert: fs.readFileSync('./localhost.pem'),
    },
  },
  1. launch vite dev server
  2. change http to https in service-worker-loader.js

I guess, Chrome not permit to access via http in default. Can I have any way that fix this?

shoota avatar Mar 14 '23 16:03 shoota

In my case, I build the dist from vite and then add a file in the web extension. After a review from google. the same issue arises. image

At local it runs fine. image

If I add a dist file in chrome in development mode it runs fine

what should steps I take to resolve this issue

Nawa-raj avatar Mar 23 '23 03:03 Nawa-raj

I am guessing you have not done npm run build before publishing.

On Thu, Mar 23, 2023, 09:08 Nawaraj Jaishi @.***> wrote:

In my case, I build the dist from vite and then add a file in the web extension. After a review from google. the same issue arises. [image: image] https://user-images.githubusercontent.com/24637410/227095805-35aa860a-9256-4904-9483-e2be1529c825.png

At local it runs fine. [image: image] https://user-images.githubusercontent.com/24637410/227095924-0680125f-be69-402b-9a4d-07cc811b70e8.png

If I add a dist file in chrome in development mode it runs fine

what should steps I take to resolve this issue

— Reply to this email directly, view it on GitHub https://github.com/crxjs/chrome-extension-tools/issues/449#issuecomment-1480555739, or unsubscribe https://github.com/notifications/unsubscribe-auth/ACAS47MD3TT5UEILCSJJZ33W5PAT3ANCNFSM53C6UWTQ . You are receiving this because you were mentioned.Message ID: @.***>

rahulbansal16 avatar Apr 08 '23 03:04 rahulbansal16

This issue is still not resolved? Could you please advice on how to solve this? @jacksteamdev

The popup shows waiting for service worker. Service worker inactive.

  1. Vite development is running in the terminal
  2. Tried reloading the extension
  3. Vite production build is working

Any solution appreciated.

ivalsaraj avatar Apr 30 '23 13:04 ivalsaraj

@jacksteamdev, my case is similar @ivalsaraj 's . I would appreciate any solution

paularah avatar May 04 '23 00:05 paularah

I've had this temperamentally and restarting chrome fixed it.

adamscybot avatar May 06 '23 15:05 adamscybot

Same issue and I noticed there seems to be an issue loading the env in server-worker-loader

import 'http:/localhost:3000/@vite/env';
import 'http://localhost:3000/crx-client-worker';

It's built with http:/ missing the second forward slash. Anyone else seeing that? Built for vue.

in index.cjs on line 3518 loader = import 'http:/localhost:${port}/@vite/env';`

ericuldall avatar May 17 '23 19:05 ericuldall

Fixing that doesn't seem to resolve the issue. I get a cors error in chrome extension logs:

Access to script at 'http://localhost:3000/crx-client-worker' from origin 'chrome-extension://gcnpefeokmmfpfbihpigfjmiancnjnhi' has been blocked by CORS policy: No 'Access-Control-Allow-Origin' header is present on the requested resource.

ericuldall avatar May 17 '23 19:05 ericuldall

found my issue. Had something running on port 3000 in docker. Vite is not port aware against non vite process' it seems.

ericuldall avatar May 17 '23 19:05 ericuldall

In my case, this only happens when there's code in the background script. Emptying the background script stops the error which is quite weird.

paularah avatar Jun 30 '23 00:06 paularah

In my case, it did not load service worker because file name was pascal-case.

cenkce avatar Sep 06 '23 21:09 cenkce

AFAIK this happens when you have error in background script. Clear error then it will load as usual.

mubaidr avatar Oct 15 '23 14:10 mubaidr

For anyone running into this issue, try doing npm run dev -- --host.

dpacmittal avatar Jan 06 '24 10:01 dpacmittal

For anyone running into this issue, try doing npm run dev -- --host.

This is the solution when your extension is running on a different port. A typical case when this happens is if you have another app already running on the default port 3000.

rojakcoder avatar Jan 21 '24 04:01 rojakcoder

Probably FOUND a solution!

The issue reproduces with the following version: "@crxjs/vite-plugin": "^1.0.14". But when I installed beta version of the package — the issue have disappeared.

So, just run the following:

bun i -D @crxjs/vite-plugin@beta

(or using npm/yarn etc).

supfiger avatar Feb 21 '24 02:02 supfiger