Setting Up Browser Coverage
This page instruments a built web application, deploys it, checks that the Browser Agent runs, and captures tests. For your framework or bundler, start from Framework and Bundler Setups. The slnodejs options used here are described in Frontend Instrumentation (static).
End-to-end setup
The steps below instrument an application built into dist/ and write the instrumented copy to sl_dist/.
Build with source maps
Build the application so that source maps with column information are written next to the bundles. See Scanning → Front-end builds.
npm run buildRun the tests on the same lab
Coverage is attributed to the test stage that is open for the agent's lab ID (qa-env here). Either use a SeaLights test framework plugin (Playwright, Cypress and others; see Node.js Testing Plugins) with the same lab ID, or open and close the test stage yourself:
npx slnodejs openTestStage --tokenFile sltoken.txt --buildSessionIdFile buildSessionId --labId qa-env --testStage "E2E Tests"
# run the browser tests against the qa-env environment
npx slnodejs closeTestStage --tokenFile sltoken.txt --buildSessionIdFile buildSessionId --labId qa-env --testStage "E2E Tests"Check that it works
Open an instrumented page of the test environment and the browser developer tools console:
The agent logs
Sealights browser version <version> has been loadedfor each build that started. The line is logged at theinfolevel, so it is hidden when the log level iswarningor lower; see Agent log level.window.$SealightsAgentis defined. It is also defined when the agent rejected the configuration of every build on the page, so check the log line as well.window.$SealightsAgent.getSlMapping('<build-session-id>')returns the mapping of that build (without an argument, the first build on the page).window.$SealightsAgent.dumpSlMappings()returns the mappings of all builds. An empty object means no mapping was loaded. (Builds instrumented with--footprintsMapping serveror--embedCorrectUniqueIddo not download a mapping.)The agent logs the lab ID it uses as
LabId:<value>. It must match the lab of the open test stage.In the network tab, requests to SeaLights (or to the Collector) for footprints return success while you use the page.
If one of these fails, see Troubleshooting.
Multiple builds on one page
Micro-frontends, separately deployed bundles and shared component libraries can each be instrumented as their own build (their own config and scan). Each instrumented build carries its own configuration, identified by its build session ID, and the agent runs one instance per build session ID on the page. A second configuration with a build session ID that is already running is ignored.
Give all builds that are tested together the same lab ID.
Code split into chunks of one build needs no extra setup: every chunk produced by the instrumented build reports to the same build session.
Source maps
slnodejs uses your build's source maps during the scan to map the built files back to your source files. Keep the source maps next to the built files when you run the scan. To keep them out of the deployed output, scan with --excludeSourceMapFiles skipCopy (or skipAndDelete, which also deletes them from the scanned folder).
Several test environments
Each environment needs its own lab ID. Instrument once per environment with its own --labId, or instrument once and set the lab ID at runtime with window["__sl.labId__"]. See Frontend Instrumentation → Multiple test environments and Configuration → Lab ID.
Next steps
Content security policy, Collector, token exposure, allowed domains: Configuration and Runtime Overrides.
Back-end coverage per browser test: Context Propagation.
Last updated
Was this helpful?

