Skip to content

Control Servo using WebDriver

Manuel Rego edited this page Jan 14, 2026 · 4 revisions

First, run an instance of Servo with the webdriver server enabled on a particular port (and optionally a particular resolution):

$ ./mach run --webdriver=7002 --screen-size "400x300"

Using curl and jq

From another terminal window, use curl or wget to interact with the webdriver web server inside of Servo (requires that the jq utility is installed):

# Create a session for subsequent commands
$ SESSIONID=$(curl -H 'Content-Type: application/json' -X POST -d '{"capabilities": {}}' http://127.0.0.1:7002/session | jq -r ".value.sessionId")

# Load the desired URL
$ curl -v -H 'Content-Type: application/json' -X POST -d '{"url": "http://example.org"}' http://127.0.0.1:7002/session/${SESSIONID}/url

# Save a screenshot of the current content to a file
$ curl -v http://127.0.0.1:7002/session/${SESSIONID}/screenshot | jq -r ".value" | base64 -d > test1.png

Using JavaScript

Using the npm webdriver package, you could do something like:

import WebDriver from 'webdriver';

const client = await WebDriver.newSession({
    hostname: '127.0.0.1',
    port: 7002,
    capabilities: {  }
})

await client.navigateTo('https://example.org/')

console.log(await client.getTitle())

await client.deleteSession()

Clone this wiki locally