Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

support the service worker static routing api #30611

Open
mschile opened this issue Nov 13, 2024 · 0 comments
Open

support the service worker static routing api #30611

mschile opened this issue Nov 13, 2024 · 0 comments

Comments

@mschile
Copy link
Contributor

mschile commented Nov 13, 2024

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:

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')
})

Running with DEBUG logs turned on,

DEBUG=cypress*:proxy:http:util:prerequests,cypress-verbose:proxy:http,cypress:proxy:service-worker-manager yarn cypress:run --project ~/Projects/cypress/packages/driver --spec ~/Projects/cypress/packages/driver/cypress/e2e/e2e/service-worker.cy.js --browser chrome

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.

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
None yet
Projects
None yet
Development

No branches or pull requests

1 participant