Skip to main content

PageSession

Enum PageSession 

Source
pub enum PageSession {
    Cdp(CdpPage),
    Bidi(BidiPage),
}
Expand description

A bound page-level session. Variants are not constructed directly outside this module; use PageSession::attach.

Variants§

§

Cdp(CdpPage)

§

Bidi(BidiPage)

A BiDi page session. The client is shared via Arc so the MCP server can keep a single persistent BiDi session across many tool calls (Firefox limits a browser to one BiDi session at a time).

Implementations§

Source§

impl PageSession

Source

pub async fn attach( endpoint: &str, engine: Engine, url_regex: Option<&str>, ) -> Result<Self>

Attach to a fresh page session over engine.

If url_regex is Some, the first page target whose URL matches is selected; otherwise the first page (or top-level browsing context) is used.

Source

pub async fn from_bidi_cache( client: Arc<BidiClient>, url_regex: Option<&str>, ) -> Result<Self>

Build a BiDi session from a pre-opened, possibly cached client.

The MCP server uses this to share one BiDi client across tool calls; session.new is invoked only when the client was freshly opened (the caller is expected to have done so).

Source

pub async fn attach_for_origin( endpoint: &str, engine: Engine, origin: &str, ) -> Result<Self>

Attach to (or create) a page whose document origin matches origin.

Strategy:

  1. List existing page targets / browsing contexts.
  2. If any has the same origin as origin, attach to it.
  3. Otherwise create a new tab navigated to the origin’s root and attach to that tab.

origin is parsed for its scheme, host, and port; path/query/fragment are ignored when comparing existing target URLs.

Source

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

Evaluate expression in the page’s main world.

await_promise = true mirrors Runtime.evaluate({awaitPromise:true}) and is appropriate for fetch / promise-returning code. The returned value is the raw result.value from CDP / BiDi after returnByValue.

Equivalent to evaluate_with_timeout with timeout = None (bounded only by the upstream client’s protocol timeout, currently 30 s). Prefer the bounded form in any path where the renderer’s responsiveness is uncertain — see the module docs.

Source

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

Bounded variant of evaluate.

If timeout is Some, the call races the upstream send against a tokio::time::sleep. On expiry, returns a typed SessionError::TabHung tagged with the target’s id and URL — this is the catch-all for the alive-but-unresponsive renderer case that has no protocol event signal (service-worker-paused page, JS infinite loop, modal dialog, devtools-paused, embedded admin UIs whose renderer ignores Runtime.evaluate).

On the CDP arm, the in-flight Runtime.evaluate is additionally raced against the renderer-crash events (Target.targetCrashed / Inspector.targetCrashed) for this target/session — a matching event short-circuits the call with a typed SessionError::TabCrashed instead of waiting for the timeout. BiDi has no equivalent protocol event; a context crash surfaces as no such frame/context on the next request and is classified as TargetGone by the client layer.

If timeout is None, the call is bounded only by the underlying client’s protocol timeout (CDP: 30 s, BiDi: 30 s).

Source

pub fn target_id(&self) -> Option<String>

Engine-specific target id for diagnostics (CDP targetId, BiDi browsing context id).

Source

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

Navigate the current page to url.

Source

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

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

The age is measured from the document’s performance.timeOrigin. about:blank, chrome://, devtools://, and other non-web pages are left untouched.

Source

pub async fn screenshot(&self, full_page: bool) -> Result<String>

Capture a PNG screenshot of the current page; returns base64 data.

Source

pub fn engine(&self) -> Engine

Engine this session is bound to.

Source

pub async fn close(self)

Release the underlying connection. For BiDi sessions that this PageSession opened, also calls session.end so that Firefox (which enforces one BiDi session per browser) accepts a fresh session.new on the next invocation.

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> 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, 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