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

Basic service worker demo misleadingly suggests that cross-origin requests can be intercepted #761

Closed
Tomaz-Vieira opened this issue Jan 19, 2022 · 1 comment

Comments

@Tomaz-Vieira
Copy link

The Basic Demo in the service worker samples page performs different actions on the requests depending on the location, stating in a comment: "// Skip cross-origin requests, like those for Google Analytics."

As far as I understand, Service Workers can't intercept cross-domain requests, so this might mislead others (as it did me) into thinking that this would be possible.

@jeffposnick
Copy link
Contributor

It's definitely possible for a service worker's fetch event handler to respond to a cross-origin request.

A service worker can only control a same-origin web page that's under it's scope. If that web page makes a request for a cross-origin resource, via a fetch('https://cross-origin.example.com') or some other loading mechanism, like <script src="https://cross-origin.example.com">, the fetch event handler will be fired and the service worker can respond.

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
None yet
Projects
None yet
Development

No branches or pull requests

2 participants