Captures API traffic during crawl/exploration and produces a structured summary of discovered endpoints for API test generation.
Attaches Playwright request/response listeners to a BrowserContext and
records every same-origin fetch/XHR call. After crawling completes, the
captured entries are deduplicated, grouped by endpoint pattern, and
summarised into an ApiEndpoint[] array that the AI prompt can consume.
What is captured
- Method, URL path, query params, request headers (safe subset)
- Request body (JSON only, truncated to 2 KB)
- Response status, content-type, body (JSON only, truncated to 2 KB)
- Timing (duration ms)
What is filtered out
- Static assets (images, fonts, CSS, JS bundles, sourcemaps)
- Third-party origins (analytics, CDNs, ads)
- Duplicate endpoint+method combinations (keeps first + last seen)
Exports
createHarCapture— attach to a BrowserContext, returns collectorsummariseApiEndpoints— deduplicate + group captured entries
- Source:
Methods
(static) createHarCapture(context, appOrigin) → {Object}
Attach API traffic capture to a Playwright BrowserContext.
Call capture.detach() when done to stop listening. Then call
capture.getEntries() to retrieve all captured API calls.
Parameters:
| Name | Type | Description |
|---|---|---|
context |
Object | — Playwright BrowserContext instance |
appOrigin |
string | — the project URL origin (only same-origin calls captured) |
- Source:
Returns:
{ detach(), getEntries() } — collector handle
- Type
- Object
(inner) extractGraphQLOperationName(body) → {string|null}
Extract the GraphQL operation name from a JSON request body. Returns null if the body is not a valid GraphQL request.
Parameters:
| Name | Type | Description |
|---|---|---|
body |
string | null | Raw request body string. |
- Source:
Returns:
Operation name, or null.
- Type
- string | null
(inner) isGraphQLPath(pathname) → {boolean}
Check if a URL path looks like a GraphQL endpoint.
Parameters:
| Name | Type | Description |
|---|---|---|
pathname |
string |
- Source:
Returns:
- Type
- boolean
(inner) normalisePathPattern(pathname) → {string}
Normalise a URL path into a pattern by replacing numeric/UUID segments
with :id placeholders. This groups /api/users/123 and /api/users/456
into the same endpoint pattern /api/users/:id.
Parameters:
| Name | Type | Description |
|---|---|---|
pathname |
string |
- Source:
Returns:
- Type
- string
Type Definitions
ApiEndpoint
Deduplicate and summarise captured HAR entries into API endpoint descriptors.
Groups entries by METHOD + normalised path pattern, keeps the first and
last example for each group (so the AI sees both the shape and variation),
and produces a compact summary suitable for the API test prompt.
Type:
- Object
Properties:
| Name | Type | Description |
|---|---|---|
method |
string | — HTTP method (GET, POST, etc.) |
pathPattern |
string | — normalised path (e.g. |
exampleUrls |
Array.<string> | — 1–2 concrete URLs observed |
statuses |
Array.<number> | — unique status codes observed |
contentType |
string | — response content-type |
requestBodyExample |
string | null | — first observed request body (JSON) |
responseBodyExample |
string | null | — first observed response body (JSON) |
callCount |
number | — how many times this endpoint was hit |
avgDurationMs |
number | |
pageUrls |
Array.<string> | — which pages triggered this endpoint |
- Source: