feat(core): open a file on disk as the app with a file: app.url

Merged
OK
1d ago
+912-47

What

app.url takes a file: URL: one file on this machine, which a browser the engine launches opens with no server.

import { pathToFileURL } from 'node:url';

app: { url: pathToFileURL('dist/index.html').href },
  • app.open('pages/about.html'), browser.goto, and the agent's navigate reach files in that file's directory or below it. A file outside it and any directory are POLICY_DENIED.
  • Every file: URL stays POLICY_DENIED on a target whose app is not a file.
  • When a link or a script in the page takes the browser outside the directory, no agent observation, trace screen, or failure screen text is taken there.
  • No screenshot of a file app is sent to a model or kept on its own: agent.assert with vision: true judges from the tree, vision: 'only' is POLICY_DENIED before any model call, and neither agent.assert nor a failure keeps a screenshot.
  • A video the user turns on still records wherever the browser goes; the docs say so.
  • A host or a directory in app.url is INVALID_APP_URL. A web() target with a browser provider, connect, headers, or basicAuth refuses a file app with INVALID_CONFIG.
  • An engine opens a file app only when it declares fileApps: true (@e2e-dev/core/engine). web() does; any other engine fails a file app.url at config load.

Why

A page that exists only as a file (a build output, a generated report, a scratch page in /tmp) needed a throwaway HTTP server in front of it before @e2e-dev/core or a test could open it: launch(web(), { app: { url: 'file:///tmp/page.html' } }) failed with INVALID_APP_URL.

file: was refused on purpose. The navigation rule in AGENTS.md is a security invariant: the agent names navigation URLs, a page can tell it to, and a file: URL reads local content. This PR changes that invariant, so it needs an owner's decision, not only a code review. It opens file: only as far as the app's own directory, and adds a second check for the one thing a file page can do that an http(s) page cannot: go to another local file by itself.

How it works

flowchart LR
  A[app.open / browser.goto / agent navigate] --> B{resolveNavigationUrl}
  B -- http, https, about:blank --> O[open]
  B -- "file: and the app is a file" --> S{fileScope}
  B -- anything else --> D[POLICY_DENIED]
  S -- inside --> O
  S -- outside or directory --> D
  P[link or script in the page] --> N[browser navigates]
  N --> C{leftFileApp at every sink}
  C -- inside --> M[model tree, trace screen, failure evidence]
  C -- outside or directory --> W[screen withheld, location kept]
  1. The scheme is read once, in core. namesFile (packages/core/src/internal/urls.ts:90) uses the same withScheme reading as normalizeBaseUrl, so file:8443/report stays the host file on port 8443. checkTargetApp (packages/core/src/config/app.ts:169) refuses a file app for an engine whose handle does not declare fileApps, and tells the engine's validateApp with fileApp: true. The flag travels in the engine manifest like launchArgumentValues (engine/manifest.ts, engine/protocol/, engine-manifest-v1.schema.json and its valid fixture).
  2. normalizeBaseUrl hands a file: URL to fileBase (urls.ts:66): no host, and fileScope must say inside, which refuses a directory even without its trailing slash. The base gets the origin file:// (:82), not URL.origin's null, which every data: and blob: URL shares.
  3. fileScope (:144) decides where a file: URL lies for a file app: inside, directory, or outside. It compares paths decoded by fileURLToPath, which refuses an encoded separator, and resolved by realPath (:119), so a symbolic link in the directory does not lead out. A path that cannot be resolved (a NUL, a name too long, an unsearchable directory) is outside.
  4. resolveNavigationUrl admits a file: URL only when the app is a file and fileScope says inside (:303). It is still the one rule behind app.open, browser.goto, and navigate. The base URL itself goes through it at app.open(), app.restart(), and app.clearState() (packages/core/src/run/fixtures.ts:630, :647), since the file may have become a directory after the config loaded.
  5. leftFileApp (:179) applies the same bound to where the page is, for every sink that keeps or sends a screen on its own. A browser lets a file page link or script its way to any local file, where an http(s) page cannot.
    • A model's observation throws POLICY_DENIED: the act loop's (packages/core/src/agent/observation-feed.ts:464) and a judgment's (packages/core/src/agent/invocation.ts:241).
    • traceScreen keeps no step screen (packages/core/src/run/step-screens.ts:124).
    • Failure evidence keeps the location and nothing else: no screen text, no screenshot (packages/e2e/src/run/failure-evidence.ts:79).
  6. A model is sent no pixels of a file app: pixelsAllowed is false there (packages/core/src/agent/act.ts:247, invocation.ts:235). A local page can embed another file in a frame, which the tree leaves out and pixels would show, and nothing can place those pixels. A judgment does not ask the engine for pixels either, and vision: 'only' throws before the capture (invocation.ts, observe). The automatic screenshots are second captures nothing places, so a file app gets none: both captureEvidence of agent.assert (agent/act.ts, agent/index.ts) and the failure screenshot (failure-evidence.ts).
  7. resolveTargetApp gives a file app no site, no engine origin, no port, environment test, and its href as identity (config/app.ts:273). An app.command beside it needs app.readyUrl, since a file answers no poll. The report leaves baseOrigin out (packages/e2e/src/report/build.ts:647).
  8. The web engine declares fileApps (packages/web/src/engine.ts:124), and validateFileApp (:534) refuses a provider and connect: the checks above run against the runner's disk, and those browsers may read another. It refuses headers and basicAuth, which always go to the app's origin.

What is left open, for the owner to accept or not:

  • The directory is the readable scope. index.html in a project root puts .env and .git in reach of the agent's navigate. The docs say to keep the file in a folder of its own. An explicit root option, or refusing dot-files, would be stricter.
  • No vision on a file app. Chosen as the safe side of the pixel question; it costs vision steps on local pages. Loosening it needs a way to prove every frame in the screenshot is inside the directory.
  • Video is not gated. A recording the user turned on shows the page outside the directory. security.mdx and SECURITY.md name it; refusing video on a file app is the stricter choice.
  • A served web() declares fileApps too. Over the engine protocol from another machine it would open that machine's file while the harness checks this disk.
  • e2e mcp session tools are not gated on pixels; that agent already has test authority through run_code.
  • Release order. web() passes fileApps to defineEngine, which an older core rejects as an unknown key, so this must ship in the release the engines' core peer floor names (0.25.0).
  • Test code is not gated at the document. After a page-initiated navigation outside the directory, a test's own textContent(), screen.tree(), or app.screenshot() still reads.
  • Recordings are tied to the absolute path. A file app's location and default identity hold the file's absolute path, so an agent.act recording replays only where the file sits at that path.

Dropped: allowing a directory as the app (file:///site/). A browser lists a directory with a link to its parent, which is a walk to every file the user can read.

Engine contract: Engine.fileApps and EngineAppCheckInfo.fileApp are new and optional, so the changeset bumps @e2e-dev/core, e2e, and every engine. mobile() and desktop() do not declare it.

Docs: "A file as the app" in docs/reference/config.mdx, the denied and navigation tables in docs/reference/security.mdx, SECURITY.md, docs/reference/errors.mdx, docs/reference/app.mdx, docs/reference/web.mdx, docs/reference/engine.mdx, docs/reference/engine-protocol.mdx, one sentence in docs/web.mdx, the invariant in AGENTS.md, and skills/e2e/references/debugging.md with its plugin copy.

Issue

None. Requested by a maintainer.

Verified

Ran it locally: yes

  • A @e2e-dev/core script on the built packages, against a page in /tmp with a sibling page, a file one level up, and a symbolic link to /etc:
app.open()                        -> file:///tmp/e2e-prs/pr3/site/index.html
heading visible                   -> true
app.screenshot()                  -> screenshots/001-file-app.png
app.open('pages/about.html')      -> file:///tmp/e2e-prs/pr3/site/pages/about.html
tap the Back link                 -> file:///tmp/e2e-prs/pr3/site/index.html
app.open('../secret.html')         -> POLICY_DENIED | file navigation stays in the directory of the app's file: file:///tmp/e2e-prs/pr3/secret.html is outside it
app.open('/etc/hosts')             -> POLICY_DENIED | file navigation stays in the directory of the app's file: file:///etc/hosts is outside it
browser.goto('file:///etc/hosts')  -> POLICY_DENIED | file navigation stays in the directory of the app's file: file:///etc/hosts is outside it
app.open('pages')                  -> POLICY_DENIED | file navigation opens a file, not a directory: file:///tmp/e2e-prs/pr3/site/pages
app.open('..%2fsecret.html')       -> POLICY_DENIED | file navigation stays in the directory of the app's file: file:///tmp/e2e-prs/pr3/site/..%2fsecret.html is outside it
app.open('etc-link/hosts') symlink -> POLICY_DENIED | file navigation stays in the directory of the app's file: file:///tmp/e2e-prs/pr3/site/etc-link/hosts is outside it
file:///tmp/e2e-prs/pr3/site/ -> INVALID_APP_URL | a file app URL names one file this machine can reach, not a directory, such as file:///path/to/index.html: fil
file://fileserver/share/index.html -> INVALID_APP_URL | a file app URL names a file on this machine, with no host, such as file:///path/to/index.html: file://fileserv
<the file> -> INVALID_CONFIG | target "web" opens a file app.url, and web({ connect }) attaches to a browser that may run on another machine,
<the file> -> INVALID_CONFIG | target "web" opens a file app.url, and web({ headers }) always goes to the app's origin, which a file does not

the file app

  • packages/e2e/tests/integration/file-app.test.ts, the runner with real Chromium:
    • a test opens the file and a page beside it; app.open and browser.goto are refused outside the directory under five spellings, and on a directory;
    • a test taps the page's own link to a file outside and then fails: the attempt's failure holds the location only, it has no screenshot artifact, and no file under .e2e holds that file's text;
    • with a scripted model, a screenshot call returns no image, navigate('../secret.html') returns the refusal, and after a tap on the page's link the next screen is withheld. No request to the model holds the file's text or an image.
    • agent.assert on a file app with a scripted judge: no image with vision: true, POLICY_DENIED and no model call with vision: 'only', no screenshot artifact. With a custom executor after the page left the directory: the observation is refused and no screenshot is kept. A failure inside the directory keeps the screen text and no screenshot. All six are red with the fix reverted.
    • report.json has no baseOrigin for the file target.
  • engine-protocol.test.ts: a server that does not announce the fileApps its manifest declares is refused at the handshake; a non-boolean flag is refused by defineEngine. schema-fixtures.test.ts: the invalid fixture fails at /fileApps and /methods.
  • packages/e2e/tests/unit/file-app-config.test.ts: an engine without fileApps is refused, the engine is told fileApp by core's reading, and file:8443/report with web({ headers }) resolves as https://file:8443/report, as on main.
  • packages/e2e/tests/unit/urls.test.ts: the base (host, directory, query, fragment), navigation inside, 13 ways out (dot segments, %2e, %2f, absolute paths, another host, links to a directory and to a file, a NUL, a 300-character name), directories, wrapper schemes, the observed-location check, and file: still denied on an http target.
  • On the published 0.24.0 packages the same launch fails with INVALID_APP_URL.
  • pnpm check passes at 05adbc08e2. pnpm test passed for every package but @e2e-dev/desktop, whose suite hung on this machine and was stopped; CI runs it.
  • Not run: Firefox and WebKit on a file app, and Windows paths.

bench-ab, from the first revision: 95f80b8b (its merge base) vs c6bf01b3 (since rebased away)

Not rerun for the later commits, which touch only file apps.

apps/testbed: e2e run --workers 1 tests/forms.e2e.ts. 12 pairs in random order, resolved after 12 pairs. Threshold ±3% and 10 ms. darwin arm64, Apple M5 Pro x15, Node 24.19.0, load 5.7.

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)2.63 s (2.58 s-2.69 s)2.59 s (2.55 s-2.65 s)-1.4% (-4.0% to +0.6%)unresolved
suite (sum of attempts)1.87 s (1.84 s-1.89 s)1.84 s (1.83 s-1.87 s)-1.0% (-3.0% to +1.3%)same
action (events)352 ms (341 ms-374 ms)344 ms (328 ms-352 ms)-1.2% (-9.6% to +0.9%)same, under the floor
step expect.not.toBeChecked1.00 s (1.00 s-1.00 s)1.00 s (1.00 s-1.00 s)+0.1% (-0.1% to +0.1%)same, under the floor
step app.open203 ms (196 ms-207 ms)198 ms (194 ms-203 ms)-1.5% (-3.4% to +1.3%)same, under the floor
step locator.fill165 ms (158 ms-171 ms)162 ms (155 ms-164 ms)-4.6% (-6.8% to +1.5%)same, under the floor
step locator.tap68 ms (65 ms-73 ms)66 ms (57 ms-70 ms)-0.8% (-16.3% to +5.2%)same, under the floor
step locator.pressSequentially45 ms (43 ms-49 ms)42 ms (41 ms-43 ms)-6.5% (-15.3% to 0.0%)same, under the floor
step locator.check40 ms (37 ms-45 ms)43 ms (38 ms-45 ms)-1.6% (-8.9% to +18.3%)same, under the floor
step locator.uncheck32 ms (31 ms-37 ms)32 ms (31 ms-36 ms)0.0% (-3.3% to +3.2%)same
step locator.selectOption20 ms (18 ms-22 ms)18 ms (17 ms-19 ms)-9.1% (-21.9% to +2.7%)same, under the floor
step locator.clear19 ms (17 ms-21 ms)17 ms (17 ms-18 ms)-7.8% (-18.4% to +2.9%)same, under the floor
step expect.toBeVisible18 ms (17 ms-19 ms)17 ms (17 ms-17 ms)-2.8% (-10.5% to 0.0%)same, under the floor
step expect.toHaveValue9 ms (8 ms-10 ms)8 ms (7 ms-9 ms)-14.7% (-33.3% to 0.0%)same, under the floor
step expect.toHaveCount6 ms (6 ms-7 ms)6 ms (5 ms-6 ms)-14.3% (-16.7% to 0.0%)same, under the floor
step expect.toHaveText4 ms (4 ms-5 ms)5 ms (3 ms-5 ms)0.0% (-18.4% to +36.9%)same
step expect.toBeChecked2 ms (2 ms-3 ms)2 ms (2 ms-2 ms)0.0% (-33.3% to 0.0%)same

Counters

Every counter matched on every run of both builds.

Tests outside the threshold: 0 of 606

With 606 tests compared at 95%, about 30.3 could land outside by chance.

  • Docs pages: not rendered. The edits are text and table rows.

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.