Skip to content

Hide Browser REPL automation from page scripts and humanize its input - #529

Open
rgarcia wants to merge 2 commits into
mainfrom
hypeship/repl-stealth-humanize
Open

rgarcia wants to merge 2 commits into
mainfrom
hypeship/repl-stealth-humanize

Conversation

@rgarcia

@rgarcia rgarcia commented Nov 29, 2026 •

Copy link
Copy Markdown
Contributor

Summary

Pages could tell the Browser REPL was driving them. This PR removes three of those signals and makes the REPL's input look human by default.

1. No Runtime.enable

enableDomains no longer enables the Runtime domain. With it enabled, Chromium previews every console argument for the client, and a page can observe that preview through getters on the logged object. Nothing in the REPL consumed Runtime.* events. Evaluation works without the domain, and helper code gets its context from Page.createIsolatedWorld (see 2).

Custom WebMCP also stops enabling it. Runtime.bindingCalled is delivered without the domain: a binding added with executionContextName fires its event and stays invisible to the page's main world.

2. Element helpers run in an isolated world

waitForElement, waitForLoad, pageInfo, click/fillInput target resolution, and the backend-node helpers (DOM.resolveNode with executionContextId) evaluate in an isolated world on the attached target's main frame. The world shares the DOM but not the page's globals or prototypes, so page scripts that wrap methods like querySelectorAll, getBoundingClientRect or scrollIntoView no longer see helper calls, and can't read helper source through Function.caller.

