diff --git a/packages/puppeteer-core/src/common/Connection.ts b/packages/puppeteer-core/src/common/Connection.ts index a07f1e48c946f..0a5c366a7d80f 100644 --- a/packages/puppeteer-core/src/common/Connection.ts +++ b/packages/puppeteer-core/src/common/Connection.ts @@ -310,7 +310,8 @@ export class Connection extends EventEmitter { const session = new CDPSessionImpl( this, object.params.targetInfo.type, - sessionId + sessionId, + object.sessionId ); this.#sessions.set(sessionId, session); this.emit('sessionattached', session); @@ -470,6 +471,15 @@ export class CDPSession extends EventEmitter { throw new Error('Not implemented'); } + /** + * Parent session in terms of CDP's auto-attach mechanism. + * + * @internal + */ + parentSession(): CDPSession | undefined { + return undefined; + } + send( method: T, ...paramArgs: ProtocolMapping.Commands[T]['paramsType'] @@ -504,21 +514,36 @@ export class CDPSessionImpl extends CDPSession { #targetType: string; #callbacks = new CallbackRegistry(); #connection?: Connection; + #parentSessionId?: string; /** * @internal */ - constructor(connection: Connection, targetType: string, sessionId: string) { + constructor( + connection: Connection, + targetType: string, + sessionId: string, + parentSessionId: string | undefined + ) { super(); this.#connection = connection; this.#targetType = targetType; this.#sessionId = sessionId; + this.#parentSessionId = parentSessionId; } override connection(): Connection | undefined { return this.#connection; } + override parentSession(): CDPSession | undefined { + if (!this.#parentSessionId) { + return; + } + const parent = this.#connection?.session(this.#parentSessionId); + return parent ?? undefined; + } + override send( method: T, ...paramArgs: ProtocolMapping.Commands[T]['paramsType'] diff --git a/packages/puppeteer-core/src/common/DeviceRequestPrompt.test.ts b/packages/puppeteer-core/src/common/DeviceRequestPrompt.test.ts index d832898380044..2d45bd14d338b 100644 --- a/packages/puppeteer-core/src/common/DeviceRequestPrompt.test.ts +++ b/packages/puppeteer-core/src/common/DeviceRequestPrompt.test.ts @@ -36,6 +36,9 @@ class MockCDPSession extends EventEmitter { id() { return '1'; } + parentSession() { + return undefined; + } } describe('DeviceRequestPrompt', function () { diff --git a/packages/puppeteer-core/src/common/NetworkManager.test.ts b/packages/puppeteer-core/src/common/NetworkManager.test.ts index 8a098f877c433..8537e7382d649 100644 --- a/packages/puppeteer-core/src/common/NetworkManager.test.ts +++ b/packages/puppeteer-core/src/common/NetworkManager.test.ts @@ -37,6 +37,9 @@ class MockCDPSession extends EventEmitter { id() { return '1'; } + parentSession() { + return undefined; + } } describe('NetworkManager', () => { diff --git a/test/TestExpectations.json b/test/TestExpectations.json index 05a73d6bfab35..ba51e60ad2c96 100644 --- a/test/TestExpectations.json +++ b/test/TestExpectations.json @@ -2649,7 +2649,7 @@ "testIdPattern": "[mouse.spec] Mouse should resize the textarea", "platforms": ["darwin", "linux", "win32"], "parameters": ["firefox", "webDriverBiDi"], - "expectations": ["PASS", "FAIL"] + "expectations": ["FAIL", "PASS"] }, { "testIdPattern": "[mouse.spec] Mouse should select the text with mouse",