diff --git a/playwriter/src/cdp-session.ts b/playwriter/src/cdp-session.ts index 14e9abd..4edda2e 100644 --- a/playwriter/src/cdp-session.ts +++ b/playwriter/src/cdp-session.ts @@ -2,6 +2,7 @@ import WebSocket from 'ws' import type { Page } from 'playwright-core' import type { ProtocolMapping } from 'devtools-protocol/types/protocol-mapping.js' import type { CDPResponseBase, CDPEventBase } from './cdp-types.js' +import { getCdpUrl } from './utils.js' /** * Common interface for CDP sessions that works with both our CDPSession @@ -162,8 +163,9 @@ export class CDPSession implements ICDPSession { } } -export async function getCDPSessionForPage({ page, wsUrl }: { page: Page; wsUrl: string }): Promise { - const ws = new WebSocket(wsUrl) +export async function getCDPSessionForPage({ page, wsUrl }: { page: Page; wsUrl?: string }): Promise { + const resolvedWsUrl = wsUrl || getCdpUrl() + const ws = new WebSocket(resolvedWsUrl) await new Promise((resolve, reject) => { ws.on('open', resolve)