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

Can't pass credentials when precaching routes #1288

Closed
mnquintana opened this issue Feb 9, 2018 · 1 comment
Closed

Can't pass credentials when precaching routes #1288

mnquintana opened this issue Feb 9, 2018 · 1 comment
Assignees

Comments

@mnquintana
Copy link

Library Affected:
workbox-precaching@3.0.0-beta.0

Browser & Platform:
All browsers

Issue or Feature Request Description:
Currently workbox.precache isn't passing credentials along when fetching assets, which means that any requests that require, say, a valid cookie, will fail. 😢

It looks like this is because the PrecacheController is explicitly passing in null for fetchOptions to the fetchWrapper:

let response = await fetchWrapper.fetch(
precacheEntry._networkRequest,
null,
plugins,
);

What I'd like to see is an API to pass fetchOptions down to the fetch wrapper, potentially on a per route / asset basis.

Steps to Reproduce

  1. Create a precache manifest entry pointing to an asset that can only be accessed with a cookie
  2. workbox.precache.precacheAndRoute(...)
  3. Load the page and wait for the Service Worker to activate
  4. Fetching the asset will fail

Let me know if there's any more info I could provide that'd be helpful! 🙇

@jeffposnick
Copy link
Contributor

Thanks for reporting this!

We hardcoded same-origin for precaching in the previous Workbox release (and in sw-precache), and it seemed to be non-controversial. Here's the v2 code:

this._requestWrapper = new RequestWrapper({
cacheName,
cacheId,
plugins,
fetchOptions: {
credentials: 'same-origin',
},
});

@gauntface, I'll put together a PR to add this in to v3, unless you're aware of why we wouldn't want to do this anymore.

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