Skip to content

Commit d70ffea

Browse files
fix: runIfWaitingForDebugger when targets are reloaded after crashing (#28254)
1 parent e8fc268 commit d70ffea

5 files changed

Lines changed: 24 additions & 3 deletions

File tree

cli/CHANGELOG.md

Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -17,6 +17,7 @@ _Released 11/7/2023 (PENDING)_
1717
- 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).
1818
- 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).
1919
- 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).
20+
- 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).
2021

2122
## 13.4.0
2223

packages/server/lib/browsers/browser-cri-client.ts

Lines changed: 11 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -263,6 +263,17 @@ export class BrowserCriClient {
263263
this._onTargetDestroyed({ browserClient, browserCriClient, browserName, event, onAsynchronousError })
264264
})
265265

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

packages/server/lib/browsers/cdp_automation.ts

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -142,7 +142,7 @@ export const normalizeResourceType = (resourceType: string | undefined): Resourc
142142

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

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

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

system-tests/projects/e2e/cypress/e2e/web_worker.cy.js

Lines changed: 9 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -32,3 +32,12 @@ it('loads web workers', { defaultCommandTimeout: 1900 }, () => {
3232
.then(webWorker)
3333
.then(sharedWorker)
3434
})
35+
36+
// Timeout of 1900 will ensure that the proxy correlation timeout is not hit
37+
it('reloads web workers', { defaultCommandTimeout: 1900 }, () => {
38+
cy.visit('https://localhost:1515/web_worker.html')
39+
40+
cy.reload()
41+
.then(webWorker)
42+
.then(sharedWorker)
43+
})

system-tests/test/web_worker_spec.js

Lines changed: 2 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -46,8 +46,8 @@ describe('e2e web worker', () => {
4646
spec: 'web_worker.cy.js',
4747
onRun: async (exec, browser) => {
4848
await exec()
49-
expect(requestsForWebWorker).to.eq(1)
50-
expect(requestsForSharedWorker).to.eq(1)
49+
expect(requestsForWebWorker).to.eq(2)
50+
expect(requestsForSharedWorker).to.eq(2)
5151
},
5252
})
5353
})

0 commit comments

Comments
 (0)