Skip to content

Commit

Permalink
fix: retain stail main frame for long
Browse files Browse the repository at this point in the history
Although #11246 has no
reproducible example and the root cause might be accessing main
frames while they are navigating, this PR adds a workaround to
retain a potentially stale main frame to prevent assertion errors.
  • Loading branch information
OrKoN committed Apr 8, 2024
1 parent 2821970 commit 8d7ab3f
Showing 1 changed file with 4 additions and 2 deletions.
6 changes: 4 additions & 2 deletions packages/puppeteer-core/src/cdp/FrameTree.ts
Original file line number Diff line number Diff line change
Expand Up @@ -21,6 +21,7 @@ export class FrameTree<FrameType extends Frame> {
// frameID -> childFrameIDs
#childIds = new Map<string, Set<string>>();
#mainFrame?: FrameType;
#isMainFrameStale = false;
#waitRequests = new Map<string, Set<Deferred<FrameType>>>();

getMainFrame(): FrameType | undefined {
Expand Down Expand Up @@ -59,8 +60,9 @@ export class FrameTree<FrameType extends Frame> {
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);
Expand All @@ -73,7 +75,7 @@ export class FrameTree<FrameType extends Frame> {
if (frame._parentId) {
this.#childIds.get(frame._parentId)?.delete(frame._id);
} else {
this.#mainFrame = undefined;
this.#isMainFrameStale = true;
}
}

Expand Down

0 comments on commit 8d7ab3f

Please sign in to comment.