Skip to main content

TabBackend

Enum TabBackend 

Source
pub enum TabBackend {
    Cdp(Arc<CdpClient>),
    Bidi(Arc<BidiClient>),
}
Expand description

Engine-agnostic tab operations. Two variants because CDP and BiDi have different protocols and clients; the methods abstract over the difference.

Variants§

Implementations§

Source§

impl TabBackend

Source

pub async fn shutdown(&self)

Release the engine session before the client goes away. Firefox does not end a BiDi session when its WebSocket closes, so a backend that is dropped without session.end leaves the browser refusing every later session.new (“Maximum number of active sessions”). CDP has nothing to release. Best-effort and idempotent.

Source

pub async fn create_tab(&self, url: &str) -> Result<String>

Create a fresh top-level tab. Returns the engine-specific id (CDP targetId, BiDi context) the registry stores verbatim. url defaults to about:blank.

Source

pub async fn close_tab(&self, target_id: &str) -> Result<()>

Close a tab by id. Best-effort — both CDP and BiDi handle a missing id gracefully, and the caller’s intent (“this tab is gone”) is satisfied either way.

Source

pub async fn navigate(&self, target_id: &str, url: &str) -> Result<()>

Navigate an existing tab to url. CDP requires attaching a transient session; BiDi takes the context id directly.

Source

pub async fn show_tab(&self, target_id: &str) -> Result<()>

Make a tab visible and focused inside the browser window. This is intentionally explicit: normal automation creates/navigates tabs in the background so agents don’t steal the user’s foreground app unless they need interactive debugging or login.

Source

pub async fn target_for_show(&self) -> Result<String>

Return a tab suitable for show: prefer an existing live tab, create about:blank if the browser currently has none.

Source

pub async fn ensure_fresh( &self, target_id: &str, max_age: Duration, ) -> Result<()>

Reload an old HTTP(S) tab before reading auth-sensitive page state.

The age is measured from the document’s performance.timeOrigin. Non-web pages such as about:blank are left untouched.

Source

pub async fn live_target_ids(&self) -> Result<HashSet<String>>

Snapshot of every live top-level tab id in the browser. Used by the registry’s sweep-on-read to drop rows whose target no longer exists.

Source

pub async fn live_targets(&self) -> Result<Vec<LiveTarget>>

Snapshot of every live top-level tab with id + URL + title. Used by tab list --all to merge the named-tab registry with the browser’s view of the world. CDP filters to type == "page"; BiDi returns every top-level browsing context.

Source

pub async fn resolve_or_create_for_origin(&self, url: &str) -> Result<String>

Resolve a target whose document origin matches url’s origin, reusing a live tab already on that origin if one exists and creating one rooted at the origin otherwise. Returns the engine-specific id.

This is the routing primitive for browser_fetch: running the in-page fetch from a same-origin document is what lets cookies and credentials propagate and lets the response bypass CORS. Routing a fetch through an about:blank scratch tab (this backend’s default active tab) gives it an opaque origin, which silently breaks authenticated and CORS-sensitive requests — see cli::fetch’s origin-bound path for the same contract.

Source

pub async fn evaluate( &self, target_id: &str, expression: &str, await_promise: bool, timeout: Duration, ) -> Result<Value>

Evaluate expression in target_id’s main world, returning the raw result value (after returnByValue). Bounded by timeout; expiry returns typed SessionError::TabHung.

CDP path attaches a transient session, calls Runtime.evaluate, detaches. BiDi path calls script.evaluate against the context. On BiDi, await_promise is ignored — BiDi always awaits per script.evaluate semantics.

Source

pub async fn screenshot( &self, target_id: &str, opts: &ScreenshotOptions, ) -> Result<String>

Capture a screenshot of target_id and return base64-encoded bytes.

CDP path attaches a transient session, calls Page.captureScreenshot, detaches. BiDi path calls browsingContext.captureScreenshot — the BiDi protocol always captures the viewport (no full_page equivalent) and has no downscale, so full_page and max_width are honoured only on CDP.

