When I set my Chrome extension's Site access from "On all sites" to "On click", I get a CORS error for requests originating from my service worker:
Access to XMLHttpRequest at 'https://example.com/target/path' from origin 'chrome-extension://<extension-id>' has been blocked by CORS policy: Response to preflight request doesn't pass access control check: Redirect is not allowed for a preflight request.
The above error was due to my server returning status 307 – redirecting to the WWW domain for the URL. Now after making the request to
https://www.example.com/target/path instead
, I discovered that Chrome is not setting the origin header on the requests from the service worker, "request.headers.origin" shows up in my backend as undefined, yet I'm getting CORS error:
No 'Access-Control-Allow-Origin' header is present on the requested resource in service worker console.
Am I supposed to wildcard (*) allow all requests that don't have an origin specified? Because whitelisting the extension origin does nothing in this case.
I never had any of these issues when Site access was set to "On all sites".