-
Notifications
You must be signed in to change notification settings - Fork 295
ServiceWorker cannot be started #1180
New issue
Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.
By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.
Already on GitHub? Sign in to your account
Comments
@mho22 Would manually removing the service worker in devtools unblock you? I'm not sure why that problem happens either, perhaps @brandonpayton would have some insights. A quick solution could be to wrap it in try/catch (but only in the local development environment) and propagate the error to the logger. |
@adamziel Anytime the page refreshes, it returns the error. Even if I remove the service worker in devtools manually. I wrapped the line in a
![]() |
Hi @mho22, I don't have any immediate ideas about this, but if you're interested, I am up for joining you for a screen share via WordPress.org Slack (assuming Slack huddles are supported there). Either way, I have a few questions that might help us troubleshoot and/or reproduce your issue:
|
It's puzzling how this could just be a problem with updating though. |
@brandonpayton sorry for the delay. OS : Mac OS Sonoma 14.4.1 (23E224) I only have to comment the line
So I suppose if you add a Edit: I found information on this link stating that the
I am not entirely certain about the reason and solution, by the way. |
While that’s a good find, I’m also confused because I thought Service Workers in general are only allowed in secure contexts: #1098 Could it be that localhost is a special case where one can user service workers but not the update() method? But why would it only fail sometimes? |
Thanks for the info, @mho22. I just ran into this same issue in Chrome Canary (Version 125.0.6401.0 (Official Build) canary (x86_64)):
@mho22 and @adamziel, localhost is indeed a special according to this:
This made me wonder about explicitly using the loopback address 127.0.0.1 instead of "localhost", and that did the trick. Chrome loaded local Playground successfully and presumably was able to update the service worker as part of the process. I wonder if we can have |
I created PR #1209 to use |
@brandonpayton briliant! I suppose we can close this issue. |
This PR fixes #1180 - Playground on localhost sometimes fails to load due to failed service worker updates from "localhost". ## How is the problem addressed? By switching from "localhost" to the explicit loopback address "127.0.0.1". This avoids the case where "localhost" does not directly resolve to a loopback address. For reference: https://w3c.github.io/webappsec-secure-contexts/#localhost > Section 6.3 of [[RFC6761]](https://w3c.github.io/webappsec-secure-contexts/#biblio-rfc6761) lays out the resolution of localhost. and names falling within .localhost. as special, and suggests that local resolvers SHOULD/MAY treat them specially. For better or worse, resolvers often ignore these suggestions, and will send localhost to the network for resolution in a number of circumstances. > > Given that uncertainty, user agents MAY treat localhost names as having [potentially trustworthy origins](https://w3c.github.io/webappsec-secure-contexts/#potentially-trustworthy-origin) if and only if they also adhere to the localhost name resolution rules spelled out in [[let-localhost-be-localhost]](https://w3c.github.io/webappsec-secure-contexts/#biblio-let-localhost-be-localhost) (which boil down to ensuring that localhost never resolves to a non-loopback address). ## Testing Instructions Run `npm run dev` and confirm the new dev server URL is `http://127.0.0.1:5400/website-server/` and that local Playground loads successfully in your browser.
I'am having the same problem in Firefox asking for both http://localhost:5400 and http://127.0.0.1:5400 Firefox version is 115.9.1esr (64 bit) errors are:
There is no issue in chrome 123.0.6312.105 (on the same linux machine). |
Localhost still exists in some places it might be worth updating everything to 127.0.0.1. @MocioF we also had this issue in Firefox before changing to 127.0.0.1. |
@MocioF, I believe this is due to Firefox not yet supporting ES module-based service workers. See #330. On playground.wordpress.net, the built service worker script does not contain any syntax specific to ES modules, so it works in Firefox. But during local dev with |
In retrospect, it seems obvious that this search should have been done in the original PR. Thank you for bringing this up, @bgrgicak! I made a note to follow up on this. |
I'm not sure switching to 127.0.0.1 did anything to fix this. Afterward, I continued to see ServiceWorker update errors in Chrome. Now that we have merged #1849, I am no longer seeing these errors. Since 127.0.0.1 seems like a more reliable loopback address than |
Please disregard the above. It was incorrect. Switching to any other commit and running the dev server still reveals this issue. In practice, it's not too annoying because we don't edit the Service Worker too often, but I'm going to reopen this issue to track it. |
When attempting to run
npm run dev
locally, I encountered this error:It's evidently linked to a
ServiceWorker
update issue.Upon examining the code, I discovered this line in
packages/php-wasm/web/src/lib/register-service-worker.ts
on line47
:When I comment this line, everything works fine.
Here is a
console.log
of theregistration
object:I don't know if something is wrong or missing on my side, that's why I wrote this issue.
The text was updated successfully, but these errors were encountered: