diff --git a/packages/playwright-core/src/server/bidi/bidiPage.ts b/packages/playwright-core/src/server/bidi/bidiPage.ts index dd2d276c18..82e57d8654 100644 --- a/packages/playwright-core/src/server/bidi/bidiPage.ts +++ b/packages/playwright-core/src/server/bidi/bidiPage.ts @@ -423,7 +423,22 @@ export class BidiPage implements PageDelegate { } async getOwnerFrame(handle: dom.ElementHandle): Promise { - throw new Error('Method not implemented.'); + // TODO: switch to utility world? + const windowHandle = await handle.evaluateHandle(node => { + const doc = node.ownerDocument ?? node as Document; + return doc.defaultView; + }); + if (!windowHandle) + return null; + if (!windowHandle._objectId) + return null; + const executionContext = toBidiExecutionContext(windowHandle._context as dom.FrameExecutionContext); + const contentWindow = await executionContext.rawCallFunction('e => e', { handle: windowHandle._objectId }); + if (contentWindow.type === 'window') { + const frameId = contentWindow.value.context; + return frameId; + } + return null; } isElementHandle(remoteObject: bidi.Script.RemoteValue): boolean {