Skip to content
Draft, pre-release documentation

The dom.* methods act on the pages of the browsers and Electron applications a session runs, over the Chrome DevTools Protocol. Firefox pages work through WebDriver BiDi. None of them needs a model.

dom.targets lists every registered application and its pages. Each page has a page reference, and every other dom.* method takes either a page or an element handle that carries its page. A call that names neither is malformed, even when only one page exists.

Over HTTP that is POST /v1/call/dom.targets with the body {}.

Call it first, and again after an application opens, restarts or closes. On a nix image every browser and Electron application the runtime starts is listed under its profile name, such as chrome or firefox. A Chromium-family browser or Electron application you start yourself joins with dom.register, naming the profile directory that holds its DevToolsActivePort file, and leaves with dom.unregister.

A reference belongs to one incarnation of its application. If the application restarts or the page closes, the call fails before anything is sent, says why, and asks for a fresh dom.targets.

A registration the runtime cannot reach is listed as unavailable with a reason and, for an installed application, a hint with the apps.start call that starts it.

dom.list_interactive returns the page’s buttons, links and fields as {handle, role, name, disabled}. A page with more than 100 interactive elements returns nothing until you pass filter, a case-insensitive part of the name.

dom.click takes a handle. A handle names one element in one document and is never matched by text. After a navigation it is stale, and the call fails naming the cause; list the page again. dom.click_described takes a description and matches it against the listing’s names, exact first and then a unique substring. When nothing matches, or several do, it clicks nothing and lists what is on the page.

A left click presses and releases the button at the element’s centre over the debugging protocol, so the page sees a trusted click with user activation. The click is refused, with nothing sent, when something covers the centre of the element or the element is hidden or has pointer-events: none. button selects right or middle, and dispatch: "script" calls the element’s own click() for the rare case where that is what you want.

Every result has an identity: the page it resolved to, the application and its title and URL. A click reports outcome (performed, not_performed or outcome_unknown) and a separate verification. outcome_unknown means the request was sent and the connection failed before the answer, so look at the page before repeating the action. Pass expect, a JavaScript condition, to add a check of your own.

selector (CSS) is accepted wherever a handle is, together with page. It searches the page’s own document first and then each open shadow root.

Method Reads
dom.url Where the page is now
dom.query One element’s tag, attributes, text, visibility and enabled state
dom.read_text The text of a section, chosen by selector, without moving focus, selection or the clipboard. Returns 4,096 code points by default, up to 65,536; read on with offset and the returned snapshot
dom.xpath Up to 32 XPath expressions in one call, evaluated on a sanitised copy of the page; max_nodes and max_chars bound the result

The text and attributes these methods return are what the page shows. Registered secret values are removed from titles, URLs and element names, and nothing else is redacted, so a caller can read whatever a signed-in person sees.

dom.fill sets a field to exactly one value. It focuses the field, clears it with Ctrl+A and Backspace, types the value one key per character as a person would, and reads the field back. dom.type types at the caret and never clears. dom.key presses a key. All three go over the debugging protocol, whether or not the browser window has focus on the desktop.

Because the page sees real key events, its own handlers, maxlength and focus moves apply, and a page that formats input can leave the field different from the value. The result’s field says what the field holds: matches is true when it shows exactly the value you sent. The value itself is never echoed. A select, and date, time, colour and range inputs, are set directly.

ref, in place of value or text, names a value from a loaded scenario’s provides: map; a driven session usually has none, so pass the literal.

dom.navigate opens a URL and returns once the new document has committed, with the URL reached and the response’s http_status. A status of 400 or more is not an error; the page that loaded is the server’s error page. When the URL’s response is a file, the result has kind: "download" and the page stays where it was; see Files, processes and the shell.

A click, a key press or a navigation that triggers another navigation returns before the next page is ready. Use dom.wait with a JavaScript predicate and timeout_s (default 30) to wait for what you need, then read the result.

dom.hover moves the page’s pointer to an element over the protocol; the desktop’s pointer does not move. dom.scroll scrolls an element into the middle of the view, or sends a mouse wheel at the centre of the viewport with dy and dx in CSS pixels.

dom.set_files sets the files of an <input type=file> without opening a file chooser. Upload the file first with PUT /v1/files/tmp/<name>, then call:

{"page": "<page reference>", "selector": "input[type=file]", "paths": ["/tmp/report.csv"]}

Each path must be an existing file under ~/ or /tmp/. The runtime refuses a symbolic link on the path, and reads the input’s files back to confirm. After the first dom.set_files on a page, the page’s own file chooser stays disabled while the runtime remains connected to it.

A page’s own alert, confirm, prompt or “Leave site?” dialog appears as dialog in the page’s identity and in dom.targets. While one is up, every method that changes the page is refused with nothing sent. dom.dialog answers it: accept: true presses OK or Leave, and text answers a prompt. The runtime never answers a dialog on its own.

On Chrome, a “Sign in with …” prompt opens the browser’s own account chooser, which the page’s document does not contain. It shows up as fedcm in the page’s identity. dom.fedcm answers it with an account index, a button, or dismiss: true; pass the id you read the accounts from. Firefox does not support FedCM, so the request is rejected without a chooser.

When a native modal dialog, such as the desktop’s file chooser, blocks a browser, every dom.* method that changes the page fails as not_performed with nothing sent. Reads still work. Desktop applications shows how to deal with the dialog first.

Firefox pages show protocol: bidi in dom.targets. On a nix image, start Firefox with apps.start and it is listed as firefox; on other images, start it with --remote-debugging-port=9222 and it is default. Firefox pages have no accessibility tree, so dom.list_interactive and dom.click_described fail there and no element handles exist. Use page with selector. Firefox’s first page, about:home, accepts only dom.navigate.