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 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, full_page: bool, clip: Option<Value>, ) -> Result<String>

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

CDP path attaches a transient session, calls Page.captureScreenshot({format:"png", captureBeyondViewport:full_page}), detaches. BiDi path calls browsingContext.captureScreenshot — the BiDi protocol always captures the viewport (no full_page equivalent), so full_page is honoured only on CDP.

When 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.

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 = Infallible

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

fn try_from(value: U) -> Result<T, <T as TryFrom<U>>::Error>

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