Version: Next
Network
Playwright provides APIs to monitor and modify network traffic, both HTTP and HTTPS. Any requests that page does, including XHRs and fetch requests, can be tracked, modified and handled.
HTTP Authentication#
- Sync
- Async
API reference#
Network events#
You can monitor all the requests and responses:
- Sync
- Async
Or wait for a network response after the button click:
- Sync
- Async
Variations#
- Sync
- Async
API reference#
- Request
- Response
- page.on("request")
- page.on("response")
- page.expect_request(url_or_predicate, **kwargs)
- page.expect_response(url_or_predicate, **kwargs)
Handle requests#
- Sync
- Async
You can mock API endpoints via handling the network quests in your Playwright script.
Variations#
- Sync
- Async
API reference#
- browser_context.route(url, handler)
- browser_context.unroute(url, **kwargs)
- page.route(url, handler)
- page.unroute(url, **kwargs)
- Route
Modify requests#
- Sync
- Async
You can continue requests with modifications. Example above removes an HTTP header from the outgoing requests.
Abort requests#
- Sync
- Async