.ie \n(.g .ds Aq \(aq
.el .ds Aq '
.TH js 1 "js "
.SH NAME
js \- JavaScript execution in page context
.SH SYNOPSIS
\fBjs\fR [\fB\-\-frame\fR] [\fB\-h\fR|\fB\-\-help\fR] <\fIsubcommands\fR>
.SH DESCRIPTION
Execute JavaScript expressions or scripts in the page context. Returns the result as structured JSON. Supports both synchronous expressions and async functions.
.SH OPTIONS
.TP
\fB\-\-frame\fR \fI<FRAME>\fR
Target frame by index, path (1/0), or \*(Aqauto\*(Aq
.TP
\fB\-h\fR, \fB\-\-help\fR
Print help (see a summary with \*(Aq\-h\*(Aq)
.SH SUBCOMMANDS
.TP
js\-exec(1)
Execute JavaScript in the page context
.TP
js\-help(1)
Print this message or the help of the given subcommand(s)
.SH EXTRA
EXAMPLES:
# Get the page title
agentchrome js exec "document.title"
# Execute a script file
agentchrome js exec \-\-file script.js
# Run code on a specific element (by UID from snapshot)
agentchrome js exec \-\-uid s3 "(el) => el.textContent"
# Read from stdin
echo \*(Aqdocument.URL\*(Aq | agentchrome js exec \-
.SH CAPABILITIES
.PP
JavaScript execution in page context
.TP
.B js exec
Execute JavaScript in the page context
.TP
.B code
JavaScript code to execute (use '-' to read from stdin)
.TP
.B --code
JavaScript code as a named argument (avoids shell quoting issues on Windows)
.TP
.B --stdin
Read JavaScript code from stdin
.TP
.B --file
Read JavaScript from a file instead of inline argument
.TP
.B --uid
Element UID from 'page snapshot'; code is wrapped in a function receiving the element
.TP
.B --no-await
Return promise objects without awaiting them
.TP
.B --timeout
Execution timeout in milliseconds (overrides global --timeout)
.TP
.B --max-size
Truncate result output exceeding this size in bytes
.TP
.B --worker
Worker index from 'page workers' for executing JS in a worker context
.SH EXAMPLES
.PP
Examples:
.TP
.B \`agentchrome js exec "document.title"\`
Get the page title
.TP
.B \`agentchrome js exec --file script.js\`
Execute a JavaScript file
.TP
.B \`agentchrome js exec --uid s3 "(el) => el.textContent"\`
Run code on a specific element by UID
.TP
.B \`echo 'document.URL' | agentchrome js exec -\`
Read JavaScript from stdin
.TP
.B \`agentchrome js --frame 1 exec "document.title"\`
Execute JavaScript inside an iframe
.TP
.B \`agentchrome js exec --worker 0 "self.registration.scope"\`
Execute JavaScript in a Service Worker