feat(core): open a path in a freshly launched app with app.open(path, { relaunch: true }) (ENG-1490)
What
app.open(path, { relaunch: true }) starts the app fresh at a path in one call on both web and device targets.
await app.open('/orders/42', { relaunch: true });
- On a web target: closes open tabs, opens a new tab that keeps storage (as
app.restart()does), and opens the URL there without loading the base URL first. - On a device target with
app.linkBase: sets the target'sapp.permissionsfirst (as on any fresh launch), stops the pinned app if it is running, and launches the app from the link. On Android and a physical iOS device, it passes the target'sapp.launchArgumentswith the launch. - Throws
UNSUPPORTED_CAPABILITYwhen it cannot launch the app from the link: the engine does not declarelinkRelaunch, the device comes from a device provider, the target has no pinned app, an iOS simulator receives anhttp(s)link or launch arguments, or the device is an older iPhone thatxcrun devicectl list devicesdoes not list. On that iPhone, the app stops before the refusal and stays closed. - Throws
INVALID_ARGUMENTfor an unknown option or a non-booleanrelaunchvalue.
Why
Tests shared across web and device targets had no single call to start the app fresh at a path. On a device, app.open(path) opens the link in the running app and app.restart() starts the app without the link, so shared tests had to check for device and call device.closeApp() before opening the link. Web had no single call for this either.
How it works
flowchart LR
A["app.open(path, { relaunch: true })"] --> B{target}
B -- URL --> C[session.restart] --> D["session.open(url)"]
B -- device + linkBase --> E{engine declares linkRelaunch?}
E -- yes --> F["session.openLink(link, ctx, { relaunch: true })"]
E -- no --> G[UNSUPPORTED_CAPABILITY]
app.openrejects unknown option keys and non-booleanrelaunchvalues withINVALID_ARGUMENT, then branches by target (packages/core/src/run/fixtures.ts:751).- On a URL target,
navigateresolves the URL first so a forbidden scheme fails withPOLICY_DENIEDbefore anything restarts. Whenrelaunchis set, it callssession.restartand thensession.openwith the resolved URL, sharing oneDeadlineacross both calls (packages/core/src/run/fixtures.ts:674). - On a device target with
app.linkBase,launchPinnedApprejects engines that do not declarelinkRelaunch(fixtures.ts:721), then callssession.openLink(link, context, { relaunch: true })(fixtures.ts:728). - The engine contract adds
OpenLinkOptionsas a third argument toopenLink(packages/core/src/engine/index.ts:381,:412) and adds thelinkRelaunchcapability (index.ts:846).defineEngine(packages/core/src/engine/manifest.ts:311), the protocol manifest (packages/core/src/engine/protocol/manifest.ts:57), and theengine-manifest-1schema (packages/e2e/schema/engine-manifest-v1.schema.json:124,:427) all rejectlinkRelaunch: truewhensession.openLinkis absent, and both schema fixtures cover this rule.session/openLinknow accepts an optionaloptionsparam. WhenconnectEngine({ session: { openLink } })handlesopenLinklocally, the client drops the server'slinkRelaunchcapability (packages/core/src/engine/protocol/client.ts:246). - The mobile engine declares
linkRelaunch(packages/mobile/src/engine.ts:43) and routes relaunch calls tosurface.relaunchLink(engine.ts:76). Plain link opens withoutrelaunchbehave as before. - Before sending any device command,
relaunchLink(packages/mobile/src/surface.ts:1021) rejects devices from a provider, targets without a pinned app, and iOS simulator calls with anhttp(s)link or launch arguments. Revyl's driver starts the app first and then sendsopen_url, so the link reaches a running app. No other provider ran on a live device, sorelaunchLinkrejects every provider. On an iOS simulator, agent-device 0.21.44 launches the app first when given anhttp(s)link or launch arguments and then runssimctl openurlin the running app. - After those checks pass,
relaunchLinksets the target's permissions (surface.ts:1047) and calls agent-deviceapps.open({ app, url, relaunch: true, launchArgs })once (surface.ts:1054). On Android, this runs as oneam startwith the link, package, and arguments. On a physical iOS device, the CoreDevice backend launches the app with the URL and arguments. - agent-device's XCTest backend stops the app and then throws
UNSUPPORTED_OPERATIONwithbackend: 'xctest'. The engine cannot tell XCTest from CoreDevice before calling it because agent-device's client dropsiosPhysicalDeviceBackendwhen mapping a device, and boot,devices.list, anddevices.capabilitiesreturn no backend. Instead,relaunchLinkrethrows the XCTest error asUNSUPPORTED_CAPABILITYwith the next step and keeps the original error ascause(surface.ts:1068,packages/mobile/src/errors.ts:372). - The mobile benchmark sets
linkBase: 'e2e-benchmark://'on both targets (apps/mobile-benchmark/e2e.config.ts:62,:67). A device test launches the app from the link while it is running and again afterdevice.closeApp()(apps/mobile-benchmark/tests/device-fixture.e2e.ts:135). The replay cache keys onapp.identity, which both targets set, so the recordings do not change.
Putting relaunch on openLink behind a capability avoids a separate stop hook and rejects older engines instead of opening the link in the running app.
Issue
Part of ENG-1434.
Verified
Ran it locally: yes
The mobile benchmark Release build (built as in mobile.yml) ran on an iOS 27.2 simulator (iPhone 18 Pro). The test opens Control Inventory and launches the app from the /login-form link. Back then lands on the home list, showing a cold start. It then calls device.closeApp() and launches the app from the /login-form link again.
$ e2e run tests/device-fixture.e2e.ts --target ios-simulator --grep relaunch --video on
✓ |ios-simulator| tests/device-fixture.e2e.ts > device fixture > closeApp then openApp relaunches on the home list 10.69s
✓ |ios-simulator| tests/device-fixture.e2e.ts > device fixture > app.open with relaunch launches the app from the link whether running or stopped 17.40s
Tests 2 passed (2)
- The video shows the iOS simulator's "Open in "e2e Benchmark"?" prompt over the home screen after the app stops. The test accepts it with
device.alert('accept'). - CI's
mobilejob passed the test on both the Android emulator and the iOS simulator at87e0ee6. Compared with that commit, this head changes only messages, comments, test titles, and code layout. packages/e2e/tests/integration/web-platform.test.tscovers the web side in Chromium: after a relaunch,sessionStorageis empty,localStoragepersists, and the page shows the path.- Unit tests cover the iOS simulator rejections, launch arguments on Android and a physical iOS device, setting permissions before the launch, and the XCTest rejection. Because no physical iOS device was available, the CoreDevice and XCTest paths ran only in unit tests.
pnpm bench:ab on the web benchmark (smoke, login-form, filter-deep-link, control-inventory), merge base against this branch:
Every test ran the same steps with the same outcome on every run of both builds, and every counter matched.
| Metric | base median (IQR) | head median (IQR) | change (95% CI) | verdict |
|---|---|---|---|---|
| wall (process) | 5.75 s (5.64 s-5.84 s) | 5.66 s (5.59 s-5.80 s) | -1.3% (-2.5% to +0.8%) | same |
| suite (sum of attempts) | 4.77 s (4.67 s-4.81 s) | 4.68 s (4.58 s-4.77 s) | -1.3% (-3.5% to -0.5%) | same |
| action (events) | 3.06 s (3.01 s-3.08 s) | 3.01 s (2.97 s-3.04 s) | -0.5% (-3.6% to +0.1%) | same |
| step locator.longPress | 1.52 s (1.51 s-1.52 s) | 1.51 s (1.51 s-1.52 s) | -0.3% (-1.0% to +0.6%) | same, under the floor |
| step app.open | 1.15 s (1.13 s-1.17 s) | 1.13 s (1.08 s-1.14 s) | -2.0% (-3.6% to -0.6%) | same |
| step locator.tap | 588 ms (573 ms-629 ms) | 591 ms (585 ms-596 ms) | -0.0% (-11.8% to +5.2%) | same, under the floor |
| step locator.check | 342 ms (325 ms-359 ms) | 343 ms (320 ms-356 ms) | -2.9% (-9.3% to +6.9%) | same, under the floor |
| step locator.fill | 260 ms (255 ms-261 ms) | 237 ms (230 ms-250 ms) | -6.5% (-14.6% to +0.4%) | unresolved |
| step expect.toHaveText | 120 ms (111 ms-124 ms) | 119 ms (113 ms-121 ms) | -2.8% (-21.4% to +3.5%) | same, under the floor |
| step locator.secondaryTap | 78 ms (67 ms-78 ms) | 79 ms (76 ms-79 ms) | +0.6% (-2.7% to +17.4%) | same, under the floor |
| step locator.doubleTap | 70 ms (60 ms-78 ms) | 70 ms (61 ms-79 ms) | +1.1% (-3.7% to +8.7%) | same, under the floor |
| step locator.scrollIntoView | 66 ms (65 ms-67 ms) | 67 ms (65 ms-69 ms) | +1.5% (-2.4% to +3.7%) | same, under the floor |
| step locator.setInputFiles | 65 ms (63 ms-68 ms) | 68 ms (64 ms-69 ms) | +1.5% (-1.5% to +6.2%) | same, under the floor |
| step locator.uncheck | 46 ms (45 ms-47 ms) | 46 ms (45 ms-47 ms) | +1.1% (-3.2% to +2.2%) | same, under the floor |
| step expect.toHaveURL | 41 ms (41 ms-42 ms) | 43 ms (43 ms-44 ms) | +3.6% (0.0% to +8.5%) | same, under the floor |
| step expect.toBeVisible | 33 ms (32 ms-35 ms) | 29 ms (27 ms-32 ms) | -3.5% (-25.6% to -1.5%) | same, under the floor |
| step expect.toHaveValue | 19 ms (18 ms-19 ms) | 18 ms (17 ms-18 ms) | -5.3% (-7.8% to +5.4%) | same, under the floor |
| step app.back | 17 ms (16 ms-18 ms) | 17 ms (17 ms-17 ms) | 0.0% (-7.8% to +6.5%) | same |
| step expect.toBeChecked | 3 ms (3 ms-5 ms) | 3 ms (3 ms-5 ms) | 0.0% (-29.3% to +41.4%) | same |
| step expect.toHaveTitle | 2 ms (2 ms-3 ms) | 2 ms (2 ms-2 ms) | 0.0% (-48.4% to +22.5%) | same |
| Evidence | |
|---|---|
| Video of the device test | iOS recording from e2e run --video on, attached below |
| Docs screenshots | Not captured. The pages render on e2e.com from another repository. pnpm docs:check passes |
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.