-
Notifications
You must be signed in to change notification settings - Fork 9.4k
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
core(service-worker): check that start_url is within SW's scope #6678
Conversation
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
I think this LGTM, but not sure about diff service worker business. I think this might be the most thoroughly tested audit we have 👏 👏 👏
}; | ||
} | ||
|
||
const startUrlFailure = ServiceWorker.checkStartUrl(artifacts.Manifest, controllingScopeUrl); |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
wouldn't we just want to check that a service worker controls the start URL? i.e. if the one controlling this page is more specific but the start URL is the homepage and so it's controlled by a root service worker for example.
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
wouldn't we just want to check that a service worker controls the start URL?
Yeah, we may need to think about this a bit. I originally had that check, and I don't think there's any technical problem with it, but then was thinking of the issues if you're testing a page and the declared web app manifest creating the PWA containing that page had a start_url
that was controlled by a different SW than the page...so I guess the start_url
is part of a different PWA than the PWA the test page is part of?
So then that seems to violate testing the page as part of a PWA. But also I don't know. But also this should only be possible when running with --disable-storage-reset
anyways, so it's fine to be tougher or not tougher on them :)
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
As an example: google.com/maps
has a service worker controlling everything under the google.com/maps
scope. So if you go to google.com/maps
, you're served offline from that SW.
However, if they accidentally put a start_url
of google.com
in their manifest (and google.com
has a SW), trying to load the maps PWA (e.g. from the homescreen) would load a completely different PWA than the one that you saved.
Again, the likely Lighthouse user experience if someone ever accidentally does this is that storage was cleared and the start_url
just doesn't work offline, but in the off chance they're running without clearing, I think it's better to fail on that case.
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
Ah, OK I buy that! SGTM
const output = ServiceWorker.audit(createArtifacts(swOpts, finalUrl)); | ||
assert.equal(output.rawValue, false); | ||
const output = ServiceWorker.audit(createArtifacts(swOpts, finalUrl, manifest)); | ||
expect(output).toMatchObject({ |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
🎉
const output = ServiceWorker.audit(createArtifacts(swOpts, finalUrl, manifest)); | ||
expect(output).toMatchObject({ | ||
rawValue: false, | ||
explanation: expect.stringMatching(new RegExp(`${finalUrl}.*not in scope`)), |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
well TIL! stringMatching
and arrayMatching
are dope
}); | ||
}); | ||
|
||
it('fails when SW that controls start_url is different than SW that controls page', () => { |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
oh it seems like it was intentional then, why is that?
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
LGTM
part of #6395
Adds a check to the
service-worker
audit to verify that thestart_url
is within the SW's scope.This joins the #6609 check that the page itself is in scope. As with that check, this is mostly useful when first setting up the SW or someone accidently alters the scope somehow. The explanation for this audit will help with debugging other failures (e.g. offline).