You can configure pages to load over the HTTP(S) proxy or SOCKSv5. Proxy can be either set globally for the entire browser, or for each browser context individually.
You can optionally specify username and password for HTTP(S) proxy, you can also specify hosts to bypass proxy for.
Here is an example of a global proxy:
When specifying proxy for each context individually, you need to give Playwright a hint that proxy will be set. This is done via passing a non-empty proxy server to the browser itself. Here is an example of a context-specific proxy:
You can monitor all the requests and responses:
Or wait for a network response after the button click:
- event Page.Request
- event Page.Response
- Page.RunAndWaitForRequestAsync(action, urlOrPredicate, options)
- Page.RunAndWaitForResponseAsync(action, urlOrPredicate, options)
You can mock API endpoints via handling the network quests in your Playwright script.
- BrowserContext.RouteAsync(url, handler)
- BrowserContext.UnrouteAsync(url, handler)
- Page.RouteAsync(url, handler)
- Page.UnrouteAsync(url, handler)
You can continue requests with modifications. Example above removes an HTTP header from the outgoing requests.
Playwright supports WebSockets inspection out of the box. Every time WebSocket is created, event Page.WebSocket event is fired. This event contains the WebSocket instance for further web socket frames inspection:
- event Page.WebSocket
- event WebSocket.FrameSent
- event WebSocket.FrameReceived
- event WebSocket.Close