diff --git a/packages/puppeteer-core/src/common/bidi/Browser.ts b/packages/puppeteer-core/src/common/bidi/Browser.ts index e869ce524ef98..b3c4bcec7a6a5 100644 --- a/packages/puppeteer-core/src/common/bidi/Browser.ts +++ b/packages/puppeteer-core/src/common/bidi/Browser.ts @@ -54,6 +54,7 @@ export class Browser extends BrowserBase { 'browsingContext', 'network', 'log', + 'script', ]; static readonly subscribeCdpEvents: Bidi.Cdp.EventNames[] = [ // Coverage diff --git a/packages/puppeteer-core/src/common/bidi/Realm.ts b/packages/puppeteer-core/src/common/bidi/Realm.ts index 8c42d552511dc..0a2c3f3097033 100644 --- a/packages/puppeteer-core/src/common/bidi/Realm.ts +++ b/packages/puppeteer-core/src/common/bidi/Realm.ts @@ -46,6 +46,17 @@ export class Realm extends EventEmitter { setFrame(frame: Frame): void { this.#frame = frame; + + // TODO(jrandolf): We should try to find a less brute-force way of doing + // this. + this.connection.on( + Bidi.ChromiumBidi.Script.EventNames.RealmDestroyed, + async () => { + const util = this.internalPuppeteerUtil; + this.internalPuppeteerUtil = undefined; + void (await util)?.dispose().catch(() => {}); + } + ); } protected internalPuppeteerUtil?: Promise>; diff --git a/packages/puppeteer-core/src/common/bidi/Sandbox.ts b/packages/puppeteer-core/src/common/bidi/Sandbox.ts index 3e8f871e9cdba..e83def6d23e68 100644 --- a/packages/puppeteer-core/src/common/bidi/Sandbox.ts +++ b/packages/puppeteer-core/src/common/bidi/Sandbox.ts @@ -60,7 +60,6 @@ export interface SandboxChart { * @internal */ export class Sandbox implements RealmBase { - #document?: ElementHandle; #realm: Realm; #timeoutSettings: TimeoutSettings; @@ -76,13 +75,11 @@ export class Sandbox implements RealmBase { } async document(): Promise> { - if (this.#document) { - return this.#document; - } - this.#document = await this.#realm.evaluateHandle(() => { + // TODO(jrandolf): We should try to cache this because we need to dispose + // this when it's unused. + return await this.#realm.evaluateHandle(() => { return document; }); - return this.#document; } async $( diff --git a/test/TestExpectations.json b/test/TestExpectations.json index 40e04e8f63d08..d5e47c6009a15 100644 --- a/test/TestExpectations.json +++ b/test/TestExpectations.json @@ -335,12 +335,48 @@ "parameters": ["webDriverBiDi"], "expectations": ["PASS"] }, + { + "testIdPattern": "[browser.spec] Browser specs Browser.target should return browser target", + "platforms": ["darwin", "linux", "win32"], + "parameters": ["webDriverBiDi"], + "expectations": ["PASS"] + }, + { + "testIdPattern": "[browsercontext.spec] BrowserContext should close all belonging targets once closing context", + "platforms": ["darwin", "linux", "win32"], + "parameters": ["webDriverBiDi"], + "expectations": ["PASS"] + }, + { + "testIdPattern": "[browsercontext.spec] BrowserContext should create new incognito context", + "platforms": ["darwin", "linux", "win32"], + "parameters": ["webDriverBiDi"], + "expectations": ["PASS"] + }, { "testIdPattern": "[browsercontext.spec] BrowserContext should have default context", "platforms": ["darwin", "linux", "win32"], "parameters": ["webDriverBiDi"], "expectations": ["PASS"] }, + { + "testIdPattern": "[browsercontext.spec] BrowserContext should timeout waiting for a non-existent target", + "platforms": ["darwin", "linux", "win32"], + "parameters": ["webDriverBiDi"], + "expectations": ["PASS"] + }, + { + "testIdPattern": "[browsercontext.spec] BrowserContext should wait for a target", + "platforms": ["darwin", "linux", "win32"], + "parameters": ["webDriverBiDi"], + "expectations": ["PASS"] + }, + { + "testIdPattern": "[browsercontext.spec] BrowserContext window.open should use parent tab context", + "platforms": ["darwin", "linux", "win32"], + "parameters": ["webDriverBiDi"], + "expectations": ["PASS"] + }, { "testIdPattern": "[CDPSession.spec] Target.createCDPSession *", "platforms": ["darwin", "linux", "win32"], @@ -1896,15 +1932,15 @@ "expectations": ["FAIL"] }, { - "testIdPattern": "[elementhandle.spec] ElementHandle specs ElementHandle.boundingBox should force a layout", + "testIdPattern": "[dialog.spec] Page.Events.Dialog should allow accepting prompts", "platforms": ["darwin", "linux", "win32"], - "parameters": ["firefox", "webDriverBiDi"], + "parameters": ["chrome", "webDriverBiDi"], "expectations": ["FAIL"] }, { - "testIdPattern": "[dialog.spec] Page.Events.Dialog should allow accepting prompts", + "testIdPattern": "[elementhandle.spec] ElementHandle specs ElementHandle.boundingBox should force a layout", "platforms": ["darwin", "linux", "win32"], - "parameters": ["chrome", "webDriverBiDi"], + "parameters": ["firefox", "webDriverBiDi"], "expectations": ["FAIL"] }, { @@ -3191,6 +3227,12 @@ "parameters": ["cdp", "firefox"], "expectations": ["SKIP"] }, + { + "testIdPattern": "[page.spec] Page Page.close should run beforeunload if asked for", + "platforms": ["darwin", "linux", "win32"], + "parameters": ["chrome", "webDriverBiDi"], + "expectations": ["PASS"] + }, { "testIdPattern": "[page.spec] Page Page.close should terminate network waiters", "platforms": ["darwin", "linux", "win32"], @@ -3845,6 +3887,12 @@ "parameters": ["cdp", "chrome", "new-headless"], "expectations": ["FAIL", "PASS"] }, + { + "testIdPattern": "[click.spec] Page.click should click the button after navigation", + "platforms": ["darwin"], + "parameters": ["chrome", "headless", "webDriverBiDi"], + "expectations": ["PASS"] + }, { "testIdPattern": "[click.spec] Page.click should click the button with fixed position inside an iframe", "platforms": ["darwin", "linux", "win32"], @@ -3952,11 +4000,5 @@ "platforms": ["darwin", "linux", "win32"], "parameters": ["cdp", "chrome", "headless"], "expectations": ["FAIL", "PASS"] - }, - { - "testIdPattern": "[page.spec] Page Page.close should run beforeunload if asked for", - "platforms": ["darwin", "linux", "win32"], - "parameters": ["chrome", "webDriverBiDi"], - "expectations": ["PASS"] } ]