Skip to main content

Module tabs

Module tabs 

Source
Expand description

Named-tab orchestration: SQLite + the engine-agnostic TabBackend working together.

The registry layer (crate::registry::tabs) is pure SQL CRUD. This module adds the logic the agent contract actually requires:

  • Get-or-create: tab_open(_, name, url) returns an existing live tab under that name, or creates a fresh about:blank (or the given url) and registers it.
  • Navigate-on-mismatch: if the existing tab’s last_url doesn’t match the requested url, run navigate first.
  • Sweep-on-read: stale rows whose target_id no longer exists in the live browser are dropped before they’re returned to the caller.
  • Budget pressure: when daemon-created rows exceed HARD_CAP, the LRU is closed and recycled.
  • Cute names: agents who pass no --name get tab-<cute-word> from the same generator that names browsers.

The same code path serves CDP (Chromium) and BiDi (Firefox) browsers via TabBackend — CDP targetId and BiDi context are both opaque ids stored in the tabs.target_id column. The registry doesn’t care which engine produced the id.

Constants§

HARD_CAP
Hard cap on daemon_created rows per browser. Hitting this triggers LRU close+recreate of the oldest daemon-created tab. Chromium itself starts to struggle around a few hundred tabs depending on RAM; 50 is comfortably under that ceiling and large enough that even busy scraping agents won’t routinely hit it.

Functions§

resolve_tab
Resolve <browser>/<name> to a live tab row for cross-command routing (eval, fetch, etc.). Returns Ok(None) if no row matches or the row’s target_id no longer exists in the browser (TabNotFound at the call site).
tab_list
tab list <browser> backend with sweep-on-read.
tab_open
Open a named tab (get-or-create), navigating if url differs from the existing tab’s last_url. Returns the up-to-date row.
with_named_tab_recovery
Run op against the named tab <browser>/<name> with one round of recover-and-retry on tab failures. Mirrors crate::session::with_scratch_recovery but for the agent-owned named-tab path.