HTTP traffic
Waiting for traffic
Wait For Request and Wait For Response wait for a request or response of the page and return what was sent and received. Start the wait before the action, with Promise To.
Wait For Request returns the first request of the
page that matches, Wait For Response the first
response. Both see page traffic, HTTP included, but not Send API Request.
Start the wait first
A wait sees only what happens after it starts, and the request usually fires during
the action. Start the wait with Promise To, act, then collect the result:
See Promises for how they work.
What they return
| Keyword | Returns | Main keys |
|---|---|---|
Wait For Request | CapturedRequest | url, method, headers, allHeaders with cookie, postDataBuffer (raw body), postDataJSON, resourceType |
Wait For Response | CapturedResponse | status, headers, allHeaders with set-cookie, bytes, text, json, request |
The body is raw bytes with the views text and json, as for the
other responses. To save it or to mock with it:
Arguments
matcherfollows the shared rules. Empty matches the first request or response. A function gets Playwright's Request or Response:response => response.status() === 500.timeoutdefaults to the library timeout. ForWait For Responseit also covers reading the body.wait_for_all_fields=TrueNew in Browser 21.1.0 (Wait For Request) also waits forallHeadersandheadersArray. Chromium and WebKit report them only when the response headers arrive, so by default they areNone.include_body=FalseNew in Browser 21.1.0 (Wait For Response) does not read the body, for a large or endless one.body,bytes,textandjsonare thenNone, and so arehttpVersion,serverAddrandsecurityDetails, which some browsers report only after the body.
Logging
Requests and responses are logged without their body. allHeaders and
headersArray are logged at DEBUG level, because they can hold cookies. The body
is logged at TRACE level: as JSON, as text, or as base64.