Configuration
Two option fixtures configure the loggers. Both are optional and flat objects.
import { defineConfig } from '@playwright/test';
import type { LoggerOptions } from 'playwright-logger-pro/fixtures';
export default defineConfig<LoggerOptions>({
use: {
apiLog: { curl: 'on-failure' },
browserLog: { network: 'failed', redact: { values: [process.env.E2E_PASSWORD].filter((v): v is string => !!v) } },
},
});
The option tables on this page are compared with the library's option types and exported defaults when the site is built (npm run check-config in website/). A missing or extra option, or a wrong default, fails the build.
Precedence and merge rules
test.use()replaces the whole object.test.use({ apiLog: { curl: true } })replaces theapiLogfrom your config; it does not merge. Repeat the options you still want. The same holds forbrowserLog.redactis merged one level deep with the defaults: settingredact: { values: [...] }keeps the defaultselectors,keysand the rest. Settingredact.selectorsorredact.keysadds to the defaults;apiLog.replaceDefaultRedaction: truereplaces them.undefinedmeans the default. An option explicitly set toundefineduses its default, which lets you writecolors: process.env.CI ? true : undefined.- Explicit
colorswins over every colour environment variable. - Invalid values never throw. An unknown option or invalid value prints a one-time
[playwright-logger-pro]warning naming the option, and the default is used. (maxEventsmust be a positive integer so a bad value can never switch the failure block off.) httpCredentialsarrays. Playwright readstest.use({ httpCredentials: [a, b] })as[value, options], not as two credentials. To pass an array, writetest.use({ httpCredentials: [[a, b], { scope: 'test' }] }).- Redaction lists are merged with the built-in lists, in apiLog and in browserLog's
redact; seereplaceDefaultRedaction, the one switch that drops the defaults of both.
apiLog options
Configures request logging for the request fixture and wrapRequestContext().
| Option | Type | Default | Description |
|---|---|---|---|
enabled | boolean | true | false makes the wrapper a transparent pass-through. |
colors | boolean | auto | true/false force ANSI colours on/off (true wins over NO_COLOR). In compact output an explicit value also decides the colours of the reporter (it reads it from the JSON attachment; the reporter's own colors wins). Auto: see Environment variables. With a custom sink and no explicit colors, auto means off, so ANSI codes do not reach a file. |
format | 'compact' | 'verbose' | 'compact' | 'compact': one line per call and detail only where something went wrong, printed by the reporter. 'verbose': the 0.3 output (request, headers, bodies, response, curl) printed live. |
curl | boolean | 'on-failure' | '5xx' | '4xx+' | 'always' | 'never' | '5xx' | Which calls get a curl (and a curl.sh attachment): '5xx' status >= 500 and network errors, '4xx+' status >= 400 and network errors, 'always' (every call gets a curl in the playwright-logger-pro.json attachment; its curl*.sh script is attached only for a failed test or with details: 'always'; the compact console still prints curls only under failed calls, status >= 400 or a network error), 'never'. Legacy: true is 'always', false is 'never', 'on-failure' is '4xx+' in compact output (the console shows curls for status >= 400 and network errors; a 1xx/3xx response also gets its curl*.sh when the test failed) and any non-2xx with format: 'verbose'. With format: 'verbose' the default is false, as in 0.3. Other values warn and use the default. To also get the curl of a successful call whose test failed, see curlOnFailedTest. |
curlOnFailedTest | false | true | 'last' | 'all' | false | Compact output. When a test fails, the curl and a curl.sh of the last call made before the failure ('last', same as true) or of every call made before it ('all'), whatever its status, shown in a neutral │ block under its line; the status chip keeps its success colour. Masked like every curl (*** on the console, ${VAR} placeholders in curl.sh). Independent of curl (works with curl: 'never'); details: 'never' leaves the block out and curlFormat.file: false the file. Calls made after the first failure (an afterEach cleanup, steps after a failed expect.soft) are never the last call. Does nothing for a passing test. See Compact output. |
slowThresholdMs | number | 1000 | A call at least this slow gets ▲ and a yellow time, and counts in the footer. |
timeColumn | number | 'auto' | 82 | Column where the timing ends. 'auto' fits the terminal width. A longer line keeps a 2-space gap and, past the terminal width, loses the middle of its query string. |
details | 'failed-tests' | 'always' | 'never' | 'failed-tests' | When a request with status >= 400 or a network error gets its │ block: only when its test failed, always, or never. |
bodyPreviewChars | number | 200 | Length of the response body preview in the block, in characters. |
theme | 'ansi' | 'dark' | 'light' | 'ansi' | 'ansi' uses the 16 basic colours of your terminal theme. 'dark' and 'light' are true-colour palettes (the ones of the README screenshots). |
ascii | boolean | false (true on legacy Windows consoles) | ASCII symbols (| <- ^ -> ok x) instead of Unicode. |
mask | { headers?, query?, bodyKeys? } | {} | Extra names to mask, merged with the built-in lists and with redactHeaders, redactQueryParams and redactBodyKeys. The mask is always ***. |
curlFormat | { colors?, multiline?, file? } | { colors: 'auto', multiline: true, file: true } | How the curl is printed and saved: colours, single-line output and the curl.sh file. See curlFormat. |
logHeaders | boolean | true | Log request and response headers (compact: keep them in the JSON attachment). |
logBody | boolean | true | Log request and response bodies (compact: keep them in the JSON attachment and show the response preview). |
maxBodyLength | number | 2000 | Truncate logged bodies beyond this many characters. A number ≥ 0; Infinity disables truncation. Applies to format: 'verbose' and the JSON attachment; the compact curl is cut at 2 KB. |
redactHeaders | string[] | [] plus the built-in authorization, proxy-authorization, cookie, set-cookie, x-api-key, x-auth-token | Extra header names masked in logs and curl. Case-insensitive; merged with the defaults. |
redactQueryParams | string[] | [] plus the built-in api_key, apikey, token, access_token, refresh_token, key, password, secret, signature, sig | Extra query parameter names masked in logged URLs and curl. Merged with the defaults. |
redactBodyKeys | string[] | [] plus the built-in password, token, accessToken, refreshToken, secret, apiKey, cardToken, cardNumber, cvv, pin, access_token, refresh_token, api_key, card_number | Extra JSON/form body keys and multipart field names masked in logged bodies and curl, at any depth. |
replaceDefaultRedaction | boolean | false | true drops the built-in lists: only your lists are used, and a list you leave out redacts nothing. Also applies to browserLog.redact (selectors, keys, queryParams, headers). Dangerous. |
sink | (line: string) => void | console.log | Where log lines go. A throwing sink warns once and falls back to console.log. |
baseURL | string | fixture: use.baseURL | Used to show absolute URLs and the original URL of redirected requests. The fixture fills it in; pass it yourself with wrapRequestContext(). |
extraHTTPHeaders | Record<string, string> | fixture: use.extraHTTPHeaders | Headers the context sends with every request, shown in logged headers and curl. The fixture fills it in; with wrapRequestContext() pass the headers you gave newContext(). |
curlFormat
Presentation of the curl command. Only the printed command changes; the redaction is the same everywhere. An invalid value warns once and uses the default.
| Option | Type | Default | Description |
|---|---|---|---|
colors | boolean | 'auto' | 'auto' | Colours the curl and, with format: 'compact', the whole output printed by the fixture (without the reporter). 'auto' colours only when NO_COLOR is unset, the process is not on CI, the output is a terminal (stdout is a TTY, the test runner's own stdout is one, or PLAYWRIGHT_FORCE_TTY is set), the resolved colors is true and the sink is the default console one. A local npx playwright test in a terminal therefore colours it with no setting. FORCE_COLOR alone does not colour it in CI or when piped, and neither does a top-level colors: true for the verbose output. In compact output a top-level colors: true colours the whole output, the curl in the block included (see Compact output). true is an explicit override that skips all of these checks (ANSI codes may reach CI logs, files and custom sinks); false never colours. See When the curl is coloured. |
multiline | boolean | true | false prints the command on a single line, options joined by single spaces. Notes and redirect step comments stay on their own # lines above it. |
file | boolean | true | With the test fixture, attach the curls to the report as scripts. Compact: curl.sh (or curl-{n}-{METHOD}-{lastPathSegment}.sh), #!/usr/bin/env bash, ${VAR} placeholders for masked values. Verbose: one curl.sh (#!/bin/sh) and a one-line notice. Only applies while curl is enabled. |
See API logging › curl output for the colours, the colouring rules and the curl.sh file.
Reporter options
playwright-logger-pro/reporter takes the display options of apiLog (they win over what the fixture recorded) and one more. See Compact output.
| Option | Type | Default | Description |
|---|---|---|---|
slowThresholdMs, timeColumn, details, bodyPreviewChars, theme, ascii | as in apiLog | Same meaning and defaults. | |
curl | '5xx' | '4xx+' | 'always' | 'never' | from apiLog.curl | Which calls show their curl. The fixture decides which calls carry one (apiLog.curl, and every failed call); this can only show fewer, or more of the failed ones. |
colors | boolean | 'auto' | 'auto' | true forces colours on, false off. 'auto': the explicit colors of the test's apiLog, if it has one; otherwise no colours on CI, with NO_COLOR, FORCE_COLOR=0, TERM=dumb or when stdout is not a terminal. |
browserLog options
| Option | Type | Default | Description |
|---|---|---|---|
enabled | boolean | true | false: no patches, listeners or session for the test. |
colors | boolean | auto | Colours for print only. Files and attachments are always plain text. |
actions | boolean | true | Interactions and navigations (click, fill, goto, ...). |
waits | boolean | true | waitFor*, locator.waitFor, waitForTimeout. |
queries | boolean | false | Read-only async calls (textContent, isVisible, count, ...). Results are never logged. |
mouseMoves | boolean | false | mouse.move (noisy). |
navigation | boolean | true | Main-frame navigations, page open/close/popup/crash, dialogs, downloads. |
browserConsole | false | 'error' | 'warning' | 'info' | 'all' | 'warning' | Minimum console level to record. |
pageErrors | boolean | true | Uncaught page exceptions. |
network | false | 'failed' | 'documents' | 'all' | false | Network capture. 'failed' = request failures and status ≥ 400; 'documents' = document, xhr and fetch. Subscribing adds protocol traffic. |
networkFilter | (r: { url: string; method: string; resourceType: string }) => boolean | none | Extra filter applied after network. |
steps | boolean | 'auto' | 'auto' | test.step integration. 'auto' is on for Playwright ≥ 1.48. false turns it off. |
includeApiLog | boolean | true | Copy apiLog lines into the attachment and file (never printed twice). |
logStart | boolean | false | Also print a line when an action starts (needs print: true). |
slowActionMs | number | 1000 | Highlight actions slower than this many ms; JSONL gets slow: true. A number ≥ 0. |
location | boolean | false | Append the call site in your spec, such as (login.spec.ts:14). Costs one stack capture per action. |
maxArgLength | number | 200 | Truncate each rendered argument and console message. A positive integer or Infinity. |
maxEvents | number | 5000 | Ring buffer per test; the oldest events are dropped and a marker says how many. A positive integer. |
redact | BrowserRedactConfig | see below | Secret masking. |
print | boolean | 'on-failure' | 'on-failure' | Print to sink: live (true) or one block when the test failed. |
attach | boolean | 'on-failure' | 'on-failure' | Attach browser-log to the report. |
attachFormat | 'text' | 'jsonl' | 'text' | Format of the attachment. |
file | boolean | 'on-failure' | false | Write a per-test file. |
fileFormat | 'text' | 'jsonl' | 'text' | Format of the file. |
fileDir | string | the test's output directory | Directory for per-test files. Never cleaned by the logger. |
sink | (line: string) => void | console.log | Where printed text goes. |
browserLog.redact
| Option | Type | Default | Description |
|---|---|---|---|
mask | string | '***' | Replacement for masked values. |
fillValues | 'auto' | 'always' | 'never' | 'auto' | Masking of typed values. 'auto': when the target looks sensitive. 'always': every typed value. 'never': none (values still applies). |
selectors | (string | RegExp)[] | DEFAULT_SENSITIVE_SELECTORS | Matched against the target's description; strings are case-insensitive substrings. Added to the default list; apiLog.replaceDefaultRedaction: true replaces it. Text is also matched after splitting on camelCase, _ and -, for your own entries too. |
values | string[] | [] | Literal secrets masked everywhere, in addition to the ones collected automatically. Values shorter than 4 characters are ignored. |
keys | (string | RegExp)[] | the sensitive key patterns | Object keys masked inside arguments. Added to the default patterns; apiLog.replaceDefaultRedaction: true replaces them. |
queryParams | string[] | apiLog's resolved list: api_key, apikey, token, access_token, refresh_token, key, password, secret, signature, sig plus your apiLog.redactQueryParams | Extra query parameter names, added to apiLog's redactQueryParams (defaults included). Their values are masked in every URL the browser log prints. |
headers | string[] | apiLog's resolved list: authorization, proxy-authorization, cookie, set-cookie, x-api-key, x-auth-token plus your apiLog.redactHeaders | Extra header names, added to apiLog's redactHeaders (defaults included). |
inspectInputType | boolean | false | Opt-in DOM probe for type=password after a fill. One extra round trip per distinct field. |
buildCurl options
buildCurl(info, redactHeaderNames?, options?) is exported for building a curl yourself: info is a RequestInfo, the second argument lists header names to mask, and the third is CurlOptions:
| Option | Type | Default | Description |
|---|---|---|---|
redactQueryParams | readonly string[] | none | Query parameter names whose values are masked in the URL. |
redactBodyKeys | readonly string[] | none | JSON/form body keys and multipart field names whose values are masked. |
maxBodyLength | number | none | Truncate the request body (and each form/field value) beyond this many characters. |
colors | boolean | false | Colour the command with ANSI codes. Removing the codes gives exactly the uncoloured command. |
colorDepth | 4 | 8 | detected | Palette used with colors: 8 for the 256-colour palette (38;5;N), 4 for the 16 basic colours. Detected from COLORTERM, TERM and the terminal when omitted. See API logging › Colours. |
multiline | boolean | true | One option per line with \ continuations; false gives a single line. |
mask | string | (key: string) => string | '***' | What replaces a masked value; a function receives the header, query parameter or body key name (the curl.sh attachment uses it for ${NAME} placeholders). Do not combine a function with colors. |
skipHeaders | readonly string[] | none | Header names (case-insensitive) left out of the command. |
truncationMarker | string | none | Appended to a body cut by maxBodyLength. |
truncationNote | (limit, total) => string | built-in note | Text of the # note that announces a cut body. |
Fixtures and exports
From playwright-logger-pro/fixtures:
| Name | Type | Description |
|---|---|---|
test | TestType | Drop-in replacement for Playwright's test: wraps request and records browser actions. Adds the apiLog and browserLog option fixtures and the browserLogger fixture. |
expect | Expect | Playwright's expect, re-exported. |
mergeTests | typeof mergeTests | Playwright's mergeTests (1.39+) that keeps the step integration. Throws on older Playwright. |
LoggerOptions | type | ApiLoggerOptions & BrowserLoggerOptions, for defineConfig<LoggerOptions>(). |
ApiLoggerOptions | type | { apiLog: ApiLoggerConfig }. |
BrowserLoggerOptions | type | { browserLog: BrowserLoggerConfig }. |
BrowserLoggerFixtures | type | { browserLogger: BrowserLogHandle }. |
BrowserLogHandle | type | note(), events(), render(), detach(). See Browser logging. |
BrowserLoggerConfig | type | The browserLog option type. |
From playwright-logger-pro:
| Name | Type | Description |
|---|---|---|
wrapRequestContext | function | Wrap an APIRequestContext with API logging. |
attachBrowserLogger | function | Record a page or context you manage yourself. |
buildCurl | function | Build the curl command for a RequestInfo. |
resolveConfig | function | Validate an ApiLoggerConfig and fill in defaults. |
resolveBrowserConfig | function | Validate a BrowserLoggerConfig and fill in defaults. |
detectColorSupport | function | The colour auto-detection used by both loggers. |
DEFAULT_CONFIG | constant | Resolved defaults of apiLog. |
DEFAULT_BROWSER_CONFIG | constant | Resolved defaults of browserLog. |
DEFAULT_REDACT_HEADERS | constant | authorization, proxy-authorization, cookie, set-cookie, x-api-key, x-auth-token. |
DEFAULT_REDACT_QUERY_PARAMS | constant | api_key, apikey, token, access_token, refresh_token, key, password, secret, signature, sig. |
DEFAULT_REDACT_BODY_KEYS | constant | password, token, accessToken, refreshToken, secret, apiKey, cardToken, cardNumber, cvv, pin and the snake_case spellings of four of them. |
renderCalls, renderCallLine, renderDetail, renderFooter, summarize | functions | The pure renderer of the compact output: records and options in, lines out. |
buildCurlParts | function | The terminal and the curl.sh form of one call's curl. |
DEFAULT_SENSITIVE_KEYS | constant | Names that usually hold secrets (password, token, api_key, authorization, cookie, otp, pin, cvv, ...), shared by both loggers. |
DEFAULT_SENSITIVE_SELECTORS | constant | Patterns matched against a target's description to decide whether a typed value is masked. |
renderBrowserEventText | function | Render one browser event as text. |
renderBrowserEventJsonl | function | Render one browser event as a JSONL line. |
formatRequestLine | function | Low-level formatting helper. |
formatResponseLine | function | Low-level formatting helper. |
formatErrorLine | function | Low-level formatting helper. |
formatHeaders | function | Low-level formatting helper. |
formatBody | function | Low-level formatting helper. |
describeResponseBody | function | Text to log for a response body (binary placeholder for non-text types). |
describeMultipart | function | Describe a multipart payload for logs and curl. |
escapeControlChars | function | Escape control characters in text. |
redactHeaders | function | Mask header values by name. |
redactUrl | function | Mask query parameter values in a URL. |
redactQueryString | function | Mask query parameter values in a query string. |
redactBodyValue | function | Mask keys in a parsed body. |
redactBodyString | function | Mask keys in a body string (JSON, form). |
truncateBody | function | Truncate a body at a character boundary. |
stringifyBody | function | Turn a request body into a string. |
ApiLoggerConfig | type | The apiLog option type. |
ResolvedConfig | type | ApiLoggerConfig after resolveConfig(). |
BrowserLoggerConfig | type | The browserLog option type. |
BrowserRedactConfig | type | The browserLog.redact option type. |
ResolvedBrowserConfig | type | BrowserLoggerConfig after resolveBrowserConfig(). |
BrowserLogEvent | type | The event union, see the JSONL format. |
BrowserLogHandle | type | The handle returned by attachBrowserLogger() and the browserLogger fixture. |
CurlOptions | type | Options of buildCurl. |
RequestInfo | type | The request description buildCurl takes. |
RedirectHop | type | One request Playwright sent while following redirects. |
The formatting and redaction helpers are exported for advanced use and are likely to be reviewed before 1.0. Signatures are in the API reference.
The BrowserLogEvent kinds are listed in Reporter & attachments.
Environment variables
These decide the default for colors (both loggers) when you do not set it, in this order:
| Variable | Effect |
|---|---|
NO_COLOR | Non-empty: colours off. |
FORCE_COLOR, DEBUG_COLORS | 0 or false: colours off. Any other value (including empty for FORCE_COLOR): on. playwright test sets both for its workers, which is why colours normally work in test output although the workers' stdout is a pipe. |
PLAYWRIGHT_FORCE_TTY | Anything but 0/false: on. |
TERM=dumb | Off (checked before the TTY test). |
| TTY | On when stdout or stderr is a TTY; otherwise off. |
colors: true or false in the options always wins, including over NO_COLOR.
The VS Code Playwright extension's play button runs tests without a terminal, so auto-detection gives no colour. Colour it everywhere except on CI:
use: { apiLog: { colors: !process.env.CI } },
Or on the reporter alone, leaving apiLog as it is:
reporter: [['list'], ['playwright-logger-pro/reporter', { colors: !process.env.CI }]],
On CI that sets colors: false, so CI logs stay plain. See Compact output › Colours.
The curl command has its own, stricter rule and reads a few more variables:
| Variable | Effect |
|---|---|
CI and the CI service variables | The curl stays plain. |
PLP_RUNNER_TTY | Set by the library in the test runner process when the runner's own stdout is a terminal (<runner pid>:<colour depth>); workers inherit it and, when it names their parent, colour the curl by default. Do not set it yourself: it is ignored unless it holds the runner's pid. See Local runs in a terminal. |
COLORTERM (truecolor, 24bit), TERM (contains 256color) | The curl uses the 256-colour palette; otherwise the 16 basic colours. |
| Variable | Effect |
|---|---|
DEBUG=plp (any value containing plp) | Prints a warning when the library could not hide its own frames from Playwright (step locations may then point into the library). |
Examples
- TypeScript
- JavaScript
import { defineConfig } from '@playwright/test';
import type { LoggerOptions } from 'playwright-logger-pro/fixtures';
export default defineConfig<LoggerOptions>({
use: {
apiLog: {
curl: 'on-failure',
redactQueryParams: ['sig'],
redactBodyKeys: ['password'],
},
browserLog: {
print: process.env.CI ? 'on-failure' : true,
network: 'failed',
file: 'on-failure',
fileFormat: 'jsonl',
fileDir: 'logs/browser',
redact: {
values: [process.env.E2E_PASSWORD].filter((v): v is string => !!v),
selectors: ['#pin-pad'],
},
},
},
});
const { defineConfig } = require('@playwright/test');
module.exports = defineConfig({
use: {
apiLog: { curl: 'on-failure', redactQueryParams: ['sig'], redactBodyKeys: ['password'] },
browserLog: {
print: process.env.CI ? 'on-failure' : true,
network: 'failed',
redact: {
values: [process.env.E2E_PASSWORD].filter(Boolean),
selectors: ['#pin-pad'],
},
},
},
});