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
impl TabBackend
Sourcepub async fn create_tab(&self, url: &str) -> Result<String>
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.
Sourcepub async fn close_tab(&self, target_id: &str) -> Result<()>
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.
Navigate an existing tab to url. CDP requires attaching a
transient session; BiDi takes the context id directly.
Sourcepub async fn show_tab(&self, target_id: &str) -> Result<()>
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.
Sourcepub async fn target_for_show(&self) -> Result<String>
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.
Sourcepub async fn ensure_fresh(
&self,
target_id: &str,
max_age: Duration,
) -> Result<()>
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.
Sourcepub async fn live_target_ids(&self) -> Result<HashSet<String>>
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.
Sourcepub async fn live_targets(&self) -> Result<Vec<LiveTarget>>
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.
Sourcepub async fn resolve_or_create_for_origin(&self, url: &str) -> Result<String>
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.
Sourcepub async fn evaluate(
&self,
target_id: &str,
expression: &str,
await_promise: bool,
timeout: Duration,
) -> Result<Value>
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.
Sourcepub async fn screenshot(
&self,
target_id: &str,
full_page: bool,
clip: Option<Value>,
) -> Result<String>
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
impl Clone for TabBackend
Source§fn clone(&self) -> TabBackend
fn clone(&self) -> TabBackend
1.0.0 (const: unstable) · Source§fn clone_from(&mut self, source: &Self)
fn clone_from(&mut self, source: &Self)
source. Read moreAuto Trait Implementations§
impl !RefUnwindSafe for TabBackend
impl !UnwindSafe for TabBackend
impl Freeze for TabBackend
impl Send for TabBackend
impl Sync for TabBackend
impl Unpin for TabBackend
impl UnsafeUnpin for TabBackend
Blanket Implementations§
Source§impl<T> BorrowMut<T> for Twhere
T: ?Sized,
impl<T> BorrowMut<T> for Twhere
T: ?Sized,
Source§fn borrow_mut(&mut self) -> &mut T
fn borrow_mut(&mut self) -> &mut T
Source§impl<T> CloneToUninit for Twhere
T: Clone,
impl<T> CloneToUninit for Twhere
T: Clone,
Source§impl<T> Instrument for T
impl<T> Instrument for T
Source§fn instrument(self, span: Span) -> Instrumented<Self> ⓘ
fn instrument(self, span: Span) -> Instrumented<Self> ⓘ
Source§fn in_current_span(self) -> Instrumented<Self> ⓘ
fn in_current_span(self) -> Instrumented<Self> ⓘ
Source§impl<T> IntoEither for T
impl<T> IntoEither for T
Source§fn into_either(self, into_left: bool) -> Either<Self, Self> ⓘ
fn into_either(self, into_left: bool) -> Either<Self, Self> ⓘ
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 moreSource§fn into_either_with<F>(self, into_left: F) -> Either<Self, Self> ⓘ
fn into_either_with<F>(self, into_left: F) -> Either<Self, Self> ⓘ
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