BrowserReplCdpClient caches one world per attached document, drops it on a main-frame Page.frameNavigated, and recreates it once if a command reports a missing context (the command never ran, so the retry can't repeat side effects).

js() still evaluates in the page's own world, because callers use it to read page state. Its help text says so and points to the helpers for element work.

3. Humanized input by default

humanize.ts ports the computer API's lib/mousetrajectory (Bezier path with jitter and ease-out) and lib/typinghumanizer (word-chunked cadence, longer pauses between words and after sentences).

  • click moves along a curved path from the pointer's last position on that target (a random viewport point the first time) and holds each button 60–120 ms. Points run on a wall-clock schedule and overdue points are skipped, so slow mouseMoved acknowledgements (~40 ms each) mean fewer events, not a longer move. A full-screen click takes ~1 s. For element targets, the click presses only while the element is still under the parked pointer; otherwise it moves to the element again, within the original timeoutSec.
  • scroll moves the pointer to the wheel position first, and rejects non-finite coordinates.
  • typeText sends key presses instead of Input.insertText; \n presses Enter.
  • fillInput types the same way and no longer dispatches synthetic input/change events. Clearing (select-all, Backspace) takes no pauses.
  • pressKey holds the key between key-down and key-up.

Typing pauses shrink to fit the cell's execution deadline, budgeting for the remaining keys' command time as measured so far, and command acknowledgement time counts toward the gap between keys. Path sampling is capped, so a huge coordinate can't allocate in proportion to its distance.

Timing differs from the computer API: the mouse step averages 10 ms instead of 20 ms and the path is capped at 80 points, which keeps clicks around a second.

4. Custom WebMCP leaves pages alone when no tools exist

Previously, every REPL start attached to each open http(s) page, enabled the Runtime domain there, created its isolated world, and left window.__kernelCustomWebMCPPage behind, even with no custom tools. Now:

  • A clean start with no custom tools touches no page.
  • Before tools are installed on pages, a marker file next to the REPL socket records that registrations may exist. If the REPL dies abruptly, the next one finds the marker and sweeps open pages as before.
  • The marker is cleared only after every open page was reached and both its main-world runtime and its isolated world were disposed; a failed attach, world setup, or dispose keeps it and retries. A graceful reset clears it under the same conditions.
  • dispose deletes the page globals.

Verification

  • make test-runtime: 74 pass. New tests cover the trajectory and typing math, the helper-world cache and retry, the absence of Runtime.enable, click/typing command sequences, re-checking the target under the pointer, deadline fitting with a fake clock and nonzero command latency, and the custom WebMCP marker across failed attach, failed world setup, failed dispose, and graceful reset. Each regression test was confirmed to fail against the code before its fix.
  • go vet ./cmd/api/... and go test ./cmd/api/api/ pass. The fake CDP server answers Page.createIsolatedWorld. TestBrowserReplRetriesCommandOnFreshConnectionClose is intermittently flaky in full-package runs on main as well, and passes alone.
  • Live check: built the bundle and swapped it into a production headful browser (Chrome 156).
    • The console-preview getter probe no longer fires.
    • Page wrappers on querySelectorAll, elementFromPoint, scrollIntoView, getBoundingClientRect, checkVisibility, focus and similar recorded zero calls across waitForElement, waitForLoad, pageInfo, selector and accessibility-node click, fillInput, typeText and scroll.
    • All dispatched events were isTrusted; fillInput replaced existing text correctly.
    • Custom WebMCP cdp and page tools invoked successfully (and, in an earlier run, through the page-side binding); removing them left no globals on the page.
  • The Docker-based e2e suite was not run.

Not covered

The passkey hook (lib/webauthnhook, while a passkey is armed) and telemetry (lib/cdpmonitor, when enabled) still enable the Runtime domain on their own connections.

Reviewed with sol-loop: 6 rounds on extra-high reasoning. Sol verdict: approved.

Stop enabling the Runtime domain, which made Chromium preview console
arguments in a way pages can observe. Run element helpers in an isolated
world so page scripts cannot see or intercept them. Move the pointer along
curved paths, hold buttons and keys, and type at a human pace, reusing the
computer API's trajectory and typing cadence. Drop the synthetic input and
change events from fillInput, and stop custom WebMCP from touching pages
when no custom tools are registered.

@cursor cursor 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.

Stale Bugbot comment from a previous run.

Comment thread server/runtime/humanize.ts Resolved
Comment thread server/runtime/browser-helpers.ts Resolved
Recover stale custom WebMCP registrations after an abrupt REPL exit with a
dirty marker that is cleared only once every open page, including its
isolated world, has been cleaned. Clear it on a graceful reset too.

Check that an element is still under the parked pointer before pressing,
within the original actionability deadline. Bound pointer path sampling and
reject non-finite scroll coordinates. Fit typing pauses to the execution
deadline using measured key command latency, and take no pauses while
clearing a field.
@rgarcia
rgarcia requested a review from JonnyShuali November 29, 2026 21:02

@cursor cursor 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.

Cursor Bugbot has reviewed your changes using default effort and found 2 potential issues.

Fix All in Cursor

❌ Bugbot Autofix is OFF. To automatically fix reported issues with cloud agents, enable autofix in the Cursor dashboard.

Reviewed by Cursor Bugbot for commit f14fb1a. Configure here.

}
if (at) {
const parked = deepElementFromPoint(at.x, at.y);
return parked && composedContains(el, parked) ? { status: 'ready', x: at.x, y: at.y } : { status: 'off target' };

Copy link
Copy Markdown

Choose a reason for hiding this comment

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

Parked click recheck requeries selector

Medium Severity

The post-move click check re-runs unique-match selector resolution before hit-testing the parked point. A hover that reveals another visible match is treated as multiple or can retarget a different element instead of asking whether the original target is still under the pointer.

Additional Locations (1)
Fix in Cursor Fix in Web

Reviewed by Cursor Bugbot for commit f14fb1a. Configure here.

// Without its isolated world, a page may still hold CDP tool
// registrations from an earlier process; only disposing that world
// shows they are gone.
const isolatedDisposed = page.contextId !== null &&

Copy link
Copy Markdown

Choose a reason for hiding this comment

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

Recovery sweep misses leftover CDP world

Medium Severity

The dirty-marker recovery creates a new isolated world and treats disposing that world as proof leftover CDP tools are gone. Page.createIsolatedWorld does not return the previous process's context, so old document.modelContext registrations in the leftover world can survive while the marker is cleared.

Additional Locations (2)
Fix in Cursor Fix in Web

Reviewed by Cursor Bugbot for commit f14fb1a. Configure here.

This branch has not been deployed

No deployments
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment

Labels

None yet

Projects

None yet

Development

Successfully merging this pull request may close these issues.

1 participant