fix: remove safari-specific service worker code (#1712)

fixes #1595
This commit is contained in:
Nolan Lawson 2020-02-26 07:38:55 -08:00 committed by GitHub
parent d16ccd5d5f
commit c83c12e617
No known key found for this signature in database
GPG key ID: 4AEE18F83AFDEB23
2 changed files with 0 additions and 37 deletions

View file

@ -1,4 +0,0 @@
import { thunk } from '../thunk'
export const isSafari = thunk(() => process.browser && /Safari/.test(navigator.userAgent) &&
!/Chrome/.test(navigator.userAgent))

View file

@ -4,7 +4,6 @@ import {
routes as __routes__
} from '../__sapper__/service-worker.js'
import { get, post } from './routes/_utils/ajax'
import { isSafari } from './routes/_utils/userAgent/isSafari'
const timestamp = process.env.SAPPER_TIMESTAMP
const ASSETS = `assets_${timestamp}`
@ -86,30 +85,6 @@ self.addEventListener('activate', event => {
})())
})
async function returnRangeRequest (request) {
const response = await fetch(request, { headers: {}, mode: 'cors', credentials: 'omit' })
const arrayBuffer = await response.arrayBuffer()
const bytes = /^bytes=(\d+)-(\d+)?$/g.exec(request.headers.get('range'))
if (bytes) {
const start = parseInt(bytes[1], 10)
const end = parseInt(bytes[2], 10) || arrayBuffer.byteLength - 1
return new Response(arrayBuffer.slice(start, end + 1), {
status: 206,
statusText: 'Partial Content',
headers: [
['Content-Range', `bytes ${start}-${end}/${arrayBuffer.byteLength}`]
]
})
} else {
return new Response(null, {
status: 416,
statusText: 'Range Not Satisfiable',
headers: [['Content-Range', `*/${arrayBuffer.byteLength}`]]
})
}
}
self.addEventListener('fetch', event => {
const req = event.request
const url = new URL(req.url)
@ -154,14 +129,6 @@ self.addEventListener('fetch', event => {
}
// for everything else, go network-only
// range request need to be be patched with a 206 response to satisfy
// Safari (https://stackoverflow.com/questions/52087208)
// Once this bug is fixed in WebKit we can remove this https://bugs.webkit.org/show_bug.cgi?id=186050
if (isSafari() && event.request.headers.get('range')) {
return returnRangeRequest(req)
}
return fetch(req)
})())
})