Skip to content

Commit

Permalink
fix: destroy puppeteer utility on context destruction
Browse files Browse the repository at this point in the history
  • Loading branch information
jrandolf committed Aug 1, 2023
1 parent 87bd791 commit a44b075
Show file tree
Hide file tree
Showing 4 changed files with 65 additions and 16 deletions.
1 change: 1 addition & 0 deletions packages/puppeteer-core/src/common/bidi/Browser.ts
Expand Up @@ -54,6 +54,7 @@ export class Browser extends BrowserBase {
'browsingContext',
'network',
'log',
'script',
];
static readonly subscribeCdpEvents: Bidi.Cdp.EventNames[] = [
// Coverage
Expand Down
11 changes: 11 additions & 0 deletions packages/puppeteer-core/src/common/bidi/Realm.ts
Expand Up @@ -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;
delete this.internalPuppeteerUtil;
void (await util)?.dispose().catch(() => {});
}
);
}

protected internalPuppeteerUtil?: Promise<JSHandle<PuppeteerUtil>>;
Expand Down
7 changes: 1 addition & 6 deletions packages/puppeteer-core/src/common/bidi/Sandbox.ts
Expand Up @@ -60,7 +60,6 @@ export interface SandboxChart {
* @internal
*/
export class Sandbox implements RealmBase {
#document?: ElementHandle<Document>;
#realm: Realm;

#timeoutSettings: TimeoutSettings;
Expand All @@ -76,13 +75,9 @@ export class Sandbox implements RealmBase {
}

async document(): Promise<ElementHandle<Document>> {
if (this.#document) {
return this.#document;
}
this.#document = await this.#realm.evaluateHandle(() => {
return await this.#realm.evaluateHandle(() => {
return document;
});
return this.#document;
}

async $<Selector extends string>(
Expand Down
62 changes: 52 additions & 10 deletions test/TestExpectations.json
Expand Up @@ -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"],
Expand Down Expand Up @@ -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"]
},
{
Expand Down Expand Up @@ -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"],
Expand Down Expand Up @@ -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"],
Expand Down Expand Up @@ -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"]
}
]

0 comments on commit a44b075

Please sign in to comment.