feat(web): tap with the middle or right mouse button

Draft
SA
4d ago
+857-189

What

button: 'left' | 'middle' | 'right' can be passed to tap() and click(). It works with count and position, like Playwright's click({ button, clickCount, position }). A count above 1 also works with position now, for any button, and on a device too. Main refused that with INVALID_ARGUMENT. A middle-click test doesn't have to dispatch auxclick in the page anymore.

await screen.getByRole('link', 'Docs').click({ button: 'middle' });
await row.tap({ button: 'right', count: 2, modifiers: ['Alt'] });
await canvas.tap({ button: 'middle', count: 3, position: { x: 40, y: 12 } });

Middle taps and repeated right taps work on the web engine only. Mobile and desktop refuse them with UNSUPPORTED_CAPABILITY. A single right tap is the same action as secondaryTap(), so it works wherever that does (web and desktop).

Why

tap() and click() only pressed the left button. Tests needed secondaryTap() for a right click, and browser.evaluate to dispatch auxclick for a middle click. A right double click wasn't possible at all.

How it works

  1. tapWith treats left as no button and turns count and button into one action with tapAction (packages/core/src/locator/screen.ts:429, :891):
    • 1 press: tap, or secondaryTap for the right button.
    • 2 presses: doubleTap.
    • 3 or more: multiTap.
    • For a middle click or repeated right clicks, button is set on the action.
  2. Without position, the node action is that same action plus the held keys. With position, it goes to performWithin as a pointer action (screen.ts:437). The step label is built from the count, button, and keys the caller passed (screen.ts:483).
  3. The contract changes are additive. The four tap kinds share TapActions, used by PointerAction and LocatorAction (with modifiers) (packages/core/src/engine/contract.ts:302, :340, :415):
    • tap takes button?: 'middle', since a single right click is secondaryTap.
    • doubleTap and multiTap take button?: 'middle' | 'right'.
    • multiTap is a new pointer kind. POINTER_ACTION_KINDS stays the SPI v1 list, and KNOWN_POINTER_ACTION_KINDS adds multiTap (contract.ts:447), as KNOWN_LOCATOR_ACTION_KINDS does for the node kinds.
  4. An engine opts in with tapButtons: true (packages/core/src/engine/index.ts:843). defineEngine accepts it with perform or performAt (packages/core/src/engine/manifest.ts:305). It's in the protocol manifest (packages/core/src/engine/protocol/manifest.ts:31). engine-manifest-v1.schema.json allows tapButtons and adds multiTap to pointerActions.
  5. An action with a button is refused with UNSUPPORTED_CAPABILITY when the engine doesn't declare tapButtons:
    • before waiting for the node, in checkAction and checkPointerAction (packages/core/src/locator/engine.ts:238, :262)
    • again in perform and performAt on the session, like modifiers (packages/core/src/engine/session.ts:483, :498)
  6. The web engine declares tapButtons and the pointer multiTap kind (packages/web/src/engine.ts:144, :147). In packages/web/src/actions.ts:
    • A middle tap goes straight to the node with locator.click({ button: 'middle' }) (:311). The label stand-in that check and left taps use would send the click to a hidden checkbox's label instead.
    • For 2 clicks it passes the button to locator.dblclick or mouse.dblclick (:318, :440).
    • For 3 or more it passes the button and clickCount to locator.click or mouse.click (:322, :443).
    • A multi-tap above 200 clicks is refused before any input (:37). Playwright queues every press before it sends the first, so a larger count could hold the worker past its timeout. The mobile engine has the same limit.
  7. The mobile engine declares the pointer multiTap kind (packages/mobile/src/actions.ts:51). It sends one agent-device press with count at the point, the way the node multiTap does, and refuses a count above 200 before any press (actions.ts:78).
  8. The web and mobile engines raise their @e2e-dev/core and e2e peer floors to 0.25.1 (packages/web/package.json, packages/mobile/package.json). Core 0.25.0 refuses tapButtons as an unknown engine key and multiTap as an unknown pointer kind, so these engines would throw at config load next to it. The desktop engine declares neither and keeps its range.

Positioned taps accepted only a count of 1 on main. They use the doubleTap pointer action for 2 clicks and multiTap for 3 or more. modifiers with position is still INVALID_ARGUMENT.

For engine authors: with an exhaustive switch over PointerAction, add a multiTap case when upgrading, even if the engine doesn't support it (an engine that doesn't list it in pointerActions can reject it).

One catch on Chromium: a tab opened by a middle click on a link doesn't have an opener, so it isn't listed by tabs() or seen by waitForPopup. It's documented under Tabs in docs/reference/web.mdx.

Issue

Part of ENG-1227 (action options on every platform). This PR covers the mouse buttons.

Verified

Ran it locally: yes

  • Built CLI against the testbed app, one scratch test on a chromium target and a firefox target. The page logs each event the link receives, and every step asserts it (Chromium video attached below). Chromium:
 ✓ |chromium| buttons.e2e.ts > taps with each mouse button, count, and position 5.66s

tap({ button: 'middle', modifiers: ['Shift'] })           -> auxclick button=1 detail=1 x=48 shiftKey
tap({ button: 'right', modifiers: ['Alt'] })              -> contextmenu button=2 detail=0 x=48 altKey, auxclick button=2 detail=1 x=48 altKey
tap({ button: 'middle', count: 2 })                       -> auxclick button=1 detail=1, auxclick button=1 detail=2
tap({ button: 'right', count: 3 })                        -> contextmenu, auxclick button=2 detail=1 / 2 / 3
tap({ button: 'middle', position: { x: 5, y: 5 } })       -> auxclick button=1 detail=1 x=5
tap({ button: 'right', count: 2, position: { x: 7, y: 5 } }) -> contextmenu, auxclick button=2 detail=1 / 2, x=7
tap({ count: 3, position: { x: 9, y: 5 } })               -> click button=0 detail=1 / 2 / 3, x=9

Firefox 159, the same test:

 ✓ |firefox| buttons.e2e.ts > taps with each mouse button, count, and position 6.57s

tap({ button: 'right', modifiers: ['Alt'] })              -> contextmenu button=2 detail=1 x=48 altKey, auxclick button=2 detail=1 x=48 altKey
tap({ button: 'right', count: 3 })                        -> contextmenu, auxclick button=2 detail=1 / 2 / 3
tap({ button: 'right', count: 2, position: { x: 7, y: 5 } }) -> contextmenu, auxclick button=2 detail=1 / 2, x=7

The other Firefox lines match Chromium's. Firefox reports a contextmenu event's detail as the click count, where Chromium reports 0, so the committed tests that check contextmenu run on Chromium.

  • Mobile benchmark on an iPhone 18 Pro simulator (iOS 27.2), with a new test in tests/controls.e2e.ts that taps the Gestures button 3 times at (10, 10) and checks the tap counter (iOS video attached below):
   ✓ |ios-simulator| tests/controls.e2e.ts > control inventory > tap({ count: 3 }) lands three presses 12.42s
   ✓ |ios-simulator| tests/controls.e2e.ts > control inventory > tap({ count: 3, position }) lands three presses at the point 9.72s
   ✓ |ios-simulator| tests/controls.e2e.ts > control inventory > pointer verbs land at the point asked for 11.94s

The report's step reads getByRole("button", name: "Double-tap me") 3 times at (10, 10). With the mobile engine from before this change, the same test fails before any press:

     Failed  × |ios-simulator| tests/controls.e2e.ts:358 > control inventory > tap({ count: 3, position }) lands three presses at the point
               UNSUPPORTED_CAPABILITY: the "multiTap" action at a point is not available on this target: its engine declares tap, doubleTap, longPress, swipeTo

Android: not run locally. CI runs the same test on the emulator.

  • Testbed pointer and click suites on Chromium (e2e run tests/pointer.e2e.ts tests/click.e2e.ts): 73 passed.
  • Docs screenshots: not captured. The repo doesn't have a local renderer for the docs site.

pnpm bench:ab --suite testbed --max-pairs 8 -- tests/click.e2e.ts tests/pointer.e2e.ts, run on b280efb7. The commits after it change comments, docs, test titles, the wording of one error message, and the mobile engine's pointer kinds, none of which this web suite runs:

bench-ab: 679519f1 (merge base with origin/main) vs b280efb7

apps/testbed: e2e run --workers 1 tests/click.e2e.ts tests/pointer.e2e.ts. 6 pairs in random order, resolved after 6 pairs. Threshold ±5% and 10 ms. darwin arm64, Apple M5 Pro x18, Node 24.22.1, load 2.5.

Behavior

Every test ran the same steps with the same outcome on every run of both builds.

Timings

Metricbase median (IQR)head median (IQR)change (95% CI)verdict
wall (process)14.61 s (14.52 s-14.71 s)14.57 s (14.54 s-14.61 s)-0.4% (-1.9% to +0.4%)same
suite (sum of attempts)13.88 s (13.79 s-13.97 s)13.88 s (13.85 s-13.90 s)-0.2% (-1.6% to +0.7%)same
action (events)10.45 s (10.39 s-10.49 s)10.43 s (10.42 s-10.45 s)-0.4% (-1.2% to +0.5%)same
step locator.tap10.01 s (9.96 s-10.04 s)9.99 s (9.97 s-10.01 s)-0.3% (-1.1% to +0.5%)same
step browser.goto2.13 s (2.12 s-2.15 s)2.15 s (2.13 s-2.17 s)+0.6% (-2.5% to +1.7%)same
step browser.evaluate605 ms (600 ms-615 ms)600 ms (598 ms-610 ms)-0.8% (-4.0% to +3.0%)same, under the floor
step app.open357 ms (347 ms-367 ms)351 ms (349 ms-356 ms)-1.1% (-5.4% to +2.0%)same, under the floor
step locator.secondaryTap171 ms (170 ms-171 ms)170 ms (170 ms-170 ms)-0.3% (-0.9% to +0.6%)same, under the floor
step screen.swipe117 ms (115 ms-119 ms)118 ms (117 ms-119 ms)-0.8% (-4.4% to +5.9%)same, under the floor
step locator.fill60 ms (58 ms-62 ms)60 ms (59 ms-60 ms)-1.6% (-7.0% to +6.1%)same, under the floor
step browser.mouse.move59 ms (57 ms-61 ms)62 ms (60 ms-63 ms)+7.0% (-9.7% to +12.3%)same, under the floor
step locator.doubleTap51 ms (51 ms-52 ms)52 ms (51 ms-52 ms)+1.0% (0.0% to +14.6%)same, under the floor
step locator.click38 ms (30 ms-47 ms)31 ms (31 ms-42 ms)-2.7% (-33.3% to +27.2%)same, under the floor
step expect.toHaveText18 ms (16 ms-18 ms)17 ms (15 ms-17 ms)-2.8% (-22.2% to +6.1%)same, under the floor
step screen.tapAt18 ms (16 ms-18 ms)17 ms (16 ms-17 ms)-2.8% (-15.7% to +3.1%)same, under the floor
step screen.doubleTapAt7 ms (6 ms-7 ms)6 ms (6 ms-7 ms)-7.4% (-14.3% to +8.0%)same, under the floor
step browser.mouse.down2 ms (1 ms-2 ms)1 ms (0 ms-1 ms)0.0% (0.0% to 0.0%)same
step browser.keyboard.up1 ms (0 ms-1 ms)0 ms (0 ms-1 ms)0.0% (0.0% to 0.0%)same
step expect.toHaveValue1 ms (1 ms-1 ms)1 ms (1 ms-1 ms)0.0% (-29.3% to +41.4%)same
step browser.mouse.up0 ms (0 ms-1 ms)2 ms (1 ms-2 ms)+41.4% (0.0% to +100.0%)same, under the floor

Counters

Every counter matched on every run of both builds.

Tests outside the threshold: 0 of 617

With 617 tests compared at 95%, about 30.9 could land outside by chance.

Checklist

  • Changeset added (pnpm changeset) for any change to a published package, or the change is testbed, docs, or CI only.
  • Breaking change: not breaking. The contract changes are additive.
  • 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): the changeset lists @e2e-dev/core, e2e, @e2e-dev/web, @e2e-dev/mobile, and @e2e-dev/desktop.

https://github.com/user-attachments/assets/d79e9ca9-12f0-4d92-b2c8-83f04cd8c89d

https://github.com/user-attachments/assets/2dd2bf1e-34a1-472f-b7dd-e985866786fe