Skip to content

Studio: browser agent can click at a point, move the mouse, drag, and run approved scripts - #13505

Merged
danielhanchen merged 15 commits into
mainfrom
studio-browser-pointer-actions
Oct 13, 2026
Merged

danielhanchen merged 15 commits into
mainfrom
studio-browser-pointer-actions

Conversation

@shimmyshimmer

@shimmyshimmer shimmyshimmer commented Oct 13, 2026 •

Copy link
Copy Markdown
Member

What changes

The browser agent could only act on elements by ref. It had no way to click something without a ref (a canvas, a map, a custom widget), hover to open a menu, drag, or run JavaScript. This adds:

  • browser_click at x, y. ref is now optional: the model can pass x and y instead. The click lands on whatever is drawn at that point, as a real click would, with the right clientX/clientY, so canvases and maps get correct offsets.
  • browser_move_mouse (ref or x, y). Sends the full pointer/mouse over, enter, leave and move sequence, so menus that open on mouseenter open.
  • browser_drag from ref or x, y to to_ref or to_x, to_y. Press, 5 to 25 moves paced one frame apart, release. Pages that listen on document (sliders, sortable lists) follow it. When the source is draggable="true" it sends HTML drag and drop events instead, with a shared DataTransfer, and reports when nothing took the drop.
  • browser_evaluate runs a script (the body of an async function; return gives back a value as JSON, await works). The result goes back to the model inside the untrusted-content fence.

Coordinates are pixels of the latest browser_screenshot. The panel scales the capture to the page's CSS size (within the server's 1024 px image edge) and keeps the scale, so a point read off the picture maps back exactly. The tool result states the picture's size. Without a screenshot, x and y are CSS pixels of the visible page.

Security

The new tools reuse the existing gates and close the gaps that points and scripts open:

  • Point clicks are gated like ref clicks. The element at the point is described first, so Buy, Delete, sign-in and POST-form buttons ask, links are checked before they load, and password and file fields stay off-limits.
  • What was asked about is what gets hit. A ref belongs to one element, but a point can land on something new while the user decides. Describe returns the element at the point. The click, and a drag's press, refuse with "the page changed under that point" if anything else is there, including after a navigation.
  • Drags: both ends are gated as clicks, since a drop can delete or send too. Hover asks nothing.
  • Scripts ask every time, whatever the site permissions say. A script can do anything the page can, including what the other tools gate or never do. The agent bar shows the whole script, and Allow stays disabled until its end has been on screen. A declined script never runs.
  • The script runs only on the document it was approved for. The executor takes the page's document token before asking. After approval it refuses if the address changed, and the page agent refuses on any other document, including a reload of the same address.
  • What the user reads is what runs. The server refuses scripts with invisible or direction-changing characters (Unicode Cf, the Trojan Source trick) and long blank runs that could hide a tail. Scripts are capped at 8000 characters.
  • Desktop native views get the script through a new browser_view_eval command. The script is spliced into source the same way as the agent and annotate code, so a page CSP without 'unsafe-eval' can't block it. The id and document token are checked to plain characters before splicing. A syntax error fails the whole script, so the page never runs half of it. The command has the same require_main and view checks as browser_view_agent. The proxied frame compiles the script in the page, where the proxy already strips the page's CSP.
  • Error messages: points outside the visible page or on an embedded frame are refused with fixed messages. All new page-agent errors are on the executor's allowlist, so page words never reach the model outside the fence.

Performance

Each action costs about what a ref click does. Settling and the snapshot after it dominate, as before.

  • Drag:
    • Each move's round trip counts toward its 16 ms frame. A 25-step drag on desktop takes about 0.4 s instead of up to 0.9 s.
    • The start is re-located only when finding the end ref could have scrolled it.
  • Script results: the first poll runs right after the start, so a synchronous script answers with no wait. Async ones are polled every 100 ms, for up to 15 s.
  • Screenshots:
    • The page size comes back from the existing mask call, with no extra round trip.
    • Captures are scaled down to at most 1024 px before upload, instead of sending full Retina frames for the server to shrink.
  • In the page:
    • Hover bookkeeping walks only the ancestor chain, and only when the element under the pointer changes.
    • Script outcomes are capped at 20 entries and dropped once read.

