Skip to content

Service Worker not defined while accessing PWA in development #3834

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

Closed
GirlBossRush opened this issue Jul 21, 2021 · 14 comments
Closed

Service Worker not defined while accessing PWA in development #3834

GirlBossRush opened this issue Jul 21, 2021 · 14 comments
Labels
bug Something isn't working high-priority This issue needs to be resolved ASAP
Milestone

Comments

@GirlBossRush
Copy link
Contributor

As first reported in a PR by @cuining, this regression seems to be introduced in the move away from Parcel.

I believe this may be addressed in #3833, but some more information is still needed.

OS/Web Information

  • Web Browser: Chrome
  • Local OS: macOS
  • Remote OS: macOS
  • Remote Architecture: 64 bit
  • code-server --version: 3.11.0

Steps to Reproduce

  1. Start code-server via yarn watch
  2. Open in Chrome, add a PWA shortcut
  3. Refresh

Expected

No console errors should occur.

Actual

Service worker registration fails due to an invalid path. However, the file is available at an different path.

Screenshot

Screen Shot 2021-07-21 at 14 40 39

@GirlBossRush GirlBossRush added bug Something isn't working help-wanted high-priority This issue needs to be resolved ASAP needs-investigation This issue needs to be further investigated labels Jul 21, 2021
@GirlBossRush GirlBossRush added this to the 3.12.0 milestone Jul 21, 2021
@jsjoeio
Copy link
Contributor

jsjoeio commented Jul 21, 2021

Apologies @cuining for prematurely closing your PR and thank you for raising the issue! ♥️ (and @TeffenEllis for following up on this!)

3.11

I am not able to reproduce in 3.11, which is a good sign.

image

Local development

I am also not able to reproduce 🤔 (macOS + Brave)

image

@jsjoeio
Copy link
Contributor

jsjoeio commented Jul 21, 2021

Wait, premature comment, I did not refresh

@jsjoeio
Copy link
Contributor

jsjoeio commented Jul 21, 2021

Video

Screen.Recording.2021-07-21.at.2.25.43.PM.mov

Okay so actually I believe this is a different bug. I told @code-asher about this a while ago but couldn't reproduce consistently. This happened before the migration away from Parcel.

The workaround is to close the PWA and reopen.

But the fact that you're seeing the raw JS in the browser feels odd and I wonder if these are two separate bugs or the same, manifesting differently 🤔

@lsoica
Copy link

lsoica commented Jul 22, 2021

I have the same issue with 3.11. It looks for the serviceWorker.js at /node_modules/code-server/dist/serviceWorker.js but in fact the new location is /node_modules/code-server/out/browser/serviceWorker.js

@jsjoeio
Copy link
Contributor

jsjoeio commented Jul 22, 2021

Ahhh, I must have forgot to change it in one place. Thank you for the tip @lsoica!

@jsjoeio
Copy link
Contributor

jsjoeio commented Jul 22, 2021

Could this be a caching issue? i.e. it cached the old path. Would a hard refresh fix it?

@lsoica
Copy link

lsoica commented Jul 22, 2021

Cleaning app cache and browser file cache didn't help. Anything else that I've missed ?

@jsjoeio
Copy link
Contributor

jsjoeio commented Jul 22, 2021

Nope! Thank you for trying. cc @code-asher in case he has any other ideas. We're going to look at this in the next cycle (starting next week 🤞)

@code-asher
Copy link
Member

code-asher commented Jul 22, 2021

Ack we didn't update this path!

https://github.com/cdr/code-server/blob/7b8cd25c0c48b6a1799587ebbc9b09d6af7988f3/src/browser/register.ts#L8

We probably didn't notice during development because we had the old Parcel dist directory from previous builds.

@code-asher
Copy link
Member

Looks like we should re-open that PR as it has the right fix.

@jsjoeio
Copy link
Contributor

jsjoeio commented Jul 22, 2021

Cool! I'll do that since I closed it.

@Flcn
Copy link

Flcn commented Aug 7, 2021

Same for me but in 'production'.
[Service Worker] registration: Failed to register a ServiceWorker for scope ('https://DOMAIN/') with script ('https://DOMAIN/static/4e8cd09ef0412dfc7b148b7639a692e20e4fd6dd/usr/lib/code-server/dist/serviceWorker.js'): A bad HTTP response code (404) was received when fetching the script. TypeError: Failed to register a ServiceWorker for scope ('https://DOMAIN/') with script ('https:/DOMAIN/static/4e8cd09ef0412dfc7b148b7639a692e20e4fd6dd/usr/lib/code-server/dist/serviceWorker.js'): A bad HTTP response code (404) was received when fetching the script.

The manifest looks like this

{
  "name": "code-server",
  "short_name": "code-server",
  "start_url": "./../../../../../../../..",
  "display": "fullscreen",
  "background-color": "#fff",
  "description": "Run editors on a remote server.",
  "icons": [
    {
      "src": "./../../../../../../../../static/4e8cd09ef0412dfc7b148b7639a692e20e4fd6dd/usr/lib/code-server/src/browser/media/pwa-icon-192.png",
      "type": "image/png",
      "sizes": "192x192"
    },
    {
      "src": "./../../../../../../../../static/4e8cd09ef0412dfc7b148b7639a692e20e4fd6dd/usr/lib/code-server/src/browser/media/pwa-icon-512.png",
      "type": "image/png",
      "sizes": "512x512"
    }
  ]
}

MacOS
3.11.1

@jsjoeio
Copy link
Contributor

jsjoeio commented Aug 9, 2021

Thanks for the update! This should be fixed when we get 3.11.2 out the door.

@jsjoeio jsjoeio modified the milestones: 3.12.0, 3.12.1, On Deck Sep 9, 2021
@stale
Copy link

stale bot commented Mar 14, 2022

This issue has been automatically marked as stale because it has not had recent activity. It will be closed if no activity occurs in the next 5 days.

@stale stale bot added the stale label Mar 14, 2022
@stale stale bot closed this as completed Mar 20, 2022
@code-asher code-asher removed the needs-investigation This issue needs to be further investigated label Jul 11, 2024
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
bug Something isn't working high-priority This issue needs to be resolved ASAP
Projects
None yet
Development

No branches or pull requests

5 participants