- From: omarsandoval1 <notifications@github.com>
- Date: Wed, 25 Jan 2023 04:22:40 -0800
- To: w3c/ServiceWorker <ServiceWorker@noreply.github.com>
- Cc: Subscribed <subscribed@noreply.github.com>
- Message-ID: <w3c/ServiceWorker/issues/1580/1403525980@github.com>
> ### Scenario
>
> Try to make HMR work inside service worker.
>
> Dynamic reload webpack generated "/a.hashid.js".
>
> Found DOMExeption.
>
>
>
> ### Code that boom
>
> ```sh
>
> $ cat a.js
>
> console.log(42);
>
> $ cat serviceWorker.js
>
> ```
>
> ```js
>
> // importScripts('/a.hashid.js');
>
>
>
> // (()=>{
>
> // importScripts('/a.hashid.js');
>
> // })();
>
>
>
> setTimeout(()=>{
>
> importScripts('/a.hashid.js');
>
> }, 1000);
>
>
>
> setInterval(()=>{
>
> importScripts('/a.hashid.js');
>
> }, 1000);
>
> ```
>
>
>
> ### Actual Output
>
> ```txt
>
> Uncaught DOMException: Failed to execute 'importScripts' on 'WorkerGlobalScope': The script at '<foobar>/a.js' failed to load.
>
> at <foobar>/serviceWorker.js
>
> ```
>
> ### Expected Output
>
> ```txt
>
> 42
>
> 42
>
> 42
>
> 42
>
> 42
>
> ...
>
> ```
>
> ### Code that works
>
> ```sh
>
> $ cat a.js
>
> console.log(42);
>
> $ cat serviceWorker.js
>
> ```
>
> ```js
>
> importScripts('/a.js');
>
>
>
> (()=>{
>
> importScripts('/a.js');
>
> })();
>
>
>
> setTimeout(()=>{
>
> importScripts('/a.js');
>
> }, 1000);
>
>
>
> setInterval(()=>{
>
> importScripts('/a.js');
>
> }, 1000);
>
> ```
>
> output:
>
> ```txt
>
> 42
>
> 42
>
> 42
>
> 42
>
> 42
>
> ...
>
> ```
>
>
>
> ### Maybe
>
> [issue838](https://github.com/w3c/ServiceWorker/issues/838) maybe related?
>
> "setTimeout/setInterval are unreliable in ServiceWorker"
>
>
>
> Not quite sure whether it is a bug or a feature, seems firefrox and chrome both fail.
>
> Hope it is the right place to fire this issue. :)
--
Reply to this email directly or view it on GitHub:
https://github.com/w3c/ServiceWorker/issues/1580#issuecomment-1403525980
You are receiving this because you are subscribed to this thread.
Message ID: <w3c/ServiceWorker/issues/1580/1403525980@github.com>
Received on Wednesday, 25 January 2023 12:22:53 UTC