Skip to content

Commit

Permalink
fix: WebSocket Connection Closed crashing from BrowserCriClient (#30174)
Browse files Browse the repository at this point in the history
* 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]>
  • Loading branch information
cacieprins and AtofStryker authored Sep 3, 2024
1 parent 57d7b63 commit bbe5328
Show file tree
Hide file tree
Showing 3 changed files with 28 additions and 1 deletion.
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
7 changes: 6 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,12 @@ export class BrowserCriClient {

browserCriClient.addExtraTargetClient(targetInfo, extraTargetCriClient)

await extraTargetCriClient.send('Fetch.enable')
try {
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', () => {
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

5 comments on commit bbe5328

@cypress-bot
Copy link
Contributor

@cypress-bot cypress-bot bot commented on bbe5328 Sep 3, 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.14.2/linux-x64/develop-bbe53286cb9c0dc59d4d12ecff2ca87d7d393afe/cypress.tgz

@cypress-bot
Copy link
Contributor

@cypress-bot cypress-bot bot commented on bbe5328 Sep 3, 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.14.2/linux-arm64/develop-bbe53286cb9c0dc59d4d12ecff2ca87d7d393afe/cypress.tgz

@cypress-bot
Copy link
Contributor

@cypress-bot cypress-bot bot commented on bbe5328 Sep 3, 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.14.2/darwin-arm64/develop-bbe53286cb9c0dc59d4d12ecff2ca87d7d393afe/cypress.tgz

@cypress-bot
Copy link
Contributor

@cypress-bot cypress-bot bot commented on bbe5328 Sep 3, 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.14.2/win32-x64/develop-bbe53286cb9c0dc59d4d12ecff2ca87d7d393afe/cypress.tgz

@cypress-bot
Copy link
Contributor

@cypress-bot cypress-bot bot commented on bbe5328 Sep 3, 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.14.2/darwin-x64/develop-bbe53286cb9c0dc59d4d12ecff2ca87d7d393afe/cypress.tgz

Please sign in to comment.