Skip to content

Commit

Permalink
fix: remove safari-specific service worker code
Browse files Browse the repository at this point in the history
fixes #1595
  • Loading branch information
nolanlawson committed Feb 26, 2020
1 parent 8400f10 commit 104d446
Show file tree
Hide file tree
Showing 2 changed files with 0 additions and 37 deletions.
4 changes: 0 additions & 4 deletions src/routes/_utils/userAgent/isSafari.js

This file was deleted.

33 changes: 0 additions & 33 deletions src/service-worker.js
Original file line number Diff line number Diff line change
Expand Up @@ -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}`
Expand Down Expand Up @@ -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)
Expand Down Expand Up @@ -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)
})())
})
Expand Down

0 comments on commit 104d446

Please sign in to comment.