← blog
· series: Measured · tool: tracescrub

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 session cookie, a bearer token (in the login response, localStorage and the Authorization header) and an API key that the account page shows.
  • 4 tests: a setup test signs in and saves storageState to playwright/.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

ArtifactPasswordSession cookieBearer tokenAPI key
4 trace.zip files72758
HTML report (playwright-report/)82758
HAR file0611
storageState file0110

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 the fill parameters, in the fill("...") 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 its storageState() call.
  • test.trace, the test steps. The Fill step 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/me responses 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.zip

show-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 close

trace 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 },
},
ArtifactPasswordSession cookieBearer tokenAPI key
4 trace.zip files4110
HTML report5110
  • No screenshots, and no API key in the traces.
  • No network log either. The type docs say the dom snapshot option will "capture DOM snapshot on every action and record network activity". With it off, trace open reports 0 requests.
  • The password is still there 4 times: the fill parameters, the fill("...") log line, and the title and value of the Fill step. The cookie and the token are still in the result of the setup test's storageState() 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 scrubbed

check 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.

RunText copies leftFindings
scrub, no options0105
scrub --no-propagate1 password and 4 API keys in the traces, the same in the report95
scrub --env DEMO_PASSWORD,...0105
  • 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 fill into a password field, an Authorization header, a Set-Cookie header, a JSON key named apiKey. It then removes the same value everywhere else. That second step is called propagation.
  • --no-propagate shows why it matters. Without it, the fill("...") log line kept the password, and the DOM snapshots kept the API key as page text.
  • --env with 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 --env or --env-file anyway.
  • All 4 scrubbed traces opened with npx playwright trace open and 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: 7
  • if: ${{ !cancelled() }} runs the scrub and the upload when tests fail, which is when you need the report.
  • check after scrub fails the job if anything is left, so an unscrubbed report is never uploaded.
  • It uploads playwright-report/ only, never playwright/.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 check after 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 storageState files. 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.