From 53894f25b1048ad1f73da33eb5ee4546b6fb01a0 Mon Sep 17 00:00:00 2001 From: Yury Semikhatsky Date: Wed, 12 Feb 2025 17:18:06 -0800 Subject: [PATCH] use-raw-call-func --- .../src/server/bidi/bidiExecutionContext.ts | 7 +++++++ .../playwright-core/src/server/bidi/bidiPage.ts | 13 +++---------- 2 files changed, 10 insertions(+), 10 deletions(-) diff --git a/packages/playwright-core/src/server/bidi/bidiExecutionContext.ts b/packages/playwright-core/src/server/bidi/bidiExecutionContext.ts index 341b11c043..aea4672196 100644 --- a/packages/playwright-core/src/server/bidi/bidiExecutionContext.ts +++ b/packages/playwright-core/src/server/bidi/bidiExecutionContext.ts @@ -156,6 +156,13 @@ export class BidiExecutionContext implements js.ExecutionContextDelegate { throw new Error('Can\'t get remote object for nodeId'); } + async contentFrameIdForFrame(handle: dom.ElementHandle) { + const contentWindow = await this._rawCallFunction('e => e.contentWindow', { handle: handle._objectId }); + if (contentWindow?.type === 'window') + return contentWindow.value.context; + return null; + } + async frameIdForWindowHandle(handle: js.JSHandle): Promise { if (!handle._objectId) throw new Error('JSHandle is not a DOM node handle'); diff --git a/packages/playwright-core/src/server/bidi/bidiPage.ts b/packages/playwright-core/src/server/bidi/bidiPage.ts index eb00aa939b..badd68d1a1 100644 --- a/packages/playwright-core/src/server/bidi/bidiPage.ts +++ b/packages/playwright-core/src/server/bidi/bidiPage.ts @@ -413,17 +413,10 @@ export class BidiPage implements PageDelegate { async getContentFrame(handle: dom.ElementHandle): Promise { const executionContext = toBidiExecutionContext(handle._context); - const contentWindow = await handle.evaluateHandle('e => e.contentWindow'); - if (!contentWindow) + const frameId = await executionContext.contentFrameIdForFrame(handle); + if (!frameId) return null; - try { - const frameId = await executionContext.frameIdForWindowHandle(contentWindow); - if (!frameId) - return null; - return this._page._frameManager.frame(frameId); - } finally { - contentWindow.dispose(); - } + return this._page._frameManager.frame(frameId); } async getOwnerFrame(handle: dom.ElementHandle): Promise {