When opts.clip is Some({x, y, width, height}) (document coordinates, as produced by crate::dom::scripts::GET_CLIP_RECT_JS) the capture is restricted to that rectangle, which takes precedence over full_page. opts.max_width downscales through clip.scale, which needs no emulation override and no restore step.

Source

pub async fn accessibility_tree( &self, target_id: &str, depth: Option<u32>, timeout: Duration, ) -> Result<Value>

Full accessibility tree (Accessibility.getFullAXTree). depth bounds the tree the browser serialises; None means everything.

Source

pub async fn document_token( &self, target_id: &str, timeout: Duration, ) -> Result<u64>

Identity of the current document (see crate::session::input::document_token).

Source

pub async fn click_node( &self, target_id: &str, backend_node_id: u64, timeout: Duration, ) -> Result<Point>

Click the element with backend_node_id. Returns the viewport point that was clicked.

Source

pub fn ids_are_session_scoped(&self) -> bool

Whether this engine’s target ids are scoped to the connection.

Firefox mints fresh browsing-context ids for every BiDi session, so an id stored by one process means nothing to the next. CDP target ids live as long as the tab.

Source

pub async fn release(&self)

End the BiDi session, if this is one.

BiDi permits one session per browser, so a backend opened and left without ending its session makes the browser refuse every later connection with “Maximum number of active sessions” — which is exactly what a short-lived CLI command does unless it calls this. The socket itself needs no attention: the process exits.

A no-op on CDP, which is happy with many concurrent clients.

Source

pub async fn type_into_focused( &self, target_id: &str, text: &str, press_sequentially: bool, submit: bool, timeout: Duration, ) -> Result<()>

Type into whatever currently has focus.

Addresses no node, so it works from a separate process that has no access to the MCP server’s ref table — which is what lets a shell pipeline deliver a secret straight into a field.

Source

pub async fn press_key_on_tab( &self, target_id: &str, chord: &Chord, timeout: Duration, ) -> Result<()>

Press a key, with any modifiers held around it.

Keyboard input goes to whatever currently has focus, so unlike the other native actions this addresses no node.

Source

pub async fn hover_node( &self, target_id: &str, backend_node_id: u64, timeout: Duration, ) -> Result<Point>

Hover the element with backend_node_id.

Source

pub async fn type_into_node( &self, target_id: &str, backend_node_id: u64, text: &str, press_sequentially: bool, submit: bool, timeout: Duration, ) -> Result<()>

Replace the element’s content with text (see crate::session::input::type_text).

Source

pub async fn drag_nodes( &self, target_id: &str, from: u64, to: u64, timeout: Duration, ) -> Result<()>

Pointer drag from one element to another.

Source

pub async fn node_clip_rect( &self, target_id: &str, backend_node_id: u64, timeout: Duration, ) -> Result<Value>

Border box of the element in document coordinates, for clipped screenshots.

Trait Implementations§

Source§

impl Clone for TabBackend

Source§

fn clone(&self) -> TabBackend

Returns a duplicate of the value. Read more
1.0.0 (const: unstable) · Source§

fn clone_from(&mut self, source: &Self)

Performs copy-assignment from source. Read more

Auto Trait Implementations§

Blanket Implementations§

Source§

impl<T> Any for T
where T: 'static + ?Sized,

Source§

fn type_id(&self) -> TypeId

Gets the TypeId of self. Read more
Source§

impl<T> Borrow<T> for T
where T: ?Sized,

Source§

fn borrow(&self) -> &T

Immutably borrows from an owned value. Read more
Source§

impl<T> BorrowMut<T> for T
where T: ?Sized,

Source§

fn borrow_mut(&mut self) -> &mut T

Mutably borrows from an owned value. Read more
Source§

impl<T> CloneToUninit for T
where T: Clone,

Source§

unsafe fn clone_to_uninit(&self, dest: *mut u8)

