Skip to content

Commit

Permalink
handling document requests [run ci]
Browse files Browse the repository at this point in the history
  • Loading branch information
mschile committed Apr 10, 2024
1 parent 17c15e8 commit 7958bb8
Showing 1 changed file with 15 additions and 1 deletion.
16 changes: 15 additions & 1 deletion packages/proxy/lib/http/util/service-worker-manager.ts
Original file line number Diff line number Diff line change
Expand Up @@ -168,6 +168,8 @@ export class ServiceWorkerManager {
*/
async processBrowserPreRequest (browserPreRequest: BrowserPreRequest) {
if (browserPreRequest.initiator?.type === 'preload') {
debug('skipping preload request: %o', browserPreRequest)

return false
}

Expand All @@ -179,6 +181,18 @@ export class ServiceWorkerManager {
activatedServiceWorker = registration.activatedServiceWorker
const paramlessDocumentURL = browserPreRequest.documentURL?.split('?')[0] || ''

// if the service worker is active and the request is for the document URL,
// we can assume that the service worker is controlling the document
// and update the registration to reflect that
if (!registration.isHandlingRequests &&
activatedServiceWorker?.initiatorOrigin &&
browserPreRequest.documentURL === browserPreRequest.url &&
browserPreRequest.url.startsWith(registration.scopeURL) &&
browserPreRequest.documentURL.startsWith(activatedServiceWorker.initiatorOrigin)) {
registration.isHandlingRequests = true
debug('received request for the document of an activated service worker, updating registration to handle requests: %o', { registration, browserPreRequest })
}

// We are determining here if a request is controlled by a service worker. A request is controlled by a service worker if
// we have an activated service worker, the request URL does not come from the service worker, and the request
// originates from the same origin as the service worker or from a script that is also controlled by the service worker.
Expand Down Expand Up @@ -285,8 +299,8 @@ export class ServiceWorkerManager {
const registration = this.getRegistrationForScope(scope)

if (registration) {
debug('service worker is handling fetch requests: %o', registration)
registration.isHandlingRequests = true
debug('service worker is handling fetch requests: %o', registration)
} else {
debug('could not find service worker registration for scope: %s', scope)
}
Expand Down

5 comments on commit 7958bb8

@cypress-bot
Copy link
Contributor

@cypress-bot cypress-bot bot commented on 7958bb8 Apr 10, 2024

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Circle has built the linux x64 version of the Test Runner.

Learn more about this pre-release build at https://on.cypress.io/advanced-installation#Install-pre-release-version

Run this command to install the pre-release locally:

npm install https://cdn.cypress.io/beta/npm/13.7.3/linux-x64/mschile/service_worker_uncontrolled-7958bb8f453addb7fd9ec11dbca858c657f8b52e/cypress.tgz

@cypress-bot
Copy link
Contributor

@cypress-bot cypress-bot bot commented on 7958bb8 Apr 10, 2024

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Circle has built the linux arm64 version of the Test Runner.

Learn more about this pre-release build at https://on.cypress.io/advanced-installation#Install-pre-release-version

Run this command to install the pre-release locally:

npm install https://cdn.cypress.io/beta/npm/13.7.3/linux-arm64/mschile/service_worker_uncontrolled-7958bb8f453addb7fd9ec11dbca858c657f8b52e/cypress.tgz

@cypress-bot
Copy link
Contributor

@cypress-bot cypress-bot bot commented on 7958bb8 Apr 10, 2024

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Circle has built the darwin x64 version of the Test Runner.

Learn more about this pre-release build at https://on.cypress.io/advanced-installation#Install-pre-release-version

Run this command to install the pre-release locally:

npm install https://cdn.cypress.io/beta/npm/13.7.3/darwin-x64/mschile/service_worker_uncontrolled-7958bb8f453addb7fd9ec11dbca858c657f8b52e/cypress.tgz

@cypress-bot
Copy link
Contributor

@cypress-bot cypress-bot bot commented on 7958bb8 Apr 10, 2024

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Circle has built the win32 x64 version of the Test Runner.

Learn more about this pre-release build at https://on.cypress.io/advanced-installation#Install-pre-release-version

Run this command to install the pre-release locally:

npm install https://cdn.cypress.io/beta/npm/13.7.3/win32-x64/mschile/service_worker_uncontrolled-7958bb8f453addb7fd9ec11dbca858c657f8b52e/cypress.tgz

@cypress-bot
Copy link
Contributor

@cypress-bot cypress-bot bot commented on 7958bb8 Apr 10, 2024

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Circle has built the darwin arm64 version of the Test Runner.

Learn more about this pre-release build at https://on.cypress.io/advanced-installation#Install-pre-release-version

Run this command to install the pre-release locally:

npm install https://cdn.cypress.io/beta/npm/13.7.3/darwin-arm64/mschile/service_worker_uncontrolled-7958bb8f453addb7fd9ec11dbca858c657f8b52e/cypress.tgz

Please sign in to comment.