feat(core): scroll a container to an edge with scrollTo (ENG-1226)
What
screen.scrollTo(edge) and locator.scrollTo(edge) scroll a container to its top, bottom, left, or right edge, as far as the content goes, on the web engine and on iOS and Android devices.
await screen.scrollTo('bottom'); // the page, or an app shell's main pane
await screen.getByTestId('feed').scrollTo('top'); // a list, or the node's nearest scrolling ancestor
await screen.getByTestId('feed').scrollTo('bottom', { timeout: 60_000 });
It resolves at once when the container is already at the edge or nothing scrolls. When the timeout runs out it fails with ACTION_FAILED: scrollTo('bottom') did not reach the edge within <timeout>ms (<engine's reason>). The desktop engine does not declare the action, so it fails with UNSUPPORTED_CAPABILITY.
Why
Cypress cy.scrollTo('bottom'), Detox scrollTo('bottom'), and Appium UiScrollable.scrollToEnd() had no deterministic equivalent. The migration guides told users to loop swipe until allTextContents() stopped changing, or to call window.scrollTo through browser.evaluate. This adds the edge scroll as one action.
Left out on purpose:
- Positions such as
cy.scrollTo(0, 500): a device can neither read nor set a scroll offset. On the web it is onebrowser.evaluateline, which the Cypress guide shows. - Corners: they take two calls.
- A scroll by an offset: that is swipe
distance(#2178).
How it works
flowchart LR
A["screen.scrollTo / locator.scrollTo"] --> B["LocatorEngine.scrollTo"]
B -- screen --> C["TargetSession.rootRef, then perform on the root ref"]
B -- locator --> D["performUntil: perform on the node"]
C --> E{engine}
D --> E
E -- web --> F["jump to ±scrollHeight, read after a frame, again while the end moves"]
E -- mobile --> G["drag in the region, read, until a drag changes nothing"]
- Contract. A new
LocatorActionkind,{ kind: 'scrollTo', edge: ScrollEdge }(packages/core/src/engine/contract.ts:375). It joinsKNOWN_LOCATOR_ACTION_KINDS, not the SPI v1 list (:403), the wayblurandmultiTapdid.ENGINE_SPI_VERSIONstays 1, because a bump would rekey every committed recording.scrollTois added to the engine manifest schema's action enum, and both fixtures list it: the invalid one has a made-up kind beside it. Core 0.25.0 refuses an engine that declares an unknown kind, so the web and mobile engines now peer on@e2e-dev/coreande2e>=0.25.1 <1, as #1919 did forblur. - API.
ScreenImpl.scrollTo(packages/core/src/locator/screen.ts:324) checks the edge (:797), takes onlytimeout, and refuses a frame's screen: scrolling the root from inside a frame would scroll the screen around it.LocatorImpl.scrollTo(:628) labels the step<locator> → <edge>.ScrollEdgeis exported besideScrollDirection. - Dispatch.
LocatorEngine.scrollTo(packages/core/src/locator/engine.ts:575) runs both forms within one deadline.- Screen form. It takes the root ref from
TargetSession.rootRef, which observes first when no observation named it yet. It refuses to send once the deadline has passed, then performsscrollToon that ref. The perform gets only what is left of the deadline after the observe. - Locator form. It goes through
performUntil, which re-resolves a stale node. - Timeouts. A failure of the scroll itself (an engine timeout, or input that may have landed) becomes
did not reach the edge, with the engine's own message kept in parentheses, so a list still moving reads differently from a stuck device read. It names the step's timeout, not the time the engine took. The engines stop a little before the deadline, so this applies whether or not the deadline has passed. A locate or first observe that ran out, a stale retry's included, stays what it was:performUntiltakes aperformFailuremapper that sees only the perform's own failure. swipe. It had the same observe-then-perform pattern insession.ts, so when it has to observe first it now gets only the budget the observe left (leftSince), and sends nothing when the observe spent all of it. A root the session already knows gets the whole budget.
- Screen form. It takes the root ref from
- Web (
scrollToEdgeinpackages/web/src/scroll-to.ts). It waits for the node to be visible, then runs oneevaluateper jump, so nothing is left running in the page when a step is cancelled.- Container.
scrollContainerpicks the node, or its nearest ancestor that scrolls along the axis.- The walk goes through slots (a closed shadow root's slots through the closed-root registry), and through open and closed shadow roots.
- A body whose overflow belongs to the viewport counts as not scrolling, unless containment on the root or the body (any
containvalue, or any container type butscroll-state, which applies none) keeps the overflow its own. - On the screen it picks the page when the page scrolls, otherwise the container under the viewport's center, without entering an iframe there.
- It runs once, and the container is held by an element handle. A located row that unmounts while the list grows therefore does not lose it, and a jump, an
ElementHandle.evaluate, cannot end in a PlaywrightTimeoutError. - A start node no longer in the document fails as a retryable
NODE_STALEinstead of falling back to the page, and so does a container that left the page when its node cannot be found again. On the screen, a re-find that runs out is the budget, since the root can't leave the page. After a container left, no re-find starts with under 50 ms left, since no jump could follow it.
- Jump.
jumpOncesets the offset to ±scrollHeightwithbehavior: 'instant', soscroll-behavior: smoothis skipped and the sign covers right-to-left containers. - Settle. The edge is reached on a jump that moved nothing, with the extent and offset unchanged after the next rendered frame. Content an IntersectionObserver adds after that frame therefore gets another jump.
- A frame that renders nothing, such as a cross-origin iframe out of view, is read after 100 ms.
- Both waits use the native timers Playwright's clock keeps, as
nextRenderedFramedoes, so a paused page clock doesn't hold them. - Right before each jump it checks for a cancel and for at least 50 ms of budget, so a step cancelled or out of budget while the page was busy moves nothing.
- Out of budget. The reason names the cause: no jump fit the budget, more content kept loading at the edge, or the budget ended before a jump confirmed the edge.
- Wiring. The engine declares the action (
packages/web/src/engine.ts:141). It is dispatched fromactions.ts:398, and from the root branch insurface.ts:1273for the screen.classifyActionErrorpassesscrollTo's ownEngineErrorthrough rather than rewriting a timeout as generic input that may have landed, so core can quote the reason.
- Container.
- Mobile (
scrollToEdgeatpackages/mobile/src/surface.ts:1722, the loop indragToEdgeinpackages/mobile/src/scroll-to.ts:47). Each pass sends an inertialswipe, the same gestureswipeWithinbuilds for a node swipe, and agent-device holds the next read until the content rests.- Region. It is measured once, before the first drag: the node's box, or the screen for the root, clipped to the screen and cut off above the soft keyboard. It refuses, with nothing sent, a region with no area, a keyboard whose bounds are unknown, and window-local bounds (
scrollRegion,:1749). - Stop rule. It compares
regionSignature(role, name, text, value, test id, and rounded box of each node in the region, spinners left out) before and after each drag, and stops when a drag changed nothing.- A truncated or sparse capture never reads as unchanged. When no capture came back whole, the timeout says so.
- The timeout message counts the drags sent.
- No drag goes out once the step is cancelled.
- Drag count. A read costs more than a drag, so a pass sends 1, then 2, then up to 3 drags. No pass starts that the budget cannot finish, estimated from the last read plus the last time per drag times the next count, so the loop fails with its own reason rather than being cut off mid-pass.
- Gesture choice.
flingwas dropped because it holds at the end, which kills the inertia. - No-hidden-content flags. agent-device's "no hidden content" flags were not used: mid-list, Android reported
hiddenContentAbovealone, with rows below.
- Region. It is measured once, before the first drag: the node's box, or the screen for the root, clipped to the screen and cut off above the soft keyboard. It refuses, with nothing sent, a region with no area, a keyboard whose bounds are unknown, and window-local bounds (
- Desktop. The engine does not declare
scrollTo, so the harness refuses it before dispatch. agent-desktop gives no edge signal. - Docs.
reference/screen.mdxhas both methods, the per-engine behavior, and a throws table.reference/engine.mdx(kind table, contract excerpt, exports) andreference/mobile.mdx(perform row) list the new kind.desktop.mdxsays the desktop engine does not support it.- The Cypress, Detox, and Appium guides map their edge scroll to it. The Cypress guide's position example returns
null, so it type-checks. - The MCP
run_codemethod list mentions it. The e2e skill now points toreference/screen.mdxfor actions (#2309), so it needs no change. - A patch changeset covers
e2e,@e2e-dev/core,@e2e-dev/web,@e2e-dev/mobile, and@e2e-dev/desktop.
Known limits, documented in reference/screen.mdx:
- On a device the last drag runs past the edge, so
scrollTo('top')on a list with pull-to-refresh refreshes it. - Content that changes on its own inside the region (a timer, an auto-advancing carousel) keeps the device dragging until the timeout, so call it on the list.
- A device drag that lands on something that doesn't scroll reads as the edge.
Verified
Ran it locally: yes, on a Mac mini, against the built packages.
-
Android emulator (
pixel_api37, mobile benchmark, Huge Virtualized List of 600 rows):e2e run tests/scroll-to.e2e.ts --target android-emulator --video on, 2 of 2 passed. The existingtests/flows-lists.e2e.tspassed 7 of 7. -
iOS simulator (iPhone 17, iOS 27.2, same list): the same command with
--target ios-simulator, 2 of 2 passed. The last frame shows Row 0600.tests/flows-lists.e2e.tspassed 6 of 7. The one failure is the WebView coupon test, which calls no scroll API. It passes on CI's simulator, and #2178 records it failing on main on this one. -
Review fixes: every fix has a test that failed on the code before it, except the mobile cancel check, whose race sits in the surface. In the last three rounds, 17 new web tests and 2 new
e2eunit tests failed on the head before their fix and pass now.pnpm check, the web suite (1223 passed), thee2eunit suite (4994 passed), and the mobile suite (689 passed, last mobile change indf6d06fe) are green. The device runs are from an earlier round. On mobile, later rounds changed onlyscrollTopaths, and this round adds just the cancel check before a drag. -
Paused clock (testbed, a throwaway test calling
browser.clock.pauseAt, thenscreen.scrollTo('bottom', { timeout: 5_000 })on/scroll):4821c36failed withACTION_FAILED ... (scrollTo timed out)after the whole 5 s. This head resolves in 90 ms, at the bottom. -
Web (testbed):
e2e run tests/scroll.e2e.ts --video on, 6 of 6 passed. The two new tests scroll the page to its bottom and back while a scrollable pane sits under the viewport center, and scroll a node to its end while the page stays at 0. -
Timeout: a throwaway Android test with an 8 s timeout failed with the output below, captured before the message switched to naming the step's timeout. It now reads
within 8000ms.ACTION_FAILED: scrollTo('bottom') did not reach the edge within 7841ms (the content was still moving after 6 drags when the budget ran out)
| Step (head) | Android | iOS |
|---|---|---|
screen.scrollTo('bottom'), row 1 to row 600 | 20.2 s | 46.8 s |
screen.scrollTo('top'), back to row 1 | 20.4 s | 47.5 s |
locator.scrollTo('bottom') on the list | 23.8 s | 51.3 s |
locator.scrollTo('bottom') when already at the bottom | 0.8 s | 4.5 s |
Every pass waits for agent-device's post-gesture settle, which is slower on iOS. The docs suggest a longer timeout for a list this long.
pnpm bench:ab --suite testbed -- tests/scroll.e2e.ts: the existing tests behave the same and no step changed time. The wall-clock difference is the two added tests. "Uncommitted changes" is a local, untracked mobile-benchmark config this run doesn't read.
bench-ab: c3109278 (merge base with origin/main) vs 5636241b + uncommitted changes
apps/testbed: e2e run --workers 1 tests/scroll.e2e.ts. 6 pairs in random order, resolved after 6 pairs. Threshold ±5% and 10 ms. darwin arm64, Apple M4 x10, Node 26.13.1, load 3.2.
The suite's tests or config differ between base and head, so each side ran its own. A timing change can be the test change.
Behavior
These tests are left out of the timing rows below.
- added tests/scroll.e2e.ts › scrolling › scrollTo jumps the page to its bottom and back to its top (web)
- added tests/scroll.e2e.ts › scrolling › scrollTo on a node scrolls that node to its end and leaves the page where it was (web)
Timings
Every row but the process wall clock covers the 635 tests whose behavior matched.
| Metric | base median (IQR) | head median (IQR) | change (95% CI) | verdict |
|---|---|---|---|---|
| wall (process) | 7.02 s (6.94 s-7.06 s) | 9.36 s (9.30 s-9.44 s) | +33.2% (+31.6% to +36.7%) | slower |
| suite (sum of attempts) | 5.99 s (5.98 s-6.04 s) | 5.97 s (5.95 s-5.99 s) | -0.6% (-1.8% to +0.3%) | same |
| action (events) | 752 ms (740 ms-756 ms) | 748 ms (736 ms-751 ms) | -1.6% (-3.1% to +1.8%) | same |
| step expect.not.toHaveText | 4.03 s (4.03 s-4.03 s) | 4.03 s (4.03 s-4.03 s) | -0.0% (-0.1% to -0.0%) | same, under the floor |
| step screen.scrollUntilVisible | 1.13 s (1.12 s-1.13 s) | 1.14 s (1.13 s-1.15 s) | +1.0% (+0.1% to +1.9%) | same |
| step app.open | 215 ms (209 ms-225 ms) | 198 ms (195 ms-203 ms) | -7.2% (-24.6% to -2.9%) | unresolved |
| step locator.tap | 144 ms (143 ms-146 ms) | 133 ms (127 ms-135 ms) | -8.3% (-20.3% to -3.2%) | unresolved |
| step screen.swipe | 87 ms (81 ms-91 ms) | 90 ms (82 ms-94 ms) | +1.7% (-9.6% to +12.9%) | same, under the floor |
| step locator.swipe | 79 ms (77 ms-80 ms) | 76 ms (67 ms-78 ms) | -2.6% (-19.1% to +13.1%) | same, under the floor |
| step expect.toHaveText | 55 ms (54 ms-57 ms) | 57 ms (55 ms-58 ms) | +1.8% (-0.9% to +32.6%) | same, under the floor |
| step expect.toHaveCount | 38 ms (37 ms-39 ms) | 36 ms (36 ms-38 ms) | -4.0% (-7.7% to +2.7%) | same, under the floor |
| step browser.mouse.wheel | 2 ms (1 ms-2 ms) | 2 ms (1 ms-2 ms) | 0.0% (-64.6% to +41.4%) | same |
Counters
| Counter | base | head |
|---|---|---|
| attempts | 4 | 6 |
| events engine | 14 | 19 |
| events poll | 12 | 19 |
| steps | 24 | 38 |
| tests passed | 4 | 6 |
Tests outside the threshold: 0 of 635
With 635 tests compared at 95%, about 31.8 could land outside by chance.
Videos, in order: Android screen.scrollTo, Android locator.scrollTo, iOS screen.scrollTo, iOS locator.scrollTo, web screen.scrollTo, web locator.scrollTo.
Not verified: the desktop engine (it refuses the action), and left/right on a device, since the mobile benchmark has no horizontal list (both edges and right-to-left are covered on the web).
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.
- 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,@e2e-dev/mobile, and@e2e-dev/desktop.
Written by Claude Opus 5.5 in Claude Code (T3 Code). Gemini 4 Neon (Antigravity) critiqued the design and reviewed the code, a fresh-context Claude reviewer checked the diff before it was opened, and the review fixes answer kdy1's, okwasniewski's, and michal-e2e's reviews.
https://github.com/user-attachments/assets/b03fb104-844d-4d2c-b407-162e1756e293
https://github.com/user-attachments/assets/ff47b035-73b1-4b77-bae2-571332d6b14b
https://github.com/user-attachments/assets/d12247e5-faf3-4087-818b-1db1f495f496
https://github.com/user-attachments/assets/df87191a-cb79-434a-8b2a-33a6465b1520
https://github.com/user-attachments/assets/4a5993f9-bac3-4600-8b1b-ef4ff92cd88f
https://github.com/user-attachments/assets/6097b307-3a7e-4b7d-945e-85c0f661785e