Skip to content

Commit

Permalink
fix: re-initialize DOM subscriptions from a full snapshot on cdp reco…
Browse files Browse the repository at this point in the history
…nnect (#29210)

* fix: re-initialize DOM subscriptions from a full snapshot on cdp reconnect

* add test

* add changelog

* Update cli/CHANGELOG.md

Co-authored-by: Bill Glesias <bglesias@gmail.com>

* Update CHANGELOG.md

---------

Co-authored-by: Bill Glesias <bglesias@gmail.com>
Co-authored-by: Jennifer Shehane <jennifer@cypress.io>
  • Loading branch information
3 people authored Mar 29, 2024
1 parent 425ba79 commit 1ae7c9e
Show file tree
Hide file tree
Showing 5 changed files with 24 additions and 5 deletions.
1 change: 1 addition & 0 deletions cli/CHANGELOG.md
Original file line number Diff line number Diff line change
Expand Up @@ -11,6 +11,7 @@ _Released 4/2/2024 (PENDING)_

- Fixed an issue where Cypress was not executing beyond the first spec in `cypress run` for versions of Firefox 124 and up when a custom user agent was provided. Fixes [#29190](https://github.com/cypress-io/cypress/issues/29190).
- Fixed a bug where fields using arrays in `cypress.config` are not correctly processed. Fixes [#27103](https://github.com/cypress-io/cypress/issues/27103). Fixed in [#27312](https://github.com/cypress-io/cypress/pull/27312).
- Fixed a hang where Cypress would run indefinitely while recording to the cloud when CDP disconnects during the middle of a test. Fixes [#29209](https://github.com/cypress-io/cypress/issues/29209).
- Fixed a bug where option values containing quotation marks could not be selected. Fixes [#29213](https://github.com/cypress-io/cypress/issues/29213)

## 13.7.1
Expand Down
5 changes: 5 additions & 0 deletions packages/server/lib/browsers/cri-client.ts
Original file line number Diff line number Diff line change
Expand Up @@ -208,6 +208,11 @@ export const create = async ({
if (onReconnect) {
onReconnect(client)
}

// When CDP disconnects, it will automatically reconnect and re-apply various subscriptions
// (e.g. DOM.enable, Network.enable, etc.). However, we need to restart tracking DOM mutations
// from scratch. We do this by capturing a brand new full snapshot of the DOM.
await protocolManager?.cdpReconnect()
}

const retryReconnect = async () => {
Expand Down
4 changes: 4 additions & 0 deletions packages/server/lib/cloud/protocol.ts
Original file line number Diff line number Diff line change
Expand Up @@ -317,6 +317,10 @@ export class ProtocolManager implements ProtocolManagerShape {
}
}

async cdpReconnect () {
await this.invokeAsync('cdpReconnect', { isEssential: true })
}

async reportNonFatalErrors (context?: {
osName: string
projectSlug: string
Expand Down
18 changes: 13 additions & 5 deletions packages/server/test/unit/browsers/cri-client_spec.ts
Original file line number Diff line number Diff line change
@@ -1,5 +1,6 @@
import EventEmitter from 'events'
import { create } from '../../../lib/browsers/cri-client'
import { ProtocolManagerShape } from '@packages/types'

const { expect, proxyquire, sinon } = require('../../spec_helper')

Expand All @@ -23,7 +24,7 @@ describe('lib/browsers/cri-client', function () {
_notifier: EventEmitter
}
let onError: sinon.SinonStub
let getClient: (options?: { host?: string, fullyManageTabs?: boolean }) => ReturnType<typeof create>
let getClient: (options?: { host?: string, fullyManageTabs?: boolean, protocolManager?: ProtocolManagerShape }) => ReturnType<typeof create>

beforeEach(function () {
send = sinon.stub()
Expand All @@ -49,8 +50,8 @@ describe('lib/browsers/cri-client', function () {
'chrome-remote-interface': criImport,
})

getClient = ({ host, fullyManageTabs } = {}) => {
return criClient.create({ target: DEBUGGER_URL, host, onAsynchronousError: onError, fullyManageTabs })
getClient = ({ host, fullyManageTabs, protocolManager } = {}) => {
return criClient.create({ target: DEBUGGER_URL, host, onAsynchronousError: onError, fullyManageTabs, protocolManager })
}
})

Expand Down Expand Up @@ -134,10 +135,16 @@ describe('lib/browsers/cri-client', function () {
})

describe('on reconnect', () => {
it('resends *.enable commands', async () => {
it('resends *.enable commands and notifies protocol manager', async () => {
criStub._notifier.on = sinon.stub()

const client = await getClient()
const protocolManager = {
cdpReconnect: sinon.stub(),
} as ProtocolManagerShape

const client = await getClient({
protocolManager,
})

client.send('Page.enable')
// @ts-ignore
Expand All @@ -157,6 +164,7 @@ describe('lib/browsers/cri-client', function () {
expect(criStub.send).to.be.calledTwice
expect(criStub.send).to.be.calledWith('Page.enable')
expect(criStub.send).to.be.calledWith('Network.enable')
expect(protocolManager.cdpReconnect).to.be.called
})

it('errors if reconnecting fails', async () => {
Expand Down
1 change: 1 addition & 0 deletions packages/types/src/protocol.ts
Original file line number Diff line number Diff line change
Expand Up @@ -18,6 +18,7 @@ export interface CDPClient {
// TODO(protocol): This is basic for now but will evolve as we progress with the protocol work

export interface AppCaptureProtocolCommon {
cdpReconnect (): Promise<void>
addRunnables (runnables: any): void
commandLogAdded (log: any): void
commandLogChanged (log: any): void
Expand Down

5 comments on commit 1ae7c9e

@cypress-bot
Copy link
Contributor

@cypress-bot cypress-bot bot commented on 1ae7c9e Mar 29, 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.7.2/linux-x64/develop-1ae7c9ef4273625eec6b94248af335824a4c2506/cypress.tgz

@cypress-bot
Copy link
Contributor

@cypress-bot cypress-bot bot commented on 1ae7c9e Mar 29, 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.7.2/linux-arm64/develop-1ae7c9ef4273625eec6b94248af335824a4c2506/cypress.tgz

@cypress-bot
Copy link
Contributor

@cypress-bot cypress-bot bot commented on 1ae7c9e Mar 29, 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.7.2/darwin-x64/develop-1ae7c9ef4273625eec6b94248af335824a4c2506/cypress.tgz

@cypress-bot
Copy link
Contributor

@cypress-bot cypress-bot bot commented on 1ae7c9e Mar 29, 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.7.2/darwin-arm64/develop-1ae7c9ef4273625eec6b94248af335824a4c2506/cypress.tgz

@cypress-bot
Copy link
Contributor

@cypress-bot cypress-bot bot commented on 1ae7c9e Mar 29, 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.7.2/win32-x64/develop-1ae7c9ef4273625eec6b94248af335824a4c2506/cypress.tgz

Please sign in to comment.