The service worker static routing api was introduced in Chrome 123 and allows defined routes to bypass the service worker. We currently assume all routes within the service worker's scope will go through the service worker.
Take the following test:
it('supports the static routing api', () => {
const script = () => {
addEventListener('install', (event) => {
// bypass the service worker for the 1mb request
event.addRoutes({
condition: {
urlPattern: '/fixtures/1mb*',
},
source: 'network',
})
})
self.addEventListener('fetch', function (event) {
console.log('fetch', event.request.url)
event.respondWith(fetch(event.request))
})
}
cy.intercept('/fixtures/service-worker.js', (req) => {
req.reply(`(${script})()`,
{ 'Content-Type': 'application/javascript' })
})
cy.visit('fixtures/service-worker.html')
cy.get('#output').should('have.text', 'done')
})
we see the 1mb prerequest timed out (250ms) waiting to see if it was controlled by the service worker.
cypress:proxy:service-worker-manager timed out checking if pre-request is controlled by service worker: { url: 'http://localhost:3500/fixtures/1mb?j=0.5439428840854426', requestId: '87682.90' } +257ms
cypress:proxy:service-worker-manager Request is not controlled by service worker: { url: 'http://localhost:3500/fixtures/1mb?j=0.5439428840854426', requestId: '87682.90', requestPotentiallyControlledByServiceWorker: true } +0ms
Why is this needed?
Adds support for the service worker static routing api.
Other
In order to add support for the static routing api, we could override addRoutes and save the route config so we can determine if a request will go through the service worker.
If we remove proxy correlation, this change will not be necessary.
What would you like?
The service worker static routing api was introduced in Chrome 123 and allows defined routes to bypass the service worker. We currently assume all routes within the service worker's scope will go through the service worker.
Take the following test:
Running with DEBUG logs turned on,
we see the
1mb
prerequest timed out (250ms) waiting to see if it was controlled by the service worker.Why is this needed?
Adds support for the service worker static routing api.
Other
In order to add support for the static routing api, we could override
addRoutes
and save the route config so we can determine if a request will go through the service worker.If we remove proxy correlation, this change will not be necessary.