Playwright Network and Input API
This appendix lists APIs related to network requests, keyboard, mouse, and touch.
Request Class
| Method | Description |
request.url() | Request URL |
request.method() | Request method (GET/POST, etc.) |
request.headers() | Request headers |
request.postData() | Body data of POST request |
request.postDataJSON() | JSON body of POST request |
request.postDataBuffer() | Buffer body of POST request |
request.isNavigationRequest() | Whether it is a navigation request |
request.frame() | The Frame that initiated the request |
request.redirectedFrom() | Redirect source Request |
request.redirectedTo() | Redirect target Request |
request.failure() | Request failure info (returns null if no failure) |
request.timing() | Request timing information |
Response Class
| Method | Description |
response.url() | Response URL |
response.status() | HTTP status code |
response.statusText() | Status text |
response.headers() | Response headers |
response.body() | Response body (Buffer) |
response.text() | Response body (text) |
response.json() | Response body (JSON) |
response.ok() | Whether the status code is in the 200-299 range |
response.request() | Corresponding Request object |
response.frame() | The Frame that initiated the request |
Route Class
| Method | Description |
route.abort(errorCode?) | Abort request |
route.continue(options?) | Continue the request after modifications |
route.fulfill(options?) | Fulfill with custom response |
route.fetch(options?) | Actually send the request and obtain the response |
route.request() | Get the corresponding Request |
WebSocket Class
| Methods/Events | Description |
webSocket.url() | WebSocket URL |
webSocket.isClosed() | Whether it is closed |
webSocket.on('framereceived', handler) | Receive frame event |
webSocket.on('framesent', handler) | Send frame event |
webSocket.on('close', handler) | Close event |
APIRequestContext Class
| Method | Description |
request.get(url, options?) | Send a GET request |
request.post(url, options?) | Send a POST request |
request.put(url, options?) | Send a PUT request |
request.patch(url, options?) | Send a PATCH request |
request.delete(url, options?) | Send a DELETE request |
request.head(url, options?) | Send a HEAD request |
request.fetch(urlOrRequest, options?) | Send a request (generic) |
request.storageState(options?) | Get storage state |
request.dispose() | Release resources |
APIResponse Class
| Method | Description |
response.status() | HTTP status code |
response.statusText() | Status text |
response.headers() | Response headers |
response.body() | body(Buffer) |
response.text() | Body (text) |
response.json() | body(JSON) |
response.ok() | Whether the status code is in 200-299 |
response.url() | The final URL of the response |
response.dispose() | Release resources |
Keyboard Class
| Method | Description |
keyboard.press(key) | Press and release a key |
keyboard.down(key) | Press a key without releasing |
keyboard.up(key) | Release a key |
keyboard.type(text, options?) | Type character by character |
keyboard.insertText(text) | Insert text directly |
Mouse Class
| Method | Description |
mouse.click(x, y, options?) | Click at coordinates |
mouse.dblclick(x, y, options?) | Double-click at coordinates |
mouse.move(x, y, options?) | Move the mouse to coordinates |
mouse.down(options?) | Press the mouse button |
mouse.up(options?) | Release the mouse button |
mouse.wheel(deltaX, deltaY) | Scroll the wheel |
Touchscreen Class
| Method | Description |
touchscreen.tap(x, y) | Tap |
Other extensions