🔬This is a nightly-only experimental API. (clone_to_uninit)
Performs copy-assignment from self to dest. Read more
Source§

impl<T> From<T> for T

Source§

fn from(t: T) -> T

Returns the argument unchanged.

Source§

impl<T> Instrument for T

Source§

fn instrument(self, span: Span) -> Instrumented<Self>

Instruments this type with the provided Span, returning an Instrumented wrapper. Read more
Source§

fn in_current_span(self) -> Instrumented<Self>

Instruments this type with the current Span, returning an Instrumented wrapper. Read more
Source§

impl<T, U> Into<U> for T
where U: From<T>,

Source§

fn into(self) -> U

Calls U::from(self).

That is, this conversion is whatever the implementation of From<T> for U chooses to do.

Source§

impl<T> IntoEither for T

Source§

fn into_either(self, into_left: bool) -> Either<Self, Self>

Converts self into a Left variant of Either<Self, Self> if into_left is true. Converts self into a Right variant of Either<Self, Self> otherwise. Read more
Source§

fn into_either_with<F>(self, into_left: F) -> Either<Self, Self>
where F: FnOnce(&Self) -> bool,

Converts self into a Left variant of Either<Self, Self> if into_left(&self) returns true. Converts self into a Right variant of Either<Self, Self> otherwise. Read more
Source§

impl<T> Pointable for T

Source§

const ALIGN: usize

The alignment of pointer.
Source§

type Init = T

The type for initializers.
Source§

unsafe fn init(init: <T as Pointable>::Init) -> usize

Initializes a with the given initializer. Read more
Source§

unsafe fn deref<'a>(ptr: usize) -> &'a T

Dereferences the given pointer. Read more
Source§

unsafe fn deref_mut<'a>(ptr: usize) -> &'a mut T

Mutably dereferences the given pointer. Read more
Source§

unsafe fn drop(ptr: usize)

Drops the object pointed to by the given pointer. Read more
Source§

impl<T> PolicyExt for T
where T: ?Sized,

Source§

fn and<P, B, E>(self, other: P) -> And<T, P>
where T: Sized + Policy<B, E>, P: Policy<B, E>,

Create a new Policy that returns Action::Follow only if self and other return Action::Follow. Read more
Source§

fn or<P, B, E>(self, other: P) -> Or<T, P>
where T: Sized + Policy<B, E>, P: Policy<B, E>,

Create a new Policy that returns Action::Follow if either self or other returns Action::Follow. Read more
Source§

impl<T> Same for T

Source§

type Output = T

Should always be Self
Source§

impl<T> ToOwned for T
where T: Clone,

Source§

type Owned = T

The resulting type after obtaining ownership.
Source§

fn to_owned(&self) -> T

Creates owned data from borrowed data, usually by cloning. Read more
Source§

fn clone_into(&self, target: &mut T)

Uses borrowed data to replace owned data, usually by cloning. Read more
Source§

impl<T, U> TryFrom<U> for T
where U: Into<T>,

Source§

type Error = !

The type returned in the event of a conversion error.
Source§

fn try_from(value: U) -> Result<T, !>

Performs the conversion.
Source§

impl<T, U> TryInto<U> for T
where U: TryFrom<T>,

Source§

type Error = <U as TryFrom<T>>::Error

The type returned in the event of a conversion error.
Source§

fn try_into(self) -> Result<U, <U as TryFrom<T>>::Error>

Performs the conversion.
Source§

impl<V, T> VZip<V> for T
where V: MultiLane<T>,

Source§

fn vzip(self) -> V

Source§

impl<T> WithSubscriber for T

Source§

fn with_subscriber<S>(self, subscriber: S) -> WithDispatch<Self>
where S: Into<Dispatch>,

Attaches the provided Subscriber to this type, returning a WithDispatch wrapper. Read more
Source§

fn with_current_subscriber(self) -> WithDispatch<Self>

Attaches the current default Subscriber to this type, returning a WithDispatch wrapper. Read more