fix(web): press a character that is not on the US keyboard in Chromium
Merged
JA
3d ago+414+414+012345678901234567890123456789-19-19-01234567890123456789
What
- On the web engine in Chromium,
press('é')(alsoß,€,中, an emoji) presses the character as a key. It failed withENGINE_FAILURE: locator.press: Unknown key: "é". - The page gets
keydown,input, andkeyupas for a US key, and modifiers work (Control+é).codeis empty andkeyCodeis 0, since no physical key stands behind the character. - In Firefox and WebKit it fails as
UNSUPPORTED_CAPABILITYbefore any key is sent.
Why
- Playwright 1.65.1 has keys for U+0020 to U+007E only, while the key grammar takes any single printable character.
press('Control+é')also left Control held for the rest of the test. Playwright presses the modifier, then throws on the key and never releases it.
How it works
requireCharacterPress(packages/web/src/press-character.ts:30) parses the key with core'sparseKey. A character outside U+0020..U+007E is returned with its modifiers on Chromium and refused elsewhere. Every other key takes the same Playwright call as on main.- Node path (
packages/web/src/surface.ts:1274):pressCharacterOnfocuses the node, as Playwright'spressdoes, then presses. Focused path, the agent'spresswithout a target (surface.ts:1329):pressCharacterdirectly. pressCharacter(press-character.ts:56) opens a CDP session on the page and sendsInput.dispatchKeyEventkeyDownwithkeyandtext, thenkeyUp. The browser routes the key to the focused element, in an iframe too.- Modifiers go down and up through
page.keyboard, so Playwright's record of held keys stays true.releaselets every held modifier up when the key fails too, and a modifier that cannot be released fails the press. The CDP event carries theirmodifiersbits. With a modifier other than Shift the event has notext, so it types nothing, as a US key does. AttemptSession.checkpoint(packages/web/src/attempt-session.ts:125) runs between opening the CDP session and the first key, so a press that timed out or lost its context sends nothing. It is the checkkeyboard.typealready had inline, moved so both use it.- Dropped: inserting the character with
keyboard.insertText. That sends no key event, so it needed checks for which nodes take text and refused buttons, selects and number inputs. A real key event leaves that to the browser. - Firefox and WebKit: Playwright exposes no channel that takes a key outside its layout there. A follow-up adds them once the engine has one.
Issue
Fixes #2282
Verified
Ran it locally: yes
Testbed, e2e run on a scratch test in Chromium, with packages/web built from this branch and with main's surface.ts and attempt-session.ts. The page logs keydown, input, and keyup.
| main | this PR | |
|---|---|---|
press('é'), 中, 😀 on a text input | ENGINE_FAILURE: locator.press: Unknown key: "é", no events | value é中😀, keydown:é;input:é;keyup:é; per character |
press('é') on a button | ENGINE_FAILURE | keydown:é;keyup:é;, nothing typed |
press('Control+é'), then press('a') | ENGINE_FAILURE, then keydown:a:ctrl: Control is still down and a is not typed | keydown:Control:ctrl;keydown:é:ctrl;keyup:é:ctrl;keyup:Control;, then a is typed |
== this PR
PROBE text field | value=é中😀 | events=keydown:é;input:é;keyup:é;keydown:中;input:中;keyup:中;keydown:😀;input:😀;keyup:😀; | errors=
PROBE button | value= | events=keydown:é;keyup:é; | errors=
PROBE modifier then plain key | value=a | events=keydown:Control:ctrl;keydown:é:ctrl;keyup:é:ctrl;keyup:Control;keydown:a;input:a;keyup:a; | errors=
Tests 3 passed (3)
== main sources
PROBE text field | value= | events= | errors=ENGINE_FAILURE: locator.press: Unknown key: "é" / ENGINE_FAILURE: locator.press: Unknown key: "中" / ENGINE_FAILURE: locator.press: Unknown key: "😀"
PROBE button | value= | events= | errors=ENGINE_FAILURE: locator.press: Unknown key: "é"
PROBE modifier then plain key | value= | events=keydown:Control:ctrl;keydown:a:ctrl;keyup:a:ctrl; | errors=ENGINE_FAILURE: locator.press: Unknown key: "é"
Tests 3 failed | 0 passed (3)
tests/integration/press-characters.test.tsruns the same cases in real Chromium, plus a contenteditable node, an iframe field, a number input (the browser rejectséitself),Shift+é, and the refusal in real Firefox.- Mutation check: seven mutants of
press-character.ts(notext, no modifier bits, no browser gate, no checkpoint, no modifier release, text with any modifier, no focus) each fail 4 to 9 tests. - Cross-site iframe: checked with a scratch Playwright script (
127.0.0.1page,localhostframe), the key reaches the frame's field. - Not run: WebKit, hosted or attached browsers. No video: the visible change is one character in a field.
Checklist
- Changeset added (
pnpm changeset) for any change to a published package, or the change is testbed, docs, or CI only. - Breaking change: title carries
!, the changeset body names what breaks and what replaces it, and the deprecation warning landed a window earlier (stability policy in CONTRIBUTING.md). - Docs updated in the same PR: the
docs/**/*.mdxpage for the behavior, andskills/e2e/if the skill describes it. - Contract change: emitted
.d.tsreviewed,tests/types/sdk-types.tsupdated; wire change edits the schema and both fixtures. - Engine contract change (
e2e/engine): changesets fore2e,@e2e-dev/web, and@e2e-dev/mobile.