From 104d44673340e147faaf76a143a7d626a57047ce Mon Sep 17 00:00:00 2001 From: Nolan Lawson Date: Wed, 26 Feb 2020 06:58:37 -0800 Subject: [PATCH] fix: remove safari-specific service worker code fixes #1595 --- src/routes/_utils/userAgent/isSafari.js | 4 --- src/service-worker.js | 33 ------------------------- 2 files changed, 37 deletions(-) delete mode 100644 src/routes/_utils/userAgent/isSafari.js diff --git a/src/routes/_utils/userAgent/isSafari.js b/src/routes/_utils/userAgent/isSafari.js deleted file mode 100644 index f239e0953..000000000 --- a/src/routes/_utils/userAgent/isSafari.js +++ /dev/null @@ -1,4 +0,0 @@ -import { thunk } from '../thunk' - -export const isSafari = thunk(() => process.browser && /Safari/.test(navigator.userAgent) && - !/Chrome/.test(navigator.userAgent)) diff --git a/src/service-worker.js b/src/service-worker.js index d6f98b6db..18b0ac489 100644 --- a/src/service-worker.js +++ b/src/service-worker.js @@ -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) })()) })