How it was verified

  • Backend:
    • pytest tests/test_browser_agent.py passes. New tests cover ref-or-point validation, script bounds and fencing, the hidden-text refusals, and the screenshot size note.
    • The browser cases of the tool-loop and route tests pass: 133 passed in total.
    • ruff is clean.
  • Frontend:
    • npm run typecheck, npm test (11766 passed, including the durable-gate list check) and npm run build pass.
    • Biome error counts per changed file are unchanged from main.
  • Rust: the full app builds, and eval_code_is_spliced_once_and_ids_are_plain passes along with the existing splice tests. The new test also checks rejection of bad ids and document tokens.
  • Page agent in real Chromium and WebKit (Playwright, 26 checks per engine):
    • Clicks: exact offsets at a point on a canvas, button activation, link handoff, and refusals for points off the page or on an embedded frame.
    • Changes under the point: a "Buy" button laid over the point after describe makes the click and the drag start refuse.
    • Hover enter and leave.
    • Drags: a slider that listens on the document, and HTML drag and drop with DataTransfer data.
    • Scripts: values, awaits, elements, throws, syntax errors, circular values, and the native function form. A script approved before a reload refuses afterwards.
  • End to end on live pages through the real executor, gates, agent bar and proxied frame (dev server against this branch's backend):
    • A click at x, y toggles a checkbox on the-internet.herokuapp.com/checkboxes.
    • A drag swaps the columns on /drag_and_drop.
    • Moving onto a jQuery UI menu item opens its submenu.
    • The script prompt names the site and shows the code.
    • Allow stays disabled on a 61-line script until it is scrolled to the end.
    • A declined script never runs.

Not covered here

  • Desktop native views were not run from this host. The splice and the command registration are compiled and unit-tested, and the page-agent side was exercised in WebKit and Chromium.
  • Synthetic events don't trigger CSS :hover or move native form controls such as <input type="range">. Menus driven by JS hover handlers, and custom sliders, work.

Screenshots

A browser_evaluate request reaching the panel, merge base (left) against this branch (right), each a separate Studio built from its tree. On the merge base there is no script tool, so nothing is asked.

The script is shown in full and Allow stays disabled while its end is off screen:

Script question with Allow disabled

Scrolled to its last line, Allow is enabled:

Script question with Allow enabled

@shimmyshimmer

Copy link
Copy Markdown
Member Author

@codex security review

@chatgpt-codex-connector

chatgpt-codex-connector Bot commented Oct 13, 2026 •

Copy link
Copy Markdown

Codex Review Summary

This comment shows the latest Codex review activity on this pull request.

Review Status Commit Review trigger
📝 Code Review ✅ Completed 2026-10-13T08:21:41.416363Z 50e577a Manual request
🔒 Security Review ✅ Completed 2026-10-13T01:16:44.230951Z 6a5e01d Manual request

Security findings

Advisory findings (1)

ℹ️ About Codex in GitHub

Your team has set up Codex to review pull requests in this repo. Reviews are triggered when you

  • Open a pull request for review
  • Mark a draft as ready
  • Comment "@codex review" or "@codex security review".

Codex reacts with 👀 while any review is running, comments if it has suggestions, and reacts with 👍 once all reviews finish with no findings.

chatgpt-codex-connector[bot]

This comment was marked as resolved.

chatgpt-codex-connector[bot]

This comment was marked as resolved.

chatgpt-codex-connector[bot]

This comment was marked as resolved.

chatgpt-codex-connector[bot]

This comment was marked as resolved.

chatgpt-codex-connector[bot]

This comment was marked as resolved.

…hrough shadow roots, and tie screenshot points to scroll and document
@unslothai unslothai deleted a comment from chatgpt-codex-connector Bot Oct 13, 2026
@unslothai unslothai deleted a comment from chatgpt-codex-connector Bot Oct 13, 2026
@unslothai unslothai deleted a comment from chatgpt-codex-connector Bot Oct 13, 2026
@unslothai unslothai deleted a comment from chatgpt-codex-connector Bot Oct 13, 2026
@unslothai unslothai deleted a comment from chatgpt-codex-connector Bot Oct 13, 2026
@unslothai unslothai deleted a comment from chatgpt-codex-connector Bot Oct 13, 2026
@unslothai unslothai deleted a comment from chatgpt-codex-connector Bot Oct 13, 2026
@unslothai unslothai deleted a comment from chatgpt-codex-connector Bot Oct 13, 2026
@unslothai unslothai deleted a comment from chatgpt-codex-connector Bot Oct 13, 2026
@unslothai unslothai deleted a comment from chatgpt-codex-connector Bot Oct 13, 2026
@unslothai unslothai deleted a comment from chatgpt-codex-connector Bot Oct 13, 2026
@unslothai unslothai deleted a comment from chatgpt-codex-connector Bot Oct 13, 2026
@unslothai unslothai deleted a comment from chatgpt-codex-connector Bot Oct 13, 2026
@unslothai unslothai deleted a comment from chatgpt-codex-connector Bot Oct 13, 2026
@unslothai unslothai deleted a comment from chatgpt-codex-connector Bot Oct 13, 2026
@danielhanchen danielhanchen self-assigned this Oct 13, 2026
danielhanchen added a commit to oobabooga/unsloth that referenced this pull request Oct 13, 2026
The browser pointer and script tools (unslothai#13505) use AgentAnswer.pending as a
boolean for a script still running; a numeric pending here would merge into
the same type.
@danielhanchen

Copy link
Copy Markdown
Member

pre-commit.ci run

chatgpt-codex-connector[bot]

This comment was marked as resolved.

Stop a drag whose page navigates mid-drag before it touches the new page,
land the last step on the end point exactly, refuse to press a disabled
control, and recheck the release target after the page's hover and dragover
handlers, as the press already does.
@unslothai unslothai deleted a comment from chatgpt-codex-connector Bot Oct 13, 2026
@unslothai unslothai deleted a comment from shimmyshimmer Oct 13, 2026
@danielhanchen

Copy link
Copy Markdown
Member

@codex review

1 similar comment
@danielhanchen

Copy link
Copy Markdown
Member

@codex review

@chatgpt-codex-connector chatgpt-codex-connector Bot left a comment

Copy link
Copy Markdown

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

💡 Codex Review

Here are some automated review suggestions for this pull request.

Reviewed commit: 77108248ae

ℹ️ About Codex in GitHub

Your team has set up Codex to review pull requests in this repo. Reviews are triggered when you

  • Open a pull request for review
  • Mark a draft as ready
  • Comment "@codex review".

If Codex has suggestions, it will comment; otherwise it will react with 👍.

Codex can also answer questions or update the PR. Try commenting "@codex address that feedback".

Comment on lines +700 to +703
const status = await pageCall(tab, { op: "status" });
const keys = ["width", "height", "scrollX", "scrollY", "scrolls", "doc"] as const;
if (keys.some((key) => status[key] !== shot[key])) return STALE_SHOT;
return { x: x * shot.scale, y: y * shot.scale };

Copy link
Copy Markdown

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

P2 Badge Invalidate screenshot points after layout mutations

When the DOM changes without a resize or scroll—for example, a carousel advances or an ad inserts content between the screenshot and the click—every key checked here remains unchanged, so the screenshot coordinates are accepted even though they may now point at a different control. The subsequent description and signature checks only bind the action to the element currently at that point, not the element the model saw in the screenshot, allowing an unintended button or link to be clicked. Track a mutation/layout generation with the screenshot and reject coordinates when it changes.

Useful? React with 👍 / 👎.

Copy link
Copy Markdown
Member

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Not changing: the point is described and gated on what is there at click time, and the click and press refuse if that element changes after the check. A mutation counter would make point clicks refuse on any page with a clock, ticker or animation.

Comment on lines +677 to +678
mouse(el, "pointermove", at, buttons);
mouse(el, "mousemove", at, buttons);

Copy link
Copy Markdown

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

P2 Badge Use real pointer movement for CSS hover interactions

browser_move_mouse only dispatches synthetic pointer and mouse events through dispatchEvent; these events can invoke JavaScript listeners but do not move the browser's pointing device or update the :hover pseudo-class. Consequently, common menus implemented purely with CSS such as .menu:hover .submenu never open even though this tool explicitly advertises hover menus as a use case. The movement path needs native/trusted pointer injection, or the tool must avoid claiming support for CSS-hover interactions.

Useful? React with 👍 / 👎.

Copy link
Copy Markdown
Member

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Known limit, stated in the PR: synthetic events cannot set :hover without trusted input injection. Menus driven by JavaScript hover handlers, the case the tool covers, open.

chatgpt-codex-connector[bot]

This comment was marked as resolved.

@unslothai unslothai deleted a comment from chatgpt-codex-connector Bot Oct 13, 2026
@unslothai unslothai deleted a comment from chatgpt-codex-connector Bot Oct 13, 2026
@unslothai unslothai deleted a comment from chatgpt-codex-connector Bot Oct 13, 2026
@unslothai unslothai deleted a comment from chatgpt-codex-connector Bot Oct 13, 2026
@danielhanchen

Copy link
Copy Markdown
Member

@codex review

1 similar comment
@danielhanchen

Copy link
Copy Markdown
Member

@codex review

@chatgpt-codex-connector

Copy link
Copy Markdown

Codex Review: Didn't find any major issues. Breezy!

Reviewed commit: 50e577a9df

ℹ️ About Codex in GitHub

Your team has set up Codex to review pull requests in this repo. Reviews are triggered when you

  • Open a pull request for review
  • Mark a draft as ready
  • Comment "@codex review".

If Codex has suggestions, it will comment; otherwise it will react with 👍.

Codex can also answer questions or update the PR. Try commenting "@codex address that feedback".

danielhanchen pushed a commit to danielhanchen/unsloth-staging-2 that referenced this pull request Oct 13, 2026
danielhanchen pushed a commit to danielhanchen/unsloth-staging-2 that referenced this pull request Oct 13, 2026
@danielhanchen
danielhanchen merged commit 2c1923e into main Oct 13, 2026
@danielhanchen
danielhanchen deleted the studio-browser-pointer-actions branch October 13, 2026 09:47
danielhanchen added a commit that referenced this pull request Oct 13, 2026
…he browser panel (#13532)

* Studio: fix compressed pages, router paths and early empty reads in the browser panel

* Keep a page's own base fixed when its router moves

* Count an empty base href as the page's own base

* Studio: name the page's open request count requests, not pending

The browser pointer and script tools (#13505) use AgentAnswer.pending as a
boolean for a script still running; a numeric pending here would merge into
the same type.

* Studio: shorten comments in the browser page wait

* Studio: keep Forward on a routed reload and an XHR count through a refused send

Reload at the router's address now swaps the entry in place instead of
truncating the pages ahead, and a second send() the browser refuses no longer
ends the count of the request still in flight.

* Studio: give a changing page its DOM allowance from when its requests close

* Studio: count a page's quiet from when its last request closed

---------

Co-authored-by: Daniel Han <[email protected]>
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment

Projects

None yet

Development

Successfully merging this pull request may close these issues.

2 participants