diff --git a/packages/puppeteer-core/src/common/Connection.ts b/packages/puppeteer-core/src/common/Connection.ts index ec00b2a5d20..d42ac877d58 100644 --- a/packages/puppeteer-core/src/common/Connection.ts +++ b/packages/puppeteer-core/src/common/Connection.ts @@ -137,10 +137,6 @@ export class CallbackRegistry { }); } - getCallback(id: number): Callback | undefined { - return this.#callbacks.get(id); - } - reject(id: number, message: string, originalMessage?: string): void { const callback = this.#callbacks.get(id); if (!callback) { diff --git a/packages/puppeteer-core/src/common/bidi/Browser.ts b/packages/puppeteer-core/src/common/bidi/Browser.ts index 66f10bb422d..f0282a751b4 100644 --- a/packages/puppeteer-core/src/common/bidi/Browser.ts +++ b/packages/puppeteer-core/src/common/bidi/Browser.ts @@ -16,6 +16,8 @@ import {ChildProcess} from 'child_process'; +import * as Bidi from 'chromium-bidi/lib/cjs/protocol/protocol.js'; + import { Browser as BrowserBase, BrowserCloseCallback, @@ -30,14 +32,16 @@ import {Connection} from './Connection.js'; * @internal */ export class Browser extends BrowserBase { - /** - * @internal - */ static async create(opts: Options): Promise { // TODO: await until the connection is established. try { await opts.connection.send('session.new', {}); } catch {} + await opts.connection.send('session.subscribe', { + events: [ + 'browsingContext.contextCreated', + ] as Bidi.Session.SubscribeParametersEvent[], + }); return new Browser(opts); } @@ -45,9 +49,6 @@ export class Browser extends BrowserBase { #closeCallback?: BrowserCloseCallback; #connection: Connection; - /** - * @internal - */ constructor(opts: Options) { super(); this.#process = opts.process; diff --git a/packages/puppeteer-core/src/common/bidi/Connection.ts b/packages/puppeteer-core/src/common/bidi/Connection.ts index 60a705b7202..05de314acf0 100644 --- a/packages/puppeteer-core/src/common/bidi/Connection.ts +++ b/packages/puppeteer-core/src/common/bidi/Connection.ts @@ -140,30 +140,37 @@ export class Connection extends EventEmitter { object.message ); } else { - if ( - this.#callbacks.getCallback(object.id)?.label === - 'browsingContext.create' - ) { - this.#contexts.set( - object.result.context, - new Context(this, object.result) - ); - } this.#callbacks.resolve(object.id, object); } } else { - let context: Context | undefined; - if ('context' in object.params) { - context = this.#contexts.get(object.params.context); - } else if ('source' in object.params && !!object.params.source.context) { - context = this.#contexts.get(object.params.source.context); - } - context?.emit(object.method, object.params); - + this.#handleSpecialEvents(object); + this.#maybeEmitOnContext(object); this.emit(object.method, object.params); } } + #maybeEmitOnContext(event: Bidi.Message.EventMessage) { + let context: Context | undefined; + // Context specific events + if ('context' in event.params) { + context = this.#contexts.get(event.params.context); + // `log.entryAdded` specific context + } else if ('source' in event.params && !!event.params.source.context) { + context = this.#contexts.get(event.params.source.context); + } + context?.emit(event.method, event.params); + } + + #handleSpecialEvents(event: Bidi.Message.EventMessage) { + switch (event.method) { + case 'browsingContext.contextCreated': + this.#contexts.set( + event.params.context, + new Context(this, event.params) + ); + } + } + #onClose(): void { if (this.#closed) { return; diff --git a/test/TestExpectations.json b/test/TestExpectations.json index dd3a29a7dbe..592d696e06c 100644 --- a/test/TestExpectations.json +++ b/test/TestExpectations.json @@ -107,12 +107,6 @@ "parameters": ["cdp", "firefox"], "expectations": ["SKIP"] }, - { - "testIdPattern": "[emulation.spec] Emulation Page.viewport should detect touch when applying viewport with touches", - "platforms": ["darwin", "linux", "win32"], - "parameters": ["firefox"], - "expectations": ["PASS", "TIMEOUT"] - }, { "testIdPattern": "[evaluation.spec] Evaluation specs Frame.evaluate should execute after cross-site navigation", "platforms": ["darwin", "linux", "win32"], @@ -671,6 +665,12 @@ "parameters": ["cdp", "firefox"], "expectations": ["FAIL"] }, + { + "testIdPattern": "[emulation.spec] Emulation Page.viewport should detect touch when applying viewport with touches", + "platforms": ["darwin", "linux", "win32"], + "parameters": ["cdp", "firefox"], + "expectations": ["PASS", "TIMEOUT"] + }, { "testIdPattern": "[emulation.spec] Emulation Page.viewport should support landscape emulation", "platforms": ["darwin", "linux", "win32"], @@ -1835,6 +1835,12 @@ "parameters": ["cdp", "firefox"], "expectations": ["FAIL"] }, + { + "testIdPattern": "[queryhandler.spec] Query handler tests P selectors should work with deep combinators", + "platforms": ["darwin", "linux", "win32"], + "parameters": ["cdp", "firefox"], + "expectations": ["FAIL"] + }, { "testIdPattern": "[requestinterception-experimental.spec] request interception \"after each\" hook in \"request interception\"", "platforms": ["win32"],