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

fix: WebSocket Connection Closed crashing from BrowserCriClient #30174

Merged
merged 9 commits into from
Sep 3, 2024
8 changes: 8 additions & 0 deletions cli/CHANGELOG.md
Original file line number Diff line number Diff line change
@@ -1,4 +1,12 @@
<!-- See the ../guides/writing-the-cypress-changelog.md for details on writing the changelog. -->
## 13.14.2

_Released 9/10/2024 (PENDING)_

**Bugfixes:**

- Fixed an issue where Cypress could crash with a `WebSocket Connection Closed` error. Fixes [#30100](https://github.com/cypress-io/cypress/issues/30100).

## 13.14.1

_Released 8/29/2024_
Expand Down
5 changes: 4 additions & 1 deletion packages/server/lib/browsers/browser-cri-client.ts
Original file line number Diff line number Diff line change
Expand Up @@ -403,7 +403,10 @@ export class BrowserCriClient {

browserCriClient.addExtraTargetClient(targetInfo, extraTargetCriClient)

await extraTargetCriClient.send('Fetch.enable')
await extraTargetCriClient.send('Fetch.enable').catch((err) => {
// swallow this error so it doesn't crash Cypress
debug('Fetch.enable failed on extra target#%s: %s', targetId, err)
})

// we mark extra targets with this header, so that the proxy can recognize
// where they came from and run only the minimal middleware necessary
Expand Down
14 changes: 14 additions & 0 deletions packages/server/test/unit/browsers/browser-cri-client_spec.ts
Original file line number Diff line number Diff line change
Expand Up @@ -278,6 +278,20 @@ describe('lib/browsers/browser-cri-client', function () {
expect(options.browserClient.send).to.be.calledWith('Runtime.runIfWaitingForDebugger', undefined, 'session-id')
})

it('does not throw if Fetch.enable on extra target throws', async () => {
cacieprins marked this conversation as resolved.
Show resolved Hide resolved
const extraTargetCriClient = {
send: sinon.stub().withArgs('Fetch.enable').rejects('Fetch.enable failed'),
on: sinon.stub(),
}

options.CriConstructor.resolves(extraTargetCriClient)

options.browserClient.send.withArgs('Fetch.enable').resolves()
options.browserClient.send.withArgs('Runtime.runIfWaitingForDebugger').resolves()

expect(BrowserCriClient._onAttachToTarget(options as any)).to.be.fulfilled
})

it('adds the service worker fetch event binding', async () => {
options.event.targetInfo.type = 'service_worker'

Expand Down
Loading