Skip to content
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

Fix the wrong service-worker mode. #733

Merged
merged 5 commits into from
Aug 28, 2023
Merged

Fix the wrong service-worker mode. #733

merged 5 commits into from
Aug 28, 2023

Conversation

qingxinwu
Copy link
Collaborator

@qingxinwu qingxinwu commented Jul 27, 2023

Our implementation uses default "all" for service worker mode, not "none". However, given the fact that all of these requests have a null client, one of the side-effects of this is neutering all service worker interception (effectively "none" although set to default "all), despite not having to set the service workers mode. The service worker interception algorithm returns at step 15.2 (our request has the default kEmpty destination, so it's a subresource request), and nothing happened before this step.

There is an issue filed for this.


Preview | Diff

@qingxinwu qingxinwu added the spec Relates to the spec label Jul 27, 2023
Copy link
Collaborator

@domfarolino domfarolino left a comment

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

I mean the spec PR looks fine, but I'm not super comfortable landing this without at least some knowledge of what the implementation does. I think this PR would make the request interceptable by service workers (but not sure if the client has to be non-null for that), and I certainly don't know what the implementation does.

For example, if we determine that even with a null client, per spec this request would be intercepted by service workers, but we also determine that our implementation doesn't match this due to it being a browser-initiated request, and it would be very hard to change that, would we want to spend a ton of time hacking the implementation to match the spec here, or would we just want to revert this PR and use none service workers mode?

Knowing what our implementation does here seems important given the somewhat anomalous implementation (not being sent via a renderer, and not being a navigation request), so landing this PR without that knowledge seems premature.

@qingxinwu
Copy link
Collaborator Author

I mean the spec PR looks fine, but I'm not super comfortable landing this without at least some knowledge of what the implementation does. I think this PR would make the request interceptable by service workers (but not sure if the client has to be non-null for that), and I certainly don't know what the implementation does.

For example, if we determine that even with a null client, per spec this request would be intercepted by service workers, but we also determine that our implementation doesn't match this due to it being a browser-initiated request, and it would be very hard to change that, would we want to spend a ton of time hacking the implementation to match the spec here, or would we just want to revert this PR and use none service workers mode?

Knowing what our implementation does here seems important given the somewhat anomalous implementation (not being sent via a renderer, and not being a navigation request), so landing this PR without that knowledge seems premature.

Matt commented under the other github issue:
"The scripts don't go through SW because they're sent directly to the network stack, just like internal Chrome network requests. There's no SW loader stuck in front of the network stack for them, so the value of skip_service_worker has no effect. So despite not explicitly setting it to none currently, it is effectively none, since no service worker loader factory is in front of the real network loader factory".

@domfarolino
Copy link
Collaborator

Layering-wise in the spec, service worker interception is done in Fetch, so it's possible you still need to set the service workers mode to "none" for the spec. That is, the reason Chrome skips service workers might be implementation-specific. I believe the service worker interception algorithm that gets initially invoked by Fetch is https://w3c.github.io/ServiceWorker/#on-fetch-request-algorithm. Could you check that algorithm out and see if it would intercept these kinds of requests? If not, then maybe Chrome and the spec are aligned, but I'm just trying to protect against the case where the spec needs the service worker mode to be "none" even though the implementation technically doesn't.

@qingxinwu
Copy link
Collaborator Author

Layering-wise in the spec, service worker interception is done in Fetch, so it's possible you still need to set the service workers mode to "none" for the spec. That is, the reason Chrome skips service workers might be implementation-specific. I believe the service worker interception algorithm that gets initially invoked by Fetch is https://w3c.github.io/ServiceWorker/#on-fetch-request-algorithm. Could you check that algorithm out and see if it would intercept these kinds of requests? If not, then maybe Chrome and the spec are aligned, but I'm just trying to protect against the case where the spec needs the service worker mode to be "none" even though the implementation technically doesn't.

I think it does not intercept these kinds of requests. If I understand it correctly, it returns at step 15.2 (our request has the default kEmpty destination, so it's a subresource request), and nothing happened before this step.

@domfarolino
Copy link
Collaborator

That makes sense to me, thanks. Given the fact that all of these requests have a null client, could you add a non-normative note somewhere saying that one of the side-effects of this is neutering all service worker interception, despite not having to set the service workers mode? I think that'd be good to clarify somewhere. I'm not sure if it would be too noisy to do it for each request or not, so I'll leave that to you.

Also if you could update the OP with your rationale for why this causes no spec behavior change (because of step 15.2 etc.) that would be great, just so we can easily find the logic here if we ever have to do any git blame archaeology in the future.

@qingxinwu
Copy link
Collaborator Author

That makes sense to me, thanks. Given the fact that all of these requests have a null client, could you add a non-normative note somewhere saying that one of the side-effects of this is neutering all service worker interception, despite not having to set the service workers mode? I think that'd be good to clarify somewhere. I'm not sure if it would be too noisy to do it for each request or not, so I'll leave that to you.

Also if you could update the OP with your rationale for why this causes no spec behavior change (because of step 15.2 etc.) that would be great, just so we can easily find the logic here if we ever have to do any git blame archaeology in the future.

Done.

@domfarolino domfarolino merged commit 09c97ee into WICG:main Aug 28, 2023
1 check passed
github-actions bot added a commit that referenced this pull request Aug 28, 2023
SHA: 09c97ee
Reason: push, by domfarolino

Co-authored-by: github-actions[bot] <41898282+github-actions[bot]@users.noreply.github.com>
@qingxinwu qingxinwu deleted the fix branch August 28, 2023 20:01
github-actions bot added a commit to qingxinwu/turtledove that referenced this pull request Aug 29, 2023
SHA: 09c97ee
Reason: push, by qingxinwu

Co-authored-by: github-actions[bot] <41898282+github-actions[bot]@users.noreply.github.com>
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
spec Relates to the spec
Projects
None yet
Development

Successfully merging this pull request may close these issues.

2 participants