question-mark
Stuck on an issue?

Lightrun Answers was designed to reduce the constant googling that comes with debugging 3rd party libraries. It collects links to all the places you might be looking at while hunting down a tough bug.

And, if you’re still stuck at the end, we’re happy to hop on a call to see how we can help out.

service-worker script wont load from non-root path

See original GitHub issue
  • code-server version: 1.939-vsc1.33.1
  • OS Version: irrelevant

Description

We are running code-server behind a reverse proxy that uses paths instead of distinct domains. e.g. domain.com/ide/123456. The service-worker script introduced in #154 will try to load the script from domain.com/service-worker.js instead of domain.com/ide/123456/service-worker.js.

~It should be sufficient~ (it’s not) to remove the leading slash in navigator.serviceWorker.register("/service-worker.js");. So either navigator.serviceWorker.register("./service-worker.js"); or navigator.serviceWorker.register("service-worker.js");. But I haven’t tested all scenarios, yet.

Issue Analytics

  • State:closed
  • Created 4 years ago
  • Comments:11 (7 by maintainers)

github_iconTop GitHub Comments

1reaction
geisericommented, May 28, 2019

Actually, the register worked, it was the resulting CSP issues that popped up later. I got around some with making workbox local vs hosted on the CDN. I will PR that part while I work out a better solution on the CSP.

1reaction
HenningCashcommented, May 27, 2019

@geiseri what issues did you encountered while working on this? The simple navigator.serviceWorker.register('service-worker.js', {scope: './'}) solution seems to work fine for me.

Paths from the manifest and links to assets inside the index.html shouldnt be a problem:

  • Relative paths inside the index.html are loaded relative to the document (you only have to ensure your URL ends in a slash which should be the case when using a reverse-proxy anyway)
  • Relative paths inside the manifest are loaded relative to the manifest-URL

I would love to see a solution without another CLI-option. The IDE shouldn’t care about where it is mounted.

Read more comments on GitHub >

github_iconTop Results From Across the Web

service-worker script wont load from non-root path #670 - GitHub
The service-worker script introduced in #154 will try to load the script from domain.com/service-worker.js instead of domain.com/ide/123456/ ...
Read more >
Service worker is not being used on non root path
It's registering, adding all the files I need to the cache, but it's not being used. My service worker is registering with scriptURL...
Read more >
Using Service Workers - Web APIs | MDN
The path to your service worker file is not written correctly — it needs to be written relative to the origin, not your...
Read more >
How to add service-worker.js file at the root directory with any ...
I want to add service-worker.js file at the root directory for the push notification. I found that root directory can not edit as...
Read more >
A guide to Service Workers - pitfalls and best practices
One of the early mistakes that one might make, is to include the service worker script into some sub-directory without specifying a scope....
Read more >

github_iconTop Related Medium Post

No results found

github_iconTop Related StackOverflow Question

No results found

github_iconTroubleshoot Live Code

Lightrun enables developers to add logs, metrics and snapshots to live code - no restarts or redeploys required.
Start Free

github_iconTop Related Reddit Thread

No results found

github_iconTop Related Hackernoon Post

No results found

github_iconTop Related Tweet

No results found

github_iconTop Related Dev.to Post

No results found

github_iconTop Related Hashnode Post

No results found