Sharing Playwright Traces Safely: One Sign-in, 7 Copies of the Password
One sign-in test left the password in its Playwright trace 7 times. What traces, reports, HAR and storageState files hold, and what tracescrub removes before you share them.
A Playwright trace records every action, page and request of a test. That makes it a copy of every secret the test touched. In a 4-test suite with 4 fake secrets, one sign-in test left the password in its trace 7 times. The session cookie was in the traces 27 times, and the HTML report carried all of it again.
This guide shows what each artifact holds, how to open a trace, and two ways to share one safely: record less, or scrub with tracescrub, a tool I maintain. Scrubbing removed every text copy, and the trace still opened. It did not touch the screenshots, and a scrubbed frame still shows the API key. The app, the tests, the counter, the workflow and the raw output are in the PoC repo.
The suite
- A sign-in page and an account page, served by a small Node server that Playwright starts with
webServer. - 4 fake secrets: the password typed into the form, a
sessioncookie, a bearer token (in the login response,localStorageand theAuthorizationheader) and an API key that the account page shows. - 4 tests: a setup test signs in and saves
storageStatetoplaywright/.auth/user.json, and 3 account tests reuse it. One account test records a HAR file. trace: 'on'and the HTML reporter. Playwright 1.65.1 with Chromium, Node v24.14.1, macOS on arm64.
To count the secrets, scripts/count.mjs unpacks every zip with unzip, unpacks the zip that the HTML report embeds in index.html, and searches for each value in plain text and in base64. It does not use tracescrub, so the counts before and after scrubbing come from the same independent check.
What the artifacts hold
| Artifact | Password | Session cookie | Bearer token | API key |
|---|---|---|---|---|
4 trace.zip files | 7 | 27 | 5 | 8 |
HTML report (playwright-report/) | 8 | 27 | 5 | 8 |
| HAR file | 0 | 6 | 1 | 1 |
storageState file | 0 | 1 | 1 | 0 |
A trace is a zip. These are the places in it that held a secret:
N-trace.trace, the action log. The password is in thefillparameters, in thefill("...")log line and in the input's value in the DOM snapshots: 4 copies. The API key is in the text of the DOM snapshots: 4 copies. The setup test's action log also has the cookie and the token, in the result of itsstorageState()call.test.trace, the test steps. TheFillstep has the password in its title,Fill "correct-horse-7319", and in its value: 2 copies.N-trace.network, the network log. The cookie and the token are in the request and response headers: 30 copies.resources/, the request and response bodies. The login request body has the password, and the/api/meresponses have the API key. The login response has the token, but the trace kept that body in only 4 of 6 runs, and not in the measured one.screencast/, the screenshots of the page. A frame of the account page shows the API key.
The HTML report holds the same 4 traces under data/, plus the Fill "..." step title in index.html. Upload the report as a CI artifact and every one of those copies goes with it.
The HAR file has the cookie in all 3 requests, as a header and in the cookies list. The token is in the Authorization header of the /api/me request, and the API key is in its response. The storageState file has the cookie and the token in plain JSON. The 3 account tests load that file and start signed in; anyone with the file can do the same.
Open a trace
npx playwright show-report
npx playwright show-trace test-results/<test>/trace.zipshow-report opens the HTML report, and each test links its trace. show-trace opens one trace in the trace viewer.
Since 1.59, Playwright can also read a trace from the terminal. Coding agents use this, so it is one more reader of your traces:
npx playwright trace open test-results/<test>/trace.zip
npx playwright trace actions
npx playwright trace closetrace open prints a summary: the title, the action count, the requests and the errors. trace actions lists each action.
Option 1: record less
The trace option takes an object. This config keeps the action log and turns off the DOM snapshots and the screenshots:
use: {
trace: { mode: 'on', snapshots: false, screenshots: false },
},| Artifact | Password | Session cookie | Bearer token | API key |
|---|---|---|---|---|
4 trace.zip files | 4 | 1 | 1 | 0 |
| HTML report | 5 | 1 | 1 | 0 |
- No screenshots, and no API key in the traces.
- No network log either. The type docs say the
domsnapshot option will "capture DOM snapshot on every action and record network activity". With it off,trace openreports 0 requests. - The password is still there 4 times: the
fillparameters, thefill("...")log line, and the title and value of theFillstep. The cookie and the token are still in the result of the setup test'sstorageState()call.
Recording less cuts the copies but does not remove them, and it takes away the DOM and network views you wanted the trace for.
Option 2: scrub with tracescrub
npm i -D pw-tracescrub
npx tracescrub check test-results playwright-report
npx tracescrub scrub test-results playwright-report playwright/.auth --out scrubbedcheck reports each secret with a masked preview and exits 1 if it finds one, or if some text content could not be scanned. Images do not count: they produce a note, not a failure. scrub writes copies with [REDACTED:<rule>] in place of each secret, or rewrites the files with --in-place.
| Run | Text copies left | Findings |
|---|---|---|
scrub, no options | 0 | 105 |
scrub --no-propagate | 1 password and 4 API keys in the traces, the same in the report | 95 |
scrub --env DEMO_PASSWORD,... | 0 | 105 |
- With no options, the scrub removed every text copy of all 4 secrets, in all 4 artifact types.
- It finds a secret by its structure first: a
fillinto a password field, anAuthorizationheader, aSet-Cookieheader, a JSON key namedapiKey. It then removes the same value everywhere else. That second step is called propagation. --no-propagateshows why it matters. Without it, thefill("...")log line kept the password, and the DOM snapshots kept the API key as page text.--envwith the 4 variable names removed the same copies. In this app every secret also had a structure that tracescrub knows. A secret with no such structure, in a place it does not parse, is only found by value, so pass--envor--env-fileanyway.- All 4 scrubbed traces opened with
npx playwright trace openand showed the same action count as the raw traces.
The images are the gap. The measured run had 18 screencast frames. tracescrub does not scan images and says so in its output: 36 image/media entries were not scanned (18 frames, once in the traces and once in the report). After the scrub, the last frame of the API key test still shows the key (the frame). The tracescrub README says it does not scan images, fonts, audio or video, so the same applies to the screenshot and video options.
The workflow
These are the steps from the workflow in the repo. It scrubs the report in place, checks it, and only then uploads it. The job's env sets the 4 variables; in your repo they come from secrets:
env:
DEMO_PASSWORD: ${{ secrets.DEMO_PASSWORD }}
# ...and the other 3
steps:
- run: npx playwright test
- name: Scrub secrets from the report
if: ${{ !cancelled() }}
run: |
npx tracescrub scrub playwright-report --in-place --env DEMO_PASSWORD,DEMO_SESSION,DEMO_API_TOKEN,DEMO_API_KEY
npx tracescrub check playwright-report --env DEMO_PASSWORD,DEMO_SESSION,DEMO_API_TOKEN,DEMO_API_KEY
- uses: actions/upload-artifact@v7
if: ${{ !cancelled() }}
with:
name: playwright-report
path: playwright-report/
retention-days: 7if: ${{ !cancelled() }}runs the scrub and the upload when tests fail, which is when you need the report.checkafterscrubfails the job if anything is left, so an unscrubbed report is never uploaded.- It uploads
playwright-report/only, neverplaywright/.auth/.
In GitHub Actions (job log), the scrub removed 49 findings from the report, check found none, and the upload ran. check passed with 15 image/media entries were not scanned: a clean check does not mean clean screenshots.
What didn't work
- One small app with 4 secrets that I planted and knew. A real suite has secrets you did not plan for, and the count is only as good as the list of values you search for.
- tracescrub does not scan images. The API key on the account page survives in the screenshots whatever you scrub.
- Recording less is not a fix on its own. The password stayed in the step title and the action log with snapshots and screenshots off.
- The token count changed between runs: 6 in 4 of 6 runs, 5 in the measured one. The sign-in page leaves as soon as it reads the login response, and the trace did not always keep that body.
- I did not test
retain-on-failure.
What I'd do
- Scrub before every upload, and run
checkafter the scrub so the job fails if a secret is left. - Pass the names of your test secrets with
--env, even when the patterns find them. - Never upload
storageStatefiles. They are a signed-in session. - Keep secrets off the pages your tests screenshot: use test accounts whose keys are not shown, or mask them in the app's test mode.
- Give test accounts their own credentials, with no access to real data, and rotate them. Then a leaked trace leaks a test account.
For the tool itself, see tracescrub. The app, the tests, the counter and the raw results: poc-playwright-sharing-traces-safely.
related
QA Ark Newsletter
Test automation, AI in testing and quality engineering practice. No spam, unsubscribe any time.