From c83c12e6178b2c1ea13604f77f433f6b770d756f Mon Sep 17 00:00:00 2001 From: Nolan Lawson Date: Wed, 26 Feb 2020 07:38:55 -0800 Subject: [PATCH] fix: remove safari-specific service worker code (#1712) 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 f239e095..00000000 --- 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 d6f98b6d..18b0ac48 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) })()) })