feat(core): open a file on disk as the app with a file: app.url
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'snavigatereach files in that file's directory or below it. A file outside it and any directory arePOLICY_DENIED.- Every
file:URL staysPOLICY_DENIEDon 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.assertwithvision: truejudges from the tree,vision: 'only'isPOLICY_DENIEDbefore any model call, and neitheragent.assertnor a failure keeps a screenshot. - A
videothe user turns on still records wherever the browser goes; the docs say so. - A host or a directory in
app.urlisINVALID_APP_URL. Aweb()target with a browser provider,connect,headers, orbasicAuthrefuses a file app withINVALID_CONFIG. - An engine opens a file app only when it declares
fileApps: true(@e2e-dev/core/engine).web()does; any other engine fails a fileapp.urlat 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]
- The scheme is read once, in core.
namesFile(packages/core/src/internal/urls.ts:90) uses the samewithSchemereading asnormalizeBaseUrl, sofile:8443/reportstays the hostfileon port 8443.checkTargetApp(packages/core/src/config/app.ts:169) refuses a file app for an engine whose handle does not declarefileApps, and tells the engine'svalidateAppwithfileApp: true. The flag travels in the engine manifest likelaunchArgumentValues(engine/manifest.ts,engine/protocol/,engine-manifest-v1.schema.jsonand its valid fixture). normalizeBaseUrlhands afile:URL tofileBase(urls.ts:66): no host, andfileScopemust sayinside, which refuses a directory even without its trailing slash. The base gets the originfile://(:82), notURL.origin'snull, which everydata:andblob:URL shares.fileScope(:144) decides where afile:URL lies for a file app:inside,directory, oroutside. It compares paths decoded byfileURLToPath, which refuses an encoded separator, and resolved byrealPath(: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) isoutside.resolveNavigationUrladmits afile:URL only when the app is a file andfileScopesaysinside(:303). It is still the one rule behindapp.open,browser.goto, andnavigate. The base URL itself goes through it atapp.open(),app.restart(), andapp.clearState()(packages/core/src/run/fixtures.ts:630,:647), since the file may have become a directory after the config loaded.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). traceScreenkeeps 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).
- A model's observation throws
- A model is sent no pixels of a file app:
pixelsAllowedis 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, andvision: 'only'throws before the capture (invocation.ts,observe). The automatic screenshots are second captures nothing places, so a file app gets none: bothcaptureEvidenceofagent.assert(agent/act.ts,agent/index.ts) and the failure screenshot (failure-evidence.ts). resolveTargetAppgives a file app no site, no engine origin, no port, environmenttest, and itshrefas identity (config/app.ts:273). Anapp.commandbeside it needsapp.readyUrl, since a file answers no poll. The report leavesbaseOriginout (packages/e2e/src/report/build.ts:647).- The web engine declares
fileApps(packages/web/src/engine.ts:124), andvalidateFileApp(:534) refuses a provider andconnect: the checks above run against the runner's disk, and those browsers may read another. It refusesheadersandbasicAuth, 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.htmlin a project root puts.envand.gitin reach of the agent'snavigate. 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
visionsteps 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.mdxandSECURITY.mdname it; refusingvideoon a file app is the stricter choice. - A served
web()declaresfileAppstoo. Over the engine protocol from another machine it would open that machine's file while the harness checks this disk. e2e mcpsession tools are not gated on pixels; that agent already has test authority throughrun_code.- Release order.
web()passesfileAppstodefineEngine, 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(), orapp.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.actrecording 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/corescript on the built packages, against a page in/tmpwith 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
packages/e2e/tests/integration/file-app.test.ts, the runner with real Chromium:- a test opens the file and a page beside it;
app.openandbrowser.gotoare 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
.e2eholds that file's text; - with a scripted model, a
screenshotcall 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.asserton a file app with a scripted judge: no image withvision: true,POLICY_DENIEDand no model call withvision: '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.jsonhas nobaseOriginfor the file target.
- a test opens the file and a page beside it;
engine-protocol.test.ts: a server that does not announce thefileAppsits manifest declares is refused at the handshake; a non-boolean flag is refused bydefineEngine.schema-fixtures.test.ts: the invalid fixture fails at/fileAppsand/methods.packages/e2e/tests/unit/file-app-config.test.ts: an engine withoutfileAppsis refused, the engine is toldfileAppby core's reading, andfile:8443/reportwithweb({ headers })resolves ashttps://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, andfile:still denied on an http target.- On the published 0.24.0 packages the same
launchfails withINVALID_APP_URL. pnpm checkpasses at05adbc08e2.pnpm testpassed 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
| Metric | base 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.toBeChecked | 1.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.open | 203 ms (196 ms-207 ms) | 198 ms (194 ms-203 ms) | -1.5% (-3.4% to +1.3%) | same, under the floor |
| step locator.fill | 165 ms (158 ms-171 ms) | 162 ms (155 ms-164 ms) | -4.6% (-6.8% to +1.5%) | same, under the floor |
| step locator.tap | 68 ms (65 ms-73 ms) | 66 ms (57 ms-70 ms) | -0.8% (-16.3% to +5.2%) | same, under the floor |
| step locator.pressSequentially | 45 ms (43 ms-49 ms) | 42 ms (41 ms-43 ms) | -6.5% (-15.3% to 0.0%) | same, under the floor |
| step locator.check | 40 ms (37 ms-45 ms) | 43 ms (38 ms-45 ms) | -1.6% (-8.9% to +18.3%) | same, under the floor |
| step locator.uncheck | 32 ms (31 ms-37 ms) | 32 ms (31 ms-36 ms) | 0.0% (-3.3% to +3.2%) | same |
| step locator.selectOption | 20 ms (18 ms-22 ms) | 18 ms (17 ms-19 ms) | -9.1% (-21.9% to +2.7%) | same, under the floor |
| step locator.clear | 19 ms (17 ms-21 ms) | 17 ms (17 ms-18 ms) | -7.8% (-18.4% to +2.9%) | same, under the floor |
| step expect.toBeVisible | 18 ms (17 ms-19 ms) | 17 ms (17 ms-17 ms) | -2.8% (-10.5% to 0.0%) | same, under the floor |
| step expect.toHaveValue | 9 ms (8 ms-10 ms) | 8 ms (7 ms-9 ms) | -14.7% (-33.3% to 0.0%) | same, under the floor |
| step expect.toHaveCount | 6 ms (6 ms-7 ms) | 6 ms (5 ms-6 ms) | -14.3% (-16.7% to 0.0%) | same, under the floor |
| step expect.toHaveText | 4 ms (4 ms-5 ms) | 5 ms (3 ms-5 ms) | 0.0% (-18.4% to +36.9%) | same |
| step expect.toBeChecked | 2 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/**/*.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.