Skip to content

Commit

Permalink
fix: runIfWaitingForDebugger when targets are reloaded after crashing (
Browse files Browse the repository at this point in the history
  • Loading branch information
ryanthemanuel authored and cacieprins committed Nov 7, 2023
1 parent 79e2dfe commit 279e050
Show file tree
Hide file tree
Showing 5 changed files with 24 additions and 3 deletions.
1 change: 1 addition & 0 deletions cli/CHANGELOG.md
Expand Up @@ -25,6 +25,7 @@ _Released 11/7/2023_
- Fixed an issue with 'other' targets (e.g. pdf documents embedded in an object tag) not fully loading. Fixes [#28228](https://github.com/cypress-io/cypress/issues/28228) and [#28162](https://github.com/cypress-io/cypress/issues/28162).
- Fixed an issue where network requests made from tabs/windows other than the main Cypress tab would be delayed. Fixes [#28113](https://github.com/cypress-io/cypress/issues/28113).
- Stopped processing CDP events at the end of a spec when Test Isolation is off and Test Replay is enabled. Addressed in [#28213](https://github.com/cypress-io/cypress/pull/28213).
- Fixed a regression in [`13.3.3`](https://docs.cypress.io/guides/references/changelog/13.3.3) where Cypress would hang on loading shared workers when using `cy.reload` to reload the page. Fixes [#28248](https://github.com/cypress-io/cypress/issues/28248).

## 13.4.0

Expand Down
11 changes: 11 additions & 0 deletions packages/server/lib/browsers/browser-cri-client.ts
Expand Up @@ -263,6 +263,17 @@ export class BrowserCriClient {
this._onTargetDestroyed({ browserClient, browserCriClient, browserName, event, onAsynchronousError })
})

browserClient.on('Inspector.targetReloadedAfterCrash', async (event, sessionId) => {
try {
// Things like service workers will effectively crash in terms of CDP when the page is reloaded in the middle of things
// We will still auto attach in this case, but we need to runIfWaitingForDebugger to get the page back to a running state
await browserClient.send('Runtime.runIfWaitingForDebugger', undefined, sessionId)
} catch (error) {
// it's possible that the target was closed before we can run. If so, just ignore
debug('error running Runtime.runIfWaitingForDebugger:', error)
}
})

await Promise.all(promises)
}

Expand Down
2 changes: 1 addition & 1 deletion packages/server/lib/browsers/cdp_automation.ts
Expand Up @@ -142,7 +142,7 @@ export const normalizeResourceType = (resourceType: string | undefined): Resourc

export type SendDebuggerCommand = <T extends CdpCommand>(message: T, data?: ProtocolMapping.Commands[T]['paramsType'][0], sessionId?: string) => Promise<ProtocolMapping.Commands[T]['returnType']>

export type OnFn = <T extends CdpEvent>(eventName: T, cb: (data: ProtocolMapping.Events[T][0]) => void) => void
export type OnFn = <T extends CdpEvent>(eventName: T, cb: (data: ProtocolMapping.Events[T][0], sessionId?: string) => void) => void

export type OffFn = (eventName: string, cb: (data: any) => void) => void

Expand Down
9 changes: 9 additions & 0 deletions system-tests/projects/e2e/cypress/e2e/web_worker.cy.js
Expand Up @@ -32,3 +32,12 @@ it('loads web workers', { defaultCommandTimeout: 1900 }, () => {
.then(webWorker)
.then(sharedWorker)
})

// Timeout of 1900 will ensure that the proxy correlation timeout is not hit
it('reloads web workers', { defaultCommandTimeout: 1900 }, () => {
cy.visit('https://localhost:1515/web_worker.html')

cy.reload()
.then(webWorker)
.then(sharedWorker)
})
4 changes: 2 additions & 2 deletions system-tests/test/web_worker_spec.js
Expand Up @@ -46,8 +46,8 @@ describe('e2e web worker', () => {
spec: 'web_worker.cy.js',
onRun: async (exec, browser) => {
await exec()
expect(requestsForWebWorker).to.eq(1)
expect(requestsForSharedWorker).to.eq(1)
expect(requestsForWebWorker).to.eq(2)
expect(requestsForSharedWorker).to.eq(2)
},
})
})

0 comments on commit 279e050

Please sign in to comment.