Frontend Instrumentation (static)
Applies to: frontend applications — Angular, React, Vue, and other bundled JavaScript apps.
Frontend apps use static instrumentation. The instrument command rewrites your built bundle and adds SeaLights coverage hooks before deployment.
You then deploy that instrumented copy to a test environment. As tests exercise the UI, the app reports coverage.
This is different from Scanning Your Application. scan uploads the build map. instrument rewrites the deployable files.
Scan the frontend build
Start by scanning the built bundle. This creates the SeaLights build map.
You need a valid token and Build Session ID first. See Scanning Your Application → Prerequisites and Scanning a frontend build.
Instrument the build
Run instrument on the built bundle, usually dist.
The command writes an instrumented copy to sl_dist.
Command syntax
npx slnodejs instrument \
--tokenFile ./sltoken.txt \
--buildSessionIdFile buildSessionId \
--scanDir dist \
--outputPath sl_dist \
--labId <Lab ID> \
--splitPreambleIntoFile \
--failOnError- name: SeaLights instrument (frontend)
run: |
npx slnodejs instrument \
--token "${{ secrets.SL_TOKEN }}" \
--buildSessionIdFile buildSessionId \
--scanDir dist \
--outputPath sl_dist \
--splitPreambleIntoFile \
--failOnErrornpx slnodejs instrument `
--tokenFile .\sltoken.txt `
--buildSessionIdFile buildSessionId `
--scanDir dist `
--outputPath sl_dist `
--labId <Lab ID> `
--splitPreambleIntoFile `
--failOnErrorImportant Notes:
Never deploy instrumented code to production.
sl_distis for test environments only.If your app sends CSP headers, they can block the SeaLights scripts. Whitelist the SeaLights endpoints or use
--splitPreambleIntoFileto serve the preamble from your own origin.
Deploy the instrumented output
instrument creates an sl_dist folder that mirrors dist, with SeaLights coverage hooks added to the JavaScript files.
Basic deployment
The simplest approach is to swap sl_dist into the original location. Your web server config stays unchanged.
mv dist dist_original
mv sl_dist dist
# Alternative: symbolic link (avoids renaming back later)
# ln -s sl_dist dist- name: Deploy instrumented build (swap)
run: |
mv dist dist_original
mv sl_dist dist
# Then deploy the dist folder to your test environmentRename-Item dist dist_original
Rename-Item sl_dist dist- script: |
mv dist dist_original
mv sl_dist dist
displayName: Swap instrumented build into placeAfter testing, restore the original (mv dist_original dist) or deploy from a clean build rather than the instrumented one for production.
Validate the result
After deployment, open the app in a browser and check:
Open Developer Tools → Sources.
Check your main bundle for the SeaLights preamble and
SLinitialization code.Confirm the build data matches the build you scanned.
If the preamble is missing, the instrumented build was not deployed or was overwritten later.
Run your tests
Once the instrumented build is deployed, continue to Capturing Tests.
Extra information
Parameters
--tokenFile / --token
SeaLights authentication (file locally, secret in CI)
--buildSessionIdFile / --buildSessionId
Build session identifier
--scanDir
The built bundle to instrument, usually dist
--outputPath
Where to write the instrumented copy, usually sl_dist
--labId
Connects this build to a test lab. If omitted, the Build Session ID is used as the Lab ID.
--splitPreambleIntoFile
Writes the SeaLights preamble to a separate file for CSP or caching scenarios
--failOnError
Fails the build step if instrumentation errors occur
Last updated
Was this helpful?

