From 26376224d557ce30c911f670c5e7625dd1a1df72 Mon Sep 17 00:00:00 2001 From: jrandolf <101637635+jrandolf@users.noreply.github.com> Date: Wed, 13 Mar 2024 16:15:00 +0100 Subject: [PATCH] fix: fix keyboard.sendCharacter (#12088) --- packages/puppeteer-core/src/bidi/Page.ts | 42 +++++++++++++++--------- test/TestExpectations.json | 7 ---- 2 files changed, 26 insertions(+), 23 deletions(-) diff --git a/packages/puppeteer-core/src/bidi/Page.ts b/packages/puppeteer-core/src/bidi/Page.ts index c662496a187..cd2921f8fea 100644 --- a/packages/puppeteer-core/src/bidi/Page.ts +++ b/packages/puppeteer-core/src/bidi/Page.ts @@ -13,8 +13,8 @@ import type {BoundingBox} from '../api/ElementHandle.js'; import type {WaitForOptions} from '../api/Frame.js'; import type {HTTPResponse} from '../api/HTTPResponse.js'; import type { - MediaFeature, GeolocationOptions, + MediaFeature, PageEvents, } from '../api/Page.js'; import { @@ -27,8 +27,12 @@ import {Accessibility} from '../cdp/Accessibility.js'; import {Coverage} from '../cdp/Coverage.js'; import {EmulationManager} from '../cdp/EmulationManager.js'; import {Tracing} from '../cdp/Tracing.js'; -import type {Cookie, CookieParam, CookieSameSite} from '../common/Cookie.js'; -import type {DeleteCookiesRequest} from '../common/Cookie.js'; +import type { + Cookie, + CookieParam, + CookieSameSite, + DeleteCookiesRequest, +} from '../common/Cookie.js'; import {UnsupportedOperation} from '../common/Errors.js'; import {EventEmitter} from '../common/EventEmitter.js'; import type {PDFOptions} from '../common/PDFOptions.js'; @@ -43,7 +47,6 @@ import type {BidiBrowser} from './Browser.js'; import type {BidiBrowserContext} from './BrowserContext.js'; import type {BidiCdpSession} from './CDPSession.js'; import type {BrowsingContext} from './core/BrowsingContext.js'; -import {BidiElementHandle} from './ElementHandle.js'; import {BidiFrame} from './Frame.js'; import type {BidiHTTPResponse} from './HTTPResponse.js'; import {BidiKeyboard, BidiMouse, BidiTouchscreen} from './Input.js'; @@ -161,21 +164,28 @@ export class BidiPage extends Page { } async focusedFrame(): Promise { - using frame = await this.mainFrame() + using handle = (await this.mainFrame() .isolatedRealm() .evaluateHandle(() => { - let frame: HTMLIFrameElement | undefined; - let win: Window | null = window; - while (win?.document.activeElement instanceof HTMLIFrameElement) { - frame = win.document.activeElement; - win = frame.contentWindow; + let win = window; + while ( + win.document.activeElement instanceof win.HTMLIFrameElement || + win.document.activeElement instanceof win.HTMLFrameElement + ) { + if (win.document.activeElement.contentWindow === null) { + break; + } + win = win.document.activeElement.contentWindow as typeof win; } - return frame; - }); - if (!(frame instanceof BidiElementHandle)) { - return this.mainFrame(); - } - return await frame.contentFrame(); + return win; + })) as BidiJSHandle; + const value = handle.remoteValue(); + assert(value.type === 'window'); + const frame = this.frames().find(frame => { + return frame._id === value.value.context; + }); + assert(frame); + return frame; } override frames(): BidiFrame[] { diff --git a/test/TestExpectations.json b/test/TestExpectations.json index 0a2e03ef62a..942abf26732 100644 --- a/test/TestExpectations.json +++ b/test/TestExpectations.json @@ -474,13 +474,6 @@ "expectations": ["FAIL"], "comment": "TODO: add a comment explaining why this expectation is required (include links to issues)" }, - { - "testIdPattern": "[keyboard.spec] Keyboard should send a character with sendCharacter in iframe", - "platforms": ["darwin", "linux", "win32"], - "parameters": ["webDriverBiDi"], - "expectations": ["SKIP"], - "comment": "TODO: add a comment explaining why this expectation is required (include links to issues)" - }, { "testIdPattern": "[launcher.spec] Launcher specs Puppeteer Browser.disconnect *", "platforms": ["win32"],