Skip to Content

Commands

Wire format for browser commands sent through the protocol.

Command structure

Commands use a command string to identify the action and a params object for arguments:

{ "type": "worker.command", "id": "cmd_001", "command": "navigate", "params": { "url": "https://example.com" } }

Actions

Navigate to a URL.

{ "command": "navigate", "params": { "url": "https://example.com" } }

reload

Reload the current page.

{ "command": "reload", "params": {} }

goBack

Navigate back.

{ "command": "goBack", "params": {} }

waitForNavigation

Wait for a navigation matching a URL pattern.

{ "command": "waitForNavigation", "params": { "urlPattern": "https://example\\.com/dashboard.*", "timeout": 10000 } }

click

Click an element.

{ "command": "click", "params": { "selector": "#login-button" } }

fill

Fill an input field.

{ "command": "fill", "params": { "selector": "#email", "value": "[email protected]" } }

select

Select a dropdown option.

{ "command": "select", "params": { "selector": "#country", "values": ["US"] } }

waitForSelector

Wait for a DOM element.

{ "command": "waitForSelector", "params": { "selector": ".dashboard", "timeout": 5000, "state": "visible" } }

getAttribute

Get an element’s attribute value.

{ "command": "getAttribute", "params": { "selector": "#link", "name": "href" } }

textContent

Get an element’s text content.

{ "command": "textContent", "params": { "selector": ".title" } }

innerHTML

Get an element’s inner HTML.

{ "command": "innerHTML", "params": { "selector": ".container" } }

isVisible

Check if an element is visible.

{ "command": "isVisible", "params": { "selector": "#modal" } }

evaluate

Execute JavaScript.

{ "command": "evaluate", "params": { "expression": "document.title" } }

url

Get the current URL.

{ "command": "url", "params": {} }

title

Get the page title.

{ "command": "title", "params": {} }

content

Get the full page HTML.

{ "command": "content", "params": {} }

screenshot

Capture a screenshot.

{ "command": "screenshot", "params": { "format": "png", "fullPage": false } }

press

Press a keyboard key.

{ "command": "press", "params": { "key": "Enter" } }

waitForNetworkIdle

Wait for network activity to settle.

{ "command": "waitForNetworkIdle", "params": { "timeout": 5000 } }

waitForTimeout

Wait for a fixed duration.

{ "command": "waitForTimeout", "params": { "timeout": 2000 } }

updateStatus

Update the overlay UI shown to the user while the script has control.

{ "command": "updateStatus", "params": { "heading": "Logging in...", "subheading": "Please wait", "progress": 50 } }

Response format

Responses use a success discriminant:

Success:

{ "type": "client.command_response", "id": "cmd_001", "success": true, "result": { "url": "https://example.com" } }

Error:

{ "type": "client.command_response", "id": "cmd_001", "success": false, "error": { "code": "ELEMENT_NOT_FOUND", "message": "Selector not found" } }

Next steps

Last updated on