Skip to content

Commit 049e13c

Browse files
authored
fix: improve frame session management (#13022)
1 parent 9aef4ab commit 049e13c

File tree

2 files changed

+5
-10
lines changed

2 files changed

+5
-10
lines changed

packages/puppeteer-core/src/cdp/Frame.ts

Lines changed: 2 additions & 6 deletions
Original file line numberDiff line numberDiff line change
@@ -322,12 +322,8 @@ export class CdpFrame extends Frame {
322322

323323
@throwIfDetached
324324
async addPreloadScript(preloadScript: CdpPreloadScript): Promise<void> {
325-
// TODO: this might be not correct and we might be adding a preload
326-
// script multiple times to the nested frames.
327-
if (
328-
this.#client === this._frameManager.client &&
329-
this !== this._frameManager.mainFrame()
330-
) {
325+
const parentFrame = this.parentFrame();
326+
if (parentFrame && this.#client === parentFrame.client) {
331327
return;
332328
}
333329
if (preloadScript.getIdForFrame(this)) {

packages/puppeteer-core/src/cdp/FrameManager.ts

Lines changed: 3 additions & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -407,11 +407,10 @@ export class FrameManager extends EventEmitter<FrameManagerEvents> {
407407
): void {
408408
let frame = this.frame(frameId);
409409
if (frame) {
410-
if (session && frame.client !== this.#client) {
411-
// TODO: check this condition. It might not be correct for
412-
// nested frames.
410+
const parentFrame = this.frame(parentFrameId);
411+
if (session && parentFrame && frame.client !== parentFrame?.client) {
413412
// If an OOP iframes becomes a normal iframe
414-
// again it is first attached to the parent page before the
413+
// again it is first attached to the parent frame before the
415414
// target is removed.
416415
frame.updateClient(session);
417416
}

0 commit comments

Comments
 (0)