Skip to content
This repository was archived by the owner on Mar 14, 2024. It is now read-only.

ServiceWorkerRegistration.active and friends return null#8784

Open
jespertheend wants to merge 1 commit intoGoogleChrome:mainfrom
jespertheend:patch-1
Open

ServiceWorkerRegistration.active and friends return null#8784
jespertheend wants to merge 1 commit intoGoogleChrome:mainfrom
jespertheend:patch-1

Conversation

@jespertheend
Copy link
Copy Markdown
Contributor

Changes proposed in this pull request:

The installing, waiting and active getters on a ServiceWorkerRegistration return null now. I reckon this is outdated.

image

@malchata
Copy link
Copy Markdown
Member

malchata commented Oct 3, 2022

Once a service worker is installed, those values should be null, because the service worker has been activated after the next page refresh. Try the following in the console to check if a service worker is activated post-install:

const reg = await navigator.serviceWorker.getRegistration("/js/sw.js");
console.log(reg.active.state);

Also beware that if a service worker is not located at the root, its scope will be restricted to whatever folder it's in. You can specify a Service-Worker-Allowed header to get around this.

cc: @jakearchibald

@malchata
Copy link
Copy Markdown
Member

malchata commented Oct 3, 2022

Ah, I see what you were referring to here.

I think this change makes sense, but didn't fully understand where you were coming from at first. Still, it'd be a good idea if @jakearchibald took a look at this, since this is a guide he wrote.

@malchata malchata added P2 A normal priority task. This is the default for most issues. content update for issues that do not require new content (only for updates to existing content) labels Oct 3, 2022
@jespertheend
Copy link
Copy Markdown
Contributor Author

Ah sorry my bad, I should have been more clear there.

So just to be clear: I think an older version of the spec said that these values would be undefined when non existent, but I think this changed at some point, because I'm observing that they are null now and the spec and mdn also state that they are initially null.

Sign up for free to subscribe to this conversation on GitHub. Already have an account? Sign in.

Labels

content update for issues that do not require new content (only for updates to existing content) P2 A normal priority task. This is the default for most issues.

Projects

None yet

Development

Successfully merging this pull request may close these issues.

3 participants