Browser Agent
The SeaLights Browser Agent collects code coverage from web applications in the browser while tests run.
The SeaLights Browser Agent collects code coverage from your web application (React, Angular, Vue, Svelte or any other JavaScript front end) while tests run against it in a browser. It reports the coverage to SeaLights for the build and for the test stage that is open on its lab.
How the agent gets into your application
You do not add the agent to your code. The Node.js agent (slnodejs) instruments the built JavaScript of your application and adds a small loader, the preamble, to the instrumented files. When the page loads, the preamble:
sets the agent configuration of the build (application, branch, build, build session ID, lab ID, server, token);
loads the agent script from SeaLights, or from your SeaLights Collector when the build was instrumented with a Collector URL;
loads the build's mapping file (sl-mapping), unless the build resolves coverage on the server.
You deploy the instrumented files instead of the original files to the environment where tests run.
CI: build ──► slnodejs scan --instrumentForBrowsers ──► sl_dist/ (instrumented copy)
Test environment: browser loads sl_dist/ ──► preamble ──► Browser Agent ──► SeaLights (or Collector)What the agent sends
Footprints: which instrumented code ran, grouped by the active test, sent to SeaLights or to the Collector.
Agent events: agent start and shutdown, and errors.
Execution queries: the agent periodically asks SeaLights which test stage is open for its lab ID, so that coverage is attributed to it. When the build has a Collector URL, the agent does not send these queries itself.
Pages in this section
End-to-end setup, checking the agent in the browser, multiple builds on one page, source maps
Angular, React, Vue, Vite, webpack, esbuild, Rsbuild and Rspack, Rollup, micro-frontends
Every flag and setting: what it does, the problem it solves, how to tell you need it, an example
Lab ID, Collector and token, allowed domains, content security policy, coverage settings, settings read at instrumentation, runtime overrides
Attributing back-end coverage to the browser test: --enableOpenTelemetry, --allowCORS, test context events and cookies
Agent not loading, no footprints, sl-mapping not found, missing context headers
The slnodejs commands and flags that instrument the build are on Frontend Instrumentation (static) and in the Command Reference.
Requirements
window and document
Required
The agent does not start.
JavaScript language level
ES2015
The agent bundle is compiled to ES2015 (ES6). Browsers without ES2015 support cannot run it.
document.head
Required
The preamble cannot add the agent script; the agent does not load.
window.sessionStorage
Optional
Test context set with set:context is not restored after a page navigation.
console.log
Optional
The agent does not log.
Quick check in the browser
Open the developer tools console on an instrumented page:
A working agent also logs a line containing has been loaded for each build. See Check that it works.
Last updated
Was this helpful?

