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

fix(workbox): add additional details for uncaught errors and fix chromium CORS #417

Merged
merged 5 commits into from
Dec 20, 2020
Merged
Changes from 1 commit
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
Prev Previous commit
Next Next commit
test: update snapshot
pi0 committed Dec 20, 2020
commit 3ce5d1cf6d213b177e53746a075de79fa8cf1498
22 changes: 22 additions & 0 deletions test/__snapshots__/pwa.test.js.snap
Original file line number Diff line number Diff line change
@@ -156,13 +156,35 @@ function precacheAssets(workbox, options) {


function runtimeCaching(workbox, options) {
const requestInterceptor = {
requestWillFetch({ request }) {
if (request.cache === 'only-if-cached' && request.mode === 'no-cors') {
return new Request(request.url, { ...request, mode: 'no-cors' })
}
return request
},
fetchDidFail(ctx) {
ctx.error.message =
'[workbox] Network request for ' + ctx.request.url + ' threw an error: ' + ctx.error.message
console.error(ctx.error, 'Details:', ctx)
},
handlerDidError(ctx) {
ctx.error.message =
\`[workbox] Network handler threw an error: \` + ctx.error.message
console.error(ctx.error, 'Details:', ctx)
return null
}
}

for (const entry of options.runtimeCaching) {
const urlPattern = new RegExp(entry.urlPattern)
const method = entry.method || 'GET'

const plugins = (entry.strategyPlugins || [])
.map(p => new (getProp(workbox, p.use))(...p.config))

plugins.unshift(requestInterceptor)

const strategyOptions = { ...entry.strategyOptions, plugins }

const strategy = new workbox.strategies[entry.handler](strategyOptions)