Files
Lahfirandvercel-v[bot] e49844de63 feat(firefox): dashboard live view, bidi module and docs (#2208)
* feat(firefox): dashboard live view, bidi module and docs

Squashed during the stack rebase onto main.

* docs(firefox): drop set device from the supported list

set device errors on Firefox, and the README and core skill already say it is unsupported.

* test(stream): use an array for the cached tabs fixture

clippy --all-targets flags the vec! as useless_vec; the test only slices it.

* fix(firefox): switch to tabs the page opens

target=_blank links and window.open left agent-browser on the old tab while Chrome follows the popup. Contexts BiDi reports with an originalOpener now become the active tab, and refs reset whenever drained events change it.

* fix(firefox): complete native HTML5 drag gestures

* fix(firefox): read the active page through BiDi

* fix(firefox): retain HAR request bodies and elapsed time

* fix(firefox): complete HTML5 drags with DOM events

* Preserve proxy settings rollback after Firefox launch failures

* Format Firefox proxy rollback regression

* Preserve Firefox and streaming documentation expectations

* fix(firefox): preserve dashboard input modifiers

* fix(firefox): restore popup openers and clear stale frames

* fix: align regression tests with integrated browser code

* style: format integrated Firefox regressions

* fix: correct docs fixtures and bound popup regression waits

* fix: apply the engine docs fixture edit once

* fix(firefox): verify restore recovery and document capture limits

* fix(firefox): preserve CLI titles while bounding tab lookups

* style: format bounded tab lookup

* test(firefox): accept the command deadline for idle waits

* test(firefox): match the clarified attach error before attach support

* ci: run pull request checks for stacked branches

* test(firefox): use the current daemon stream constructor

* test(firefox): cover selectors shared by light and shadow roots

* fix(firefox): resolve shadow refs through exact DOM ancestry

* Fix the BiDi client path in the pointer rejection test

* Remove duplicate Firefox dialog regression

* Skip unreadable Firefox frames during state save

* Format the unreadable-frame regression

* Remove the unused RDP dispatcher dependency

* Restore the owning tab when an iframe popup closes

* Format the request scope regression

* Fix renamed module references in request scope tests

* Keep stale-ref checks tied to the snapshot document

* Format snapshot document tracking

* Adapt pointer checks and snapshot tracking to BiDi APIs

* Return the snapshot result after recording its document

* Apply RDP reply matching in the renamed module

* Fail closed after a Firefox DevTools timeout

* Format fail-closed RDP timeout assertions

* Keep standard RDP replies after fail-closed timeouts

* Remove duplicate DevTools initialization after merge

* test(bidi): restore unit tests dropped when the Firefox modules moved

38 tests were lost in the move from firefox/ to bidi/. Restore them, porting the touch tap and stale-ref recovery tests to the new Origin and document-identity APIs.

* docs: drop the stale browser engine edit from the commands fixture

The page already lists firefox, so the edit no longer applies and the docs contract test fails on the missing anchor.

* docs: keep one engine-list edit for the commands page

The fixture listed the same replacement twice, so the second pass failed. Keep a single entry and leave the baseline untouched, so the route contract sees the Firefox engine list.

* docs: record the Firefox engine in the configuration fixture

The env table row changed with the engine list, so the route contract needs the matching edit.

* docs: cover the plain-text configuration sample in the fixture

The rendered sample and the table markup carry the engine list in different forms, so both need the edit.

* fix(firefox): give the dashboard live view one owner

With streaming enabled, every Firefox command asked the browser for the
tab tree and each tab's title, whether or not a dashboard was
connected, and the frame poller awaited each screenshot inline with a
30 s timeout, so one unresponsive tab stalled commands and froze prompt
tracking.

The poller is now the only code that talks to Firefox for the
dashboard and the only writer of frames, viewport status, the tab list
and the paused state. It is started once per session, works only while
a client is connected, runs captures and tab reads as child tasks with
2 s timeouts, and learns about tab changes through one watch channel.
The command path sends no BiDi request for the stream.

Dashboards now get a tab list within one poll interval of a command
instead of immediately.

* fix(firefox): start a new dashboard poller for each Firefox session

The poller was created once and reused for whatever session came next.
It listens to one session's events and stops when that session's
socket closes, so after Firefox exited and the session was relaunched,
dashboards got no frames.

A poller now knows which session it serves, and a session it does not
serve gets its own.

* fix(firefox): round live-view wheel input and reject connect

Firefox takes only integers for a wheel scroll, so a trackpad's
fractional deltas were rejected and live-view scrolling did nothing.
The wheel builder now rounds the position and deltas for every caller.

`connect` with `--engine firefox` attached to Chrome over CDP because
the engine was set by the settings patch and dropped by the launch
patch. The launch patch now carries it, so `connect` is rejected like
`--cdp`. The docs no longer say it drives Chrome.

* fix(stream): serve /api/tabs only to same-origin and local requests

A session's HTTP server returned its cached tab titles and URLs from
`/api/tabs` with a wildcard CORS header and no check of the request, so
any page that could reach the loopback port could read them. Firefox
sessions now fill that cache too.

`/api/tabs` is served only when the request's `Origin` names the same
loopback authority as `Host`, or when there is no `Origin` and `Host` is
a loopback authority, which also stops a DNS-rebinding page. Other
requests get 403. The response no longer carries the wildcard header; a
same-origin request gets its own origin reflected.

The dashboard reads tabs through its server-side proxy, which sends a
loopback `Host` and no `Origin`, so it is unaffected.

* test(firefox): point the stalled-tab test at the bidi module

The merge from laf/bidi-network-emulation brought in a test that still
named the firefox module, which this branch renames to bidi.

* fix(firefox): cap live view frames and validate options before a relaunch closes Firefox

AGENT_BROWSER_STREAM_MAX_WIDTH and AGENT_BROWSER_STREAM_MAX_HEIGHT did
nothing on Firefox, which captures frames at the viewport size. Frames
larger than the cap are now scaled down in proportion before they are
published.

A relaunch closed the running Firefox and only then checked the new
settings, so an option Firefox rejects cost the open pages. The settings
are now checked first, and a rejected option leaves the browser open.

* refactor(firefox): drop duplicate live view tests, helpers and docs

Removes a copied upload helper, two forwarding accessors, tests that
repeat another test's assertions, and docs passages that repeat the
Firefox engine page. No behaviour change.

* test(firefox): give the idle live view test a session that already collects bodies

A dashboard turns request tracking on, so the session adds its body
collector on the first command. The test asserts an idle live view asks
Firefox for nothing, so its session now starts with the collector in
place.

* test(firefox): restore the connect test and two docs passages

The cleanup removed the only test that drives the explicit launch
command with a CDP target into the Firefox check, the Obscura sentence
saying later commands keep the engine, and the guidance on when to
choose Firefox. None of the three is stated or tested anywhere else.

* docs(firefox): note auth challenges, closed shadow roots and transformed iframes

Firefox now cancels an auth challenge it has no credentials for, so the guide says what the page shows and how to authenticate. It also names two limits: controls in closed shadow roots cannot be acted on, and pointer commands can miss inside an iframe with a CSS transform.

* docs(firefox): state that the Windows DevTools port is open to local accounts

On Windows the daemon can only give Firefox's DevTools server a loopback
TCP port, and Firefox has no way to restrict it to one account or
authenticate its clients. The Firefox page now says so and tells readers
to use the engine on Windows only where they trust every local account.

* Take the relaunch validation from laf/bidi-network-emulation before merging it

Brings in the base branch's launch validation hunks as they are so the merge that follows is conflict-free; the next commit reconciles them with this branch's validate_firefox_launch.

Co-authored-by: vercel-v[bot] <353008837+vercel-v[bot]@users.noreply.github.com>

* Bring in laf/bidi-network-emulation's relaunch validation and snapshot hint fixes

Content of merging laf/bidi-network-emulation, with the relaunch pre-check reconciled with this branch's validate_firefox_launch and the Firefox hint pass carried to bidi/snapshot.rs. Pushed as a single commit because the signed-commit rule and GitHub's merge endpoint (no rename detection for firefox/ to bidi/) leave no way to push the two-parent merge from here. Running git merge -s ours origin/laf/bidi-network-emulation records the ancestry without changing the tree.

Co-authored-by: vercel-v[bot] <353008837+vercel-v[bot]@users.noreply.github.com>

* fix(firefox): record the pointer position from the browser, not from page scripts

The pointer position is kept in top-level coordinates and later used by coordinate-free mouse commands. It was built from two values computed in the page's own realm: the element's point inside its frame, and a frame offset read through window.frameElement and window.parent, with a page-reported flag that skipped the browser-based mapping. A cross-origin iframe can redefine all of those, so hovering one of its refs could leave the pointer on a control in the parent, and the next mouse down and up would press it.

The point inside the frame is now read in the isolated sandbox, and every frame hop is mapped from the browser's context tree and a verified frame handle read in the parent's sandbox. The page-realm mapper and the DOM-scanning mapper are gone, and the click path shares the frame lookup. The viewport edge used to plan the pointer path is read in the sandbox too.

Adds a unit test where the page answers every call in its own realm with coordinates aimed at a parent control; the recorded position must still come from the sandbox and the frame handle.

* fix(console): bound the console and page error history by memory, not only by count

The tracker kept the latest 1,000 console messages and 1,000 page errors whatever their size, so a page that logged multi-megabyte messages could grow the daemon by gigabytes. Both engines feed it, and Firefox now subscribes to page logs at launch.

The tracker now cuts each message or error to 64 KiB of text, marked with the number of bytes cut, replaces console arguments over 64 KiB with a note, and drops the oldest entries once the console messages, or the page errors, hold about 8 MiB. One bounded store handles both lists and the lists are read-only outside it. Callers pass arguments by reference, so an oversized value is never copied first.

With a page logging 3 MiB messages, the daemon held 447 MiB on Firefox and 792 MiB on Chrome before, and 73 MiB and 193 MiB after. The console command returned 198 MB and 314 MB before, and about 4 MB and 6.5 MB after.

Adds unit tests for the cut, the note, the byte bound with oldest-first eviction, and page errors. The limits are documented in the console and errors help, the debugging page and the command reference.

* fix(firefox): serve fresh /api/tabs for Firefox sessions without a WebSocket client

- Add a single-flight on-demand tab refresh channel from GET /api/tabs to the active Firefox poller when no WebSocket dashboard client is connected
- Clear cached tabs when attaching a new Firefox BiDi client so stale Chrome tabs are not served
- Keep idle Firefox sessions free of background polling when neither a WebSocket client nor /api/tabs requests tabs

* test(firefox): accept default-denied geolocation before granting in loaded iframe E2E

* docs(firefox): note that closed shadow root refs are actionable

* Align actions.rs, bidi/client.rs and bidi/forms.rs ahead of laf/bidi-network-emulation merge

* Temporarily align renamed firefox/ paths ahead of laf/bidi-network-emulation merge

* Resolve merge, sync dashboard live view on pin changes, and document Firefox form commands

Resolve the merge of laf/bidi-network-emulation across actions.rs and cli/src/native/bidi/.

Reconcile the dashboard Firefox live target at command and tick boundaries so disabling --pin-tab after a closed pinned tab re-points dashboard input and live frames to the surviving tab.

Document shared Firefox form prechecks, warnings, select --by, and check behavior in firefox.mdx, commands.mdx, skill-data/core/references/commands.md, CLI help, and MCP tool descriptions.

---------

Co-authored-by: vercel-v[bot] <353008837+vercel-v[bot]@users.noreply.github.com>
2026-11-24 15:10:53 -08:00
..