Skip to content

Commit bbe5328

Browse files
fix: WebSocket Connection Closed crashing from BrowserCriClient (#30174)
* catch Fetch.enable errors on extra target in browser CRI * changelog * changelog * changelog * Update packages/server/test/unit/browsers/browser-cri-client_spec.ts Co-authored-by: Bill Glesias <[email protected]> * use try/catch instead of .catch for wider unit test support --------- Co-authored-by: Bill Glesias <[email protected]>
1 parent 57d7b63 commit bbe5328

File tree

3 files changed

+28
-1
lines changed

3 files changed

+28
-1
lines changed

cli/CHANGELOG.md

Lines changed: 8 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -1,4 +1,12 @@
11
<!-- See the ../guides/writing-the-cypress-changelog.md for details on writing the changelog. -->
2+
## 13.14.2
3+
4+
_Released 9/10/2024 (PENDING)_
5+
6+
**Bugfixes:**
7+
8+
- Fixed an issue where Cypress could crash with a `WebSocket Connection Closed` error. Fixes [#30100](https://github.com/cypress-io/cypress/issues/30100).
9+
210
## 13.14.1
311

412
_Released 8/29/2024_

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

Lines changed: 6 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -403,7 +403,12 @@ export class BrowserCriClient {
403403

404404
browserCriClient.addExtraTargetClient(targetInfo, extraTargetCriClient)
405405

406-
await extraTargetCriClient.send('Fetch.enable')
406+
try {
407+
await extraTargetCriClient.send('Fetch.enable')
408+
} catch (err) {
409+
// swallow this error so it doesn't crash Cypress
410+
debug('Fetch.enable failed on extra target#%s: %s', targetId, err)
411+
}
407412

408413
// we mark extra targets with this header, so that the proxy can recognize
409414
// where they came from and run only the minimal middleware necessary

packages/server/test/unit/browsers/browser-cri-client_spec.ts

Lines changed: 14 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -278,6 +278,20 @@ describe('lib/browsers/browser-cri-client', function () {
278278
expect(options.browserClient.send).to.be.calledWith('Runtime.runIfWaitingForDebugger', undefined, 'session-id')
279279
})
280280

281+
it('does not throw if Fetch.enable on extra target throws', () => {
282+
const extraTargetCriClient = {
283+
send: sinon.stub().withArgs('Fetch.enable').rejects('Fetch.enable failed'),
284+
on: sinon.stub(),
285+
}
286+
287+
options.CriConstructor.resolves(extraTargetCriClient)
288+
289+
options.browserClient.send.withArgs('Fetch.enable').resolves()
290+
options.browserClient.send.withArgs('Runtime.runIfWaitingForDebugger').resolves()
291+
292+
expect(BrowserCriClient._onAttachToTarget(options as any)).to.be.fulfilled
293+
})
294+
281295
it('adds the service worker fetch event binding', async () => {
282296
options.event.targetInfo.type = 'service_worker'
283297

0 commit comments

Comments
 (0)