-
Notifications
You must be signed in to change notification settings - Fork 314
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
CORS preflight for static import in a module service worker #1574
Comments
|
Possibly related: whatwg/fetch#1005 Given that most browsers exempt browser-added headers, should this header be treated the same? Chrome doesn't do this by default, but I think other browsers do. |
We don't add this header to Also, right now we're breaking cases where It doesn't look like we're doing the byte-identical check on imported scripts either. |
So it seems we need to move the "Append https://w3c.github.io/ServiceWorker/#update-algorithm Step 9 substep 1 to be after substep 4 where "is top-level flag" check is made. Maybe we should file a separate issue for byte-for-byte update checking issues with es modules. |
Link to the spec discussion issue can be found at w3c/ServiceWorker#1574 Bug: 1191514 Change-Id: I4c8680e11f01178567fe8e58df267b51a4baeff6 Reviewed-on: https://chromium-review.googlesource.com/c/chromium/src/+/2785310 Reviewed-by: Ben Kelly <[email protected]> Commit-Queue: Ghazale Hosseinabadi <[email protected]> Cr-Commit-Position: refs/heads/master@{#868484}
A static import for a cross-origin script in a module service worker causes a CORS preflight due to the added "Service-Worker" header (specified in https://w3c.github.io/ServiceWorker/#update-algorithm). Hence the fetch operation will fail unless the remote server handles CORS preflight correctly.
For example, assume there is a service worker script like this
and if https://b.com/cross-origin-script.js doesn’t have “Access-Control-Allow-Headers: service-worker” and “Access-Control-Allow-Origin: a.com“, the registration of sw.js will fail with the following error:
(Tested it on Chrome)
I think it’s confusing behavior so I’d like to suggest the following options:
Keep the current behavior and a cross-origin script should explicitly return “Access-Control-Allow-Headers: service-worker” in its response.
Add “Service-Worker” to “CORS-safelisted request-header”.
Do not add the "Service Worker: script" header to import scripts.
The text was updated successfully, but these errors were encountered: