Serviceworker: Cache.addAll() and .add() needs to accept an init argument to use for fetch()

Created on 26 Nov 2017  路  2Comments  路  Source: w3c/ServiceWorker

Cache.addAll() is not as useful if it doesn't take an init argument that fetch() needs to fetch correctly in some cases. addAll() uses fetch() internally and fetch() is overly conservative with credentials defaulting to 'omit' which causes a fetch failure while using web authentication. Currently the only way to work around this is to unroll the addAll() function for the sole reason to pass the more user friendly {'credentials': 'same-origin'} argument to fetch(). If addAll() would accept an init structure then then the init can be passed to fetch().
Please change addAll() and add() to accept an optional init argument to use for fetch(): addAll(requests, init).

Most helpful comment

Both add and addAll take Request objects:

cache.addAll(
  urls.map(url => new Request(url, { credentials: 'include' }))
);

All 2 comments

Ambient context like fetch credential-mode is the root of w3ctag/design-reviews#76 .

Both add and addAll take Request objects:

cache.addAll(
  urls.map(url => new Request(url, { credentials: 'include' }))
);
Was this page helpful?
0 / 5 - 0 ratings