fix(web): press a character that is not on the US keyboard in Chromium

Merged
JA
3d ago
+414-19

What

  • On the web engine in Chromium, press('é') (also ß, €, 中, an emoji) presses the character as a key. It failed with ENGINE_FAILURE: locator.press: Unknown key: "é".
  • The page gets keydown, input, and keyup as for a US key, and modifiers work (Control+é). code is empty and keyCode is 0, since no physical key stands behind the character.
  • In Firefox and WebKit it fails as UNSUPPORTED_CAPABILITY before 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

  1. requireCharacterPress (packages/web/src/press-character.ts:30) parses the key with core's parseKey. 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.
  2. Node path (packages/web/src/surface.ts:1274): pressCharacterOn focuses the node, as Playwright's press does, then presses. Focused path, the agent's press without a target (surface.ts:1329): pressCharacter directly.
  3. pressCharacter (press-character.ts:56) opens a CDP session on the page and sends Input.dispatchKeyEvent keyDown with key and text, then keyUp. The browser routes the key to the focused element, in an iframe too.
  4. Modifiers go down and up through page.keyboard, so Playwright's record of held keys stays true. release lets every held modifier up when the key fails too, and a modifier that cannot be released fails the press. The CDP event carries their modifiers bits. With a modifier other than Shift the event has no text, so it types nothing, as a US key does.
  5. 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 check keyboard.type already had inline, moved so both use it.
  6. 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.
  7. 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.

mainthis PR
press('é'), 中, 😀 on a text inputENGINE_FAILURE: locator.press: Unknown key: "é", no eventsvalue é中😀, keydown:é;input:é;keyup:é; per character
press('é') on a buttonENGINE_FAILUREkeydown:é;keyup:é;, nothing typed
press('Control+é'), then press('a')ENGINE_FAILURE, then keydown:a:ctrl: Control is still down and a is not typedkeydown: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.ts runs 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 (no text, 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.1 page, localhost frame), 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/**/*.mdx page for the behavior, and skills/e2e/ if the skill describes it.
  • Contract change: emitted .d.ts reviewed, tests/types/sdk-types.ts updated; wire change edits the schema and both fixtures.
  • Engine contract change (e2e/engine): changesets for e2e, @e2e-dev/web, and @e2e-dev/mobile.