Expand description
Browser’s terminal action: typing and running commands in a web
terminal on a site the person granted
(docs/specs/SPEC_BROWSER_WEB_TERMINAL_TYPING_2026_10_23.md §4).
The host does the typing (browser_api/terminal.rs: real key events into
xterm.js); this module decides whether it may happen and what comes back:
- the agent needs a live grant with the
terminalpower on this pane, and the page and the terminal’s own frame must be on the granted sites; - a line that looks like a credential is never typed, and neither is anything while the terminal is asking for a password or a code;
- text goes in small chunks, and the grant, the pause and Stop are checked between them, so a brake pressed mid-script ends it within a moment;
- what the terminal prints goes back to the agent only, as untrusted page content, and is never written to the Log or the host log.
Structs§
- Host
Failure 🔒 - The host could not type a chunk, after
sentkeys had gone in. - KeyStep 🔒
- One key for the host: the fields of a CDP key event.
- Typing 🔒
- How far typing a script got, and why it stopped short, if it did.
Enums§
- Refusal 🔒
- Why the terminal can’t be typed into right now.
Constants§
- CHUNK 🔒
- Keys per call to the host. A brake is checked between calls.
- CTRL_
LETTERS 🔒 - The Ctrl combinations a shell uses (spec D6): interrupt, end of input, suspend, clear, history search, and the line-editing set.
- DEFAULT_
WAIT_ 🔒SECS - How long to wait for output when the agent didn’t say.
- LINE_
SETTLE 🔒 - The longest to wait for the rows to catch up with a line before reading them for a prompt and sending the next one.
- MAX_
CHARS 🔒 - Most characters one call types, so a script fits and a runaway can’t.
- MAX_
LINES 🔒 - Lines (Enter presses) per call. Each one after the first waits for the rows to catch up and is checked again, about a second and a half apiece, so this keeps a call well inside the MCP client’s timeout.
- MAX_
ROWS 🔒 - Rows of output given back, from the bottom of the terminal.
- MAX_
WAIT_ 🔒SECS - The longest an agent may ask to wait for output.
- POLL 🔒
- How often the rows are read while waiting.
- QUIET 🔒
- Output counts as settled once it hasn’t changed for this long (a little
over
ROWS_LAG, so the rows have caught up with what it printed). - ROWS_
LAG 🔒 - How long xterm.js’s screen-reader rows can trail the screen: it redraws them at most once a second, so a line’s output (a password prompt) may not be in the rows for up to this long after the line ran.
- SECRET_
NAMES 🔒 - Names whose assignment (
NAME=value) puts a secret on the command line. - SECRET_
PROMPT_ 🔒WORDS - Words a terminal prompt uses when it asks for something only the person should type.
- TYPE_
BUDGET 🔒 - The longest a call spends typing before it stops and says how far it got. Lines are capped, but a long line is many pieces, each checked again; this keeps any call inside the MCP client’s 120 s (plus the output wait), so a client that gave up never leaves the handler typing with nobody waiting.
Functions§
- auth_
header 🔒 - An
Authorization:header, orBearerfollowed by a long token. - budget_
stop 🔒 - check_
target 🔒 - Looks at the page, at the frame that holds the terminal, and at the last line the terminal shows, and says whether the grant lets the agent type there now. Run before the first key and again before every later line: a page can navigate, and a command can open a prompt, between two keys.
- credential_
line 🔒 - Does
textlook like it holds a credential (a key, a token, a private key, a header value, a password in an assignment or a URL)? It is then never typed: it would land in the shell’s history and the process list. The key and token shapes are the ones the app redacts logs with; the rest is for a command line. Errs towards refusing: the person can type it, or the agent can use a value the shell already has. - detail_
for_ 🔒log - What the Log keeps for a call: the text (shortened), else the keys. Empty when the text looks like a credential, on every path including a call that is refused for another reason: the Log is the person’s record, and a key or a token has no place in it.
- enter 🔒
- finish_
typing 🔒 - Reads what the terminal printed, once it settles, logs the call and answers it.
- handle_
ui_ 🔒browser_ terminal POST /api/v1/ui/browser/terminal— backsBrowser’sterminalaction.- is_
token_ 🔒char - jwt 🔒
- A JSON web token:
eyJ…and two more dot-separated parts. - let_
screen_ 🔒catch_ up - Before the next line goes in, let what the last one did reach the rows: wait
out
ROWS_LAG, then read until two reads in a row agree, for at mostLINE_SETTLE, so a prompt a command opened is showing when it is checked. - log_how 🔒
- How the Log records the call: typed under the grant, or, when not one key went in, refused. A prompt’s text is never what the Log keeps.
- look 🔒
- Ask the host what the page’s terminal looks like now.
- output_
fields 🔒 - What a call tells the agent about the terminal’s output: the rows when they could be read (page content, untrusted), else why not.
- over_
budget 🔒 - Whether a call has typed for as long as one call may.
- pieces 🔒
- The keys in the order they go out, in pieces. A piece ends after an Enter
(the end of a line, so the screen can be read before the next line goes in:
a command may have opened a password prompt) or at
maxkeys, whichever comes first. - rows_of 🔒
- secret_
assignment 🔒 NAME=valuewith a secret-looking NAME and a literal value (not$VAR, a<placeholder>or a short word likenone).- secret_
prompt 🔒 - Is the terminal’s last line asking for a password, passphrase, code or
token? The line must end like a prompt (a colon or a question mark) and
name one, so a path or a project called
token-servicedoesn’t count. Echo is usually off at such a prompt, so the person types there anyway (spec §4.3). - settle 🔒
- Read the terminal until its rows stop changing for
QUIET, oruntilshows in them, orwaitis up. - step_
for_ 🔒char - The key for one typed character: what a keyboard would send for it. The
code and the virtual key are best effort for punctuation and non-ASCII
text: xterm.js acts on
key, and Chrome raises the character fromtext. - step_
for_ 🔒key - A named key from the
keyslist. - steps_
for_ 🔒request - The keys a call types: its text, then an Enter (default: yes when text is given) unless the text ended in one, then its named keys. Checked before anything is typed.
- steps_
for_ 🔒text - The keys that type
text: each line break is a real Enter, a tab is Tab. Other control characters are refused (a stray escape sequence is not text the agent meant to type). - stop_
before 🔒 - Whether the call must stop before typing chunk
nofparts, and why (with whether it is a secret prompt): over the time one call may type, the person paused the pane or ended the grant, or, from the second chunk, the page or terminal no longer passes (after a line, once the screen has caught up with it). - terminal_
grant 🔒 - The grant that lets
agenttype onpane: this agent, this pane, the terminal power, and this page. The person’s standing grant for the agent on the page’s site makes one when the pane has none. - tidy_
rows 🔒 - The terminal’s rows as the agent gets them: trailing blank rows dropped,
the bottom
MAX_ROWSkept. - type_
steps 🔒 - Types
stepsa line at a time (or a chunk of a long one), with the brakes, the grant, the page and the prompt checked between pieces. - typed_
for_ 🔒log - What the Log keeps of what was typed: the line itself when short, else its first and last lines and its length. Masked and cut again by the Log.
- url_
password 🔒 - A password in a URL:
scheme://user:password@host. - wait_
for 🔒 - How long a call waits for the terminal’s output: what the agent asked, at most
MAX_WAIT_SECS.