Skip to content

Commit

Permalink
refactor: CriClient -> traditional class + async factory (#29676)
Browse files Browse the repository at this point in the history
* refactor: CriClient -> traditional class + async factory

* Update packages/server/test/unit/browsers/cri-client_spec.ts

* member fns of CriClient must be bound to context

* rethrow debug-inspected ws send error

* make cri client constructor private to force factory method; ref cri connection via closure

* add todo for potential memory leak in CriClient
  • Loading branch information
cacieprins committed Jun 26, 2024
1 parent db6afb1 commit 606a43b
Show file tree
Hide file tree
Showing 7 changed files with 262 additions and 239 deletions.
8 changes: 4 additions & 4 deletions packages/server/lib/browsers/browser-cri-client.ts
Original file line number Diff line number Diff line change
Expand Up @@ -5,7 +5,7 @@ import Debug from 'debug'
import type { Protocol } from 'devtools-protocol'
import { _connectAsync, _getDelayMsForRetry } from './protocol'
import * as errors from '../errors'
import { create, CriClient, DEFAULT_NETWORK_ENABLE_OPTIONS } from './cri-client'
import { CriClient, DEFAULT_NETWORK_ENABLE_OPTIONS } from './cri-client'
import { serviceWorkerClientEventHandler, serviceWorkerClientEventHandlerName } from '@packages/proxy/lib/http/util/service-worker-manager'
import type { ProtocolManagerShape } from '@packages/types'
import type { ServiceWorkerEventHandler } from '@packages/proxy/lib/http/util/service-worker-manager'
Expand Down Expand Up @@ -241,7 +241,7 @@ export class BrowserCriClient {
return retryWithIncreasingDelay(async () => {
const versionInfo = await CRI.Version({ host, port, useHostName: true })

const browserClient = await create({
const browserClient = await CriClient.create({
target: versionInfo.webSocketDebuggerUrl,
onAsynchronousError,
onReconnect,
Expand Down Expand Up @@ -543,7 +543,7 @@ export class BrowserCriClient {
throw new Error(`Could not find url target in browser ${url}. Targets were ${JSON.stringify(targets)}`)
}

this.currentlyAttachedTarget = await create({
this.currentlyAttachedTarget = await CriClient.create({
target: target.targetId,
onAsynchronousError: this.onAsynchronousError,
host: this.host,
Expand Down Expand Up @@ -603,7 +603,7 @@ export class BrowserCriClient {
})

if (target) {
this.currentlyAttachedTarget = await create({
this.currentlyAttachedTarget = await CriClient.create({
target: target.targetId,
onAsynchronousError: this.onAsynchronousError,
host: this.host,
Expand Down
2 changes: 1 addition & 1 deletion packages/server/lib/browsers/cdp_automation.ts
Original file line number Diff line number Diff line change
Expand Up @@ -144,7 +144,7 @@ export type SendDebuggerCommand = <T extends CdpCommand>(message: T, data?: Prot

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

export type OffFn = (eventName: string, cb: (data: any) => void) => void
export type OffFn = <T extends CdpEvent>(eventName: T, cb: (data: any) => void) => void

type SendCloseCommand = (shouldKeepTabOpen: boolean) => Promise<any> | void
interface HasFrame {
Expand Down
Loading

3 comments on commit 606a43b

@cypress-bot
Copy link
Contributor

@cypress-bot cypress-bot bot commented on 606a43b Jun 26, 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.12.1/linux-x64/develop-606a43bef86a66faf98eeeb02c6041f5dbda694b/cypress.tgz

@cypress-bot
Copy link
Contributor

@cypress-bot cypress-bot bot commented on 606a43b Jun 26, 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.12.1/linux-arm64/develop-606a43bef86a66faf98eeeb02c6041f5dbda694b/cypress.tgz

@cypress-bot
Copy link
Contributor

@cypress-bot cypress-bot bot commented on 606a43b Jun 26, 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.12.1/win32-x64/develop-606a43bef86a66faf98eeeb02c6041f5dbda694b/cypress.tgz

Please sign in to comment.