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 {