Private archive copy · Unofficial site · Content copyright belongs to Runoob Tutorial and the original authors · View Original

Playwright Network and Input API

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 a POST request
request.postDataJSON() JSON body of a POST request
request.postDataBuffer() Buffer body of a 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 information (returns null if no failure)
request.timing() Request timing information

Response class

Method Description
response.url() Response URL
response.status() HTTP Status Codes
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() The corresponding Request object
response.frame() The Frame that initiated the request

Route class

Method Description
route.abort(errorCode?) Abort the request
route.continue(options?) Continue the request after modification
route.fulfill(options?) Return a custom response
route.fetch(options?) Actually send the request and get 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) Frame received event
webSocket.on('framesent', handler) Frame sent 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 (general)
request.storageState(options?) Get storage state
request.dispose() Dispose resources

APIResponse class

Method Description
response.status() HTTP Status Codes
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() Dispose 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 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