NekitCorp / chrome-extension-svelte-typescript-boilerplate

Boilerplate for Chrome Extension Svelte Typescript project
235 stars 49 forks source link

Waiting for service worker #12

Open erezsh opened 1 year ago

erezsh commented 1 year ago

Interacting with the boilerplate extension after letting the service worker to become inactive, we are greeting with the aforementioned message, which doesn't go away until we close and open the page again -

image

image

I think the desired behavior would be to hide this message once the worker is done loading.

NekitCorp commented 1 year ago

This is the message from crxjs: https://github.com/crxjs/chrome-extension-tools/issues/449

Follow the link to find out why this happens and what it affects. In short, this error only occurs during development and due to the fact that you turn off the development dev Vite server.

And so try just start the dev server:

npm run dev

Or you can build production version of extension (npm run build) and reload extension (in chrome://extensions).

erezsh commented 1 year ago

This happens while the server is running.

The worker starts immediately after displaying that message, and reloading the page gets rid of the message. But I think the reload should be automatic?

NekitCorp commented 1 year ago

I don't quite understand what the problem is, could you send me the steps to reproduce and the expected behavior please? And also please tell me this problem is reproduced in a clean fork chrome-extension-svelte-typescript-boilerplate?

NekitCorp commented 1 year ago

And once again I repeat that this error occurs only during development. In production, this error will not occur. It seems to me that the case with disabling the service worker is quite rare (because, for example, chrome works in the backround mode even when the browser is closed and the service worker continues to work), so simply reopening the extension to solve this problem in development mode is enough. In general, after reopening, the extension will already know about restarting the server worker.

Screen Recording 2023-01-30 at 15 40 13

erezsh commented 1 year ago

Yes, this happens with a clean fork.

Steps are simple:

  1. Run extension
  2. Wait for service worker to become idle (takes about a minute)
  3. Open options / popup, and get this message
  4. Opening options / popup again immediately after will work as expected.

I understand this only happens in dev mode.

Whether it's enough or not is, I suppose, subjective. But I think that if the boilerplate knows to show this error page, it shouldn't be that hard to just wait for the worker to be ready and reload? It would definitely be a nicer dev experience.

NekitCorp commented 1 year ago

Oh, thanks, i get what you mean. I agree, sounds like a nice dev experience. But unfortunately, I can’t influence this logic in this boilerplate. Because this is the package logic from https://github.com/crxjs/chrome-extension-tools.

I think you can bring this idea to this issue: https://github.com/crxjs/chrome-extension-tools/issues/449.