From aa5b1824a5c82005fcfc05b002facfbbb9810f8f Mon Sep 17 00:00:00 2001 From: Alex Rudenko Date: Mon, 8 Apr 2024 11:24:54 +0200 Subject: [PATCH] fix: retain stale main frame for longer (#12225) --- packages/puppeteer-core/src/cdp/FrameTree.ts | 6 ++++-- 1 file changed, 4 insertions(+), 2 deletions(-) diff --git a/packages/puppeteer-core/src/cdp/FrameTree.ts b/packages/puppeteer-core/src/cdp/FrameTree.ts index 7ee1b86b5fa..dcd341c9e33 100644 --- a/packages/puppeteer-core/src/cdp/FrameTree.ts +++ b/packages/puppeteer-core/src/cdp/FrameTree.ts @@ -21,6 +21,7 @@ export class FrameTree { // frameID -> childFrameIDs #childIds = new Map>(); #mainFrame?: FrameType; + #isMainFrameStale = false; #waitRequests = new Map>>(); getMainFrame(): FrameType | undefined { @@ -59,8 +60,9 @@ export class FrameTree { this.#childIds.set(frame._parentId, new Set()); } this.#childIds.get(frame._parentId)!.add(frame._id); - } else if (!this.#mainFrame) { + } else if (!this.#mainFrame || this.#isMainFrameStale) { this.#mainFrame = frame; + this.#isMainFrameStale = false; } this.#waitRequests.get(frame._id)?.forEach(request => { return request.resolve(frame); @@ -73,7 +75,7 @@ export class FrameTree { if (frame._parentId) { this.#childIds.get(frame._parentId)?.delete(frame._id); } else { - this.#mainFrame = undefined; + this.#isMainFrameStale = true; } }