Overview
Evaluate JavaScript code in the browser page context. Returns the result of the expression or script execution.
Syntax
bdg dom eval < scrip t > [options]
Arguments
JavaScript expression or statement to execute (e.g., "document.title", "window.location.href")
Options
Output as JSON with full Runtime.evaluate response
Output
Returns the evaluated result. Objects are serialized to strings.
$ bdg dom eval "document.title"
Browser Debugger CLI
$ bdg dom eval "document.querySelectorAll('button').length"
3
{
"version" : "0.5.1" ,
"success" : true ,
"data" : {
"result" : "Browser Debugger CLI"
}
}
Examples
Get page properties
bdg dom eval "document.title"
bdg dom eval "window.location.href"
bdg dom eval "document.readyState"
Query DOM
bdg dom eval "document.querySelector('h1').textContent"
bdg dom eval "document.querySelectorAll('.error').length"
Execute complex scripts
bdg dom eval '(() => {
const buttons = document.querySelectorAll("button");
return Array.from(buttons).map(b => b.textContent);
})()'
Check element state
bdg dom eval "document.querySelector('#submit-btn').disabled"
bdg dom eval "document.querySelector('input').value"
Shell quote handling
JavaScript expressions with quotes require careful escaping:
Single quotes (recommended)
Double quotes
Heredoc for complex scripts
bdg dom eval 'document.querySelector("h1").textContent'
If you see a SyntaxError, the shell may have stripped quotes. The error message shows the script as received to help diagnose escaping issues.
Error messages
When JavaScript execution fails, bdg provides context:
$ bdg dom eval "document.querySelector(input).value"
Error: ReferenceError: input is not defined
Script received: document.querySelector ( input ) .value
Shell quote damage detected:
querySelector(input ) - quotes stripped by shell
Try: bdg dom eval 'document.querySelector("input")'
Common use cases
# Get all link URLs
bdg dom eval 'Array.from(document.querySelectorAll("a")).map(a => a.href)'
# Get form data
bdg dom eval 'Object.fromEntries(new FormData(document.querySelector("form")))'
Check page state
# Scroll position
bdg dom eval "window.scrollY"
# Viewport size
bdg dom eval '[window.innerWidth, window.innerHeight]'
Modify page
# Scroll to element
bdg dom eval 'document.querySelector("#footer").scrollIntoView()'
# Set value
bdg dom eval 'document.querySelector("#search").value = "test"'
Return value limitations
Objects are serialized (not live references)
DOM nodes return [object HTMLElement] (use selectors instead)
Functions cannot be returned
Circular references may fail
Exit codes
Success - script executed
INVALID_ARGUMENTS - JavaScript syntax error
CDP_TIMEOUT - CDP operation timed out
SESSION_FILE_ERROR - session metadata missing