feat(web): emulate a touchscreen with web({ hasTouch: true })
What
web({ hasTouch: true }) emulates a touchscreen on a web target. A single tap() on a node or at a point sends touchstart and touchend before the browser fires click. click() stays a mouse click that waits for navigation, as in Playwright. hasTouch is off by default.
targets: [{ name: 'web', engine: web({ hasTouch: true }), app: { url } }]
await screen.getByRole('button', 'Go').tap(); // sends touchstart and touchend
await screen.tapAt({ x: 40, y: 30 }); // sends the same events at viewport coordinates
await screen.getByRole('link', 'Next').click(); // a mouse click that waits for the next page
Why
Web targets sent taps as mouse clicks, so tests could miss bugs in an app's touch handlers.
How it works
web()throwsINVALID_CONFIGwhenhasTouchisn't a boolean, naming the received type (packages/web/src/engine.ts:100). LikeuserAgent,hasTouch: truethrowsINVALID_CONFIGwithconnect.reconnectEndpointor an attempt-scoped browser provider, because it applies only when a context is created.hasTouch: falseis accepted there (packages/web/src/engine.ts:116,:212).- Every context the engine creates gets the option, including contexts from
app.clearState()and session state restores (packages/web/src/surface.ts:618). - Core still dispatches
click()as atap, and marks it with an optionalclick: true(packages/core/src/locator/screen.ts:429,:431,:446).clickis on the single-tapLocatorActionandPointerActionforms (packages/core/src/engine/contract.ts:323,:412) and crosses JSON-RPC as is. Other engines still treat the action as a tap. A new kind would have made every engine declare it. - A single tap on a node goes through Playwright's
tap()instead ofclick(), unless it carriesclick: true. That includes a tap through a checkbox's label and a tap with held modifiers (packages/web/src/actions.ts:292,:173,:208). - A
tapat a point goes throughpage.touchscreen.tap, unless it carriesclick: true(packages/web/src/actions.ts:417). - A swipe on a node skips the
:hovershortcut when touch is on (packages/web/src/support.ts:611, passed frompackages/web/src/actions.ts:394). A touch tap leaves:hoveron the tapped node without moving Playwright's mouse, so the wheel would land at the old mouse position instead of the node. - Every other action is unchanged.
click(),tap({ count })above 1, double taps, long presses,check(),uncheck(), drags, andscreen.swipestill use the mouse, with or withouthasTouch. - A touch tap doesn't wait for a navigation it starts. It leaves the mouse pointer where it was. Both caveats and the
toHaveURLlink are in thehasTouchreference entry.
Issue
Part of #1374 and ENG-1022. Touch gestures beyond taps are left for later.
Verified
Ran it locally: yes.
- Built CLI on the testbed
/pointerpage, with targetsweb({ hasTouch: true })andweb(). The test callstap(),click(), andscreen.tapAt(), and logs the events the page received after each:
|chromium-touch|
tap(): touchstart,touchend,mousedown,click
click(): mousedown,click
screen.tapAt(): touchstart,touchend,mousedown,click
|chromium-default|
tap(): mousedown,click
click(): mousedown,click
screen.tapAt(): mousedown,click
- Firefox, from an earlier head that covered a locator tap and a point tap only, with
web({ browser: 'firefox', hasTouch: true })andweb({ browser: 'firefox' }):
|firefox-touch| a locator tap and a point tap
events: touchstart,touchend,mousedown,click,touchstart,touchend,mousedown,click
|firefox-default| a locator tap and a point tap
events: mousedown,click,mousedown,click
Firefox doesn't launch on this machine, so click() under hasTouch hasn't run there.
-
In Chromium,
packages/web/tests/integration/touch.test.tscovers: a node tap, a tap through a checkbox's label, a tap with Shift held, a point tap, a tap after the context is replaced, a list swipe after a tap inside the list,click()on a node and at a point (mouse events only),click()waiting for a navigation to a page that answers after 400 ms, and a plain click withhasTouchleft out. The navigation test fails when the tap goes through the touchscreen. The list swipe test fails without the fix in step 6. On an earlier head, the original 6 tests passed in Firefox 159 with the surface switched tobrowser: 'firefox'. The tests added since haven't run in Firefox. -
packages/e2e/tests/unit/engine-protocol.test.tschecks thatclick: truecrosses JSON-RPC inperformandperformAt.packages/e2e/tests/types/sdk-types.tspins it astrue | undefined. -
pnpm bench:abon the testbed pointer tests, the defaulthasTouch: falsepath:Behavior and counters match on every run. The timings are unresolved, since the machine's load was 44 during the run.
bench-ab: c371f78c (merge base with origin/main) vs 9468d06d
apps/testbed: e2e run --workers 1 tests/pointer.e2e.ts. 8 pairs in random order, stopped at the 8-pair budget, unresolved. Threshold ±5% and 10 ms. darwin arm64, Apple M5 Pro x18, Node 24.22.1, load 44.1.
Behavior
Every test ran the same steps with the same outcome on every run of both builds.
Timings
| Metric | base median (IQR) | head median (IQR) | change (95% CI) | verdict |
|---|---|---|---|---|
| wall (process) | 2.91 s (2.82 s-3.34 s) | 2.83 s (2.77 s-3.13 s) | -0.8% (-6.7% to +5.9%) | unresolved |
| suite (sum of attempts) | 1.96 s (1.94 s-2.17 s) | 1.98 s (1.91 s-2.03 s) | -1.7% (-7.4% to +6.3%) | unresolved |
| action (events) | 1.06 s (1.03 s-1.08 s) | 1.05 s (1.03 s-1.06 s) | -1.4% (-3.9% to +3.2%) | same |
| step locator.tap | 831 ms (820 ms-840 ms) | 836 ms (824 ms-838 ms) | +0.1% (-0.2% to +1.0%) | same, under the floor |
| step app.open | 452 ms (435 ms-495 ms) | 438 ms (421 ms-473 ms) | -2.2% (-15.0% to +9.7%) | same, under the floor |
| step screen.swipe | 136 ms (125 ms-144 ms) | 126 ms (108 ms-134 ms) | -7.3% (-20.0% to +9.8%) | unresolved |
| step locator.click | 46 ms (42 ms-46 ms) | 43 ms (43 ms-45 ms) | -4.3% (-8.7% to +2.4%) | same, under the floor |
| step screen.tapAt | 32 ms (30 ms-36 ms) | 31 ms (30 ms-31 ms) | -3.2% (-13.9% to +17.8%) | same, under the floor |
| step expect.toHaveText | 30 ms (28 ms-35 ms) | 30 ms (27 ms-31 ms) | -2.2% (-22.6% to +30.9%) | same, under the floor |
| step locator.fill | 28 ms (26 ms-30 ms) | 28 ms (26 ms-31 ms) | +3.3% (-17.2% to +20.8%) | same, under the floor |
| step browser.mouse.move | 18 ms (17 ms-21 ms) | 20 ms (18 ms-31 ms) | -3.0% (-15.6% to +72.2%) | same, under the floor |
| step screen.doubleTapAt | 8 ms (8 ms-8 ms) | 8 ms (8 ms-10 ms) | +6.9% (0.0% to +37.5%) | same, under the floor |
| step browser.evaluate | 4 ms (3 ms-4 ms) | 4 ms (4 ms-5 ms) | +26.5% (-13.4% to +66.7%) | same, under the floor |
| step expect.toHaveValue | 3 ms (2 ms-3 ms) | 2 ms (2 ms-2 ms) | -18.4% (-65.2% to +33.3%) | same, under the floor |
| step browser.mouse.down | 1 ms (1 ms-1 ms) | 1 ms (1 ms-1 ms) | 0.0% (0.0% to 0.0%) | same |
| step browser.mouse.up | 1 ms (1 ms-1 ms) | 1 ms (1 ms-1 ms) | 0.0% (0.0% to 0.0%) | same |
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.
- Video: the
chromium-touchrun, attached below. - Docs screenshots: not captured. The repo doesn't have a local docs preview, so the changed
reference/web.mdxentry was checked withpnpm docs:checkonly.
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.
https://github.com/user-attachments/assets/1551ed1e-9950-4634-9f2b-0ef51206044a