Skip to main content

Module browser

Module browser 

Source
Expand description

A real browser as a page tier: headless Chrome, driven over the DevTools protocol.

Browser::launch starts Chrome with --remote-debugging-pipe — the protocol travels over two pipes the harness owns, so no port is opened and nothing else can attach. Browser::open serves a PageBundle from a loopback HTTP server and loads it in a fresh target inside a browser context of its own (no cookies, storage or cache shared with any other page), then returns a Page once the page’s module has run main and committed its first paint.

What a Page offers is the whole driving surface a page tier needs:

  • real input — Page::click, Page::type_into, Page::press dispatch trusted mouse and keyboard events through the browser’s input pipeline, so default actions (a submit button submitting, Enter submitting a form) happen exactly as they do for a visitor; Page::choose and Page::submit use the DOM’s own change/requestSubmit paths;
  • Page::snapshot — the document as a canonical tree, title, URL and focused element;
  • Page::import_trace — every host import the module called and every export the host called, in order, recorded by wrapping WebAssembly.instantiate (the page’s own runtime is untouched);
  • Page::advance — the page’s clock under virtual time: paused from the moment the page is ready, moving only when a test moves it;
  • Page::answer — network stubs: every request outside the bundle is intercepted, answered when a stub matches and otherwise HELD, so an unanswered request stays pending as it would on a network that has not replied;
  • navigation — a document the page asks the browser for (a link it follows, a form it submits, a location it assigns) is let in only once the document that asked has reported everything it will, and every act, settle and read is made in the document the page came to rest in, never in one half-replaced;
  • Page::eval — anything else, as JavaScript.

One browser serves a whole test binary (shared); every Page is its own target and is closed when dropped. Every wait has a deadline and fails loudly, naming what it waited for.

Structs§

Answer
An answer for a request the page may make: method path answered with status, a content-type and body. path is relative to the page’s origin (/api/todo) or a full URL for another origin.
Browser
A running headless Chrome.
ChromeLauncher
Launches a page in the shared, process-wide Chrome for one scenario, as its project serves it: the project’s static/ files beside the page and its stylesheets linked from the document’s head, by the rule largo serve applies (serve_web::stylesheet_links_for). A page’s layout is its stylesheet’s as much as its markup’s — which element a click lands on depends on it — so a page tested bare is not the page a visitor gets. A launcher with no project serves the page alone.
ConsoleLine
One console message the page logged.
DomCounters
The renderer’s live object counts after a full garbage collection.
HostCall
One call across the host boundary, as the recorder saw it. Arguments and results are the decimal form of the raw wasm values (a Text argument is its handle).
OpenOptions
Setup applied before the page’s own scripts run.
Page
An open page. Closed, with its browser context, when dropped.
PageBundle
A built page: files by URL path, and the path the browser opens.
PageRequest
One request in the page’s own request table, as the page asked for it at the host boundary: its method, URL, body and headers as the page wrote them, and the timeout and abort it later asked for.
RelayHub
A relay the pages of one test share: every page opened with it publishes into it and hears what the others publish.
Snapshot
The page at one moment, as the browser holds it.

Enums§

BrowserError
Why a browser operation failed.
CallKind
Which way a traced call crossed the host boundary.
DomNode
One node of a snapshot document. An element carries its attributes sorted by name, and the two control PROPERTIES a visitor moves — value and checked — only where they differ from what the markup alone says (an untouched <input value="x"> has no value entry; a typed-into one does).

Functions§

locate_chrome
The Chrome (or Chromium) binary this machine has: CHROME_BIN when it names a file, otherwise the first of the usual names found on PATH.
shared
The one browser this process shares, launched from chrome on first use.