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
impl PageSession
Sourcepub async fn attach(
endpoint: &str,
engine: Engine,
url_regex: Option<&str>,
) -> Result<Self>
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.
Sourcepub async fn from_bidi_cache(
client: Arc<BidiClient>,
url_regex: Option<&str>,
) -> Result<Self>
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).
Sourcepub async fn attach_for_origin(
endpoint: &str,
engine: Engine,
origin: &str,
) -> Result<Self>
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:
- List existing page targets / browsing contexts.
- If any has the same origin as
origin, attach to it. - 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.
Sourcepub async fn evaluate(
&self,
expression: &str,
await_promise: bool,
) -> Result<Value>
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.
Navigate the current page to url.
Sourcepub async fn screenshot(&self, full_page: bool) -> Result<String>
pub async fn screenshot(&self, full_page: bool) -> Result<String>
Capture a PNG screenshot of the current page; returns base64 data.
Auto Trait Implementations§
impl !Freeze for PageSession
impl !RefUnwindSafe for PageSession
impl Send for PageSession
impl Sync for PageSession
impl Unpin for PageSession
impl UnsafeUnpin for PageSession
impl !UnwindSafe for PageSession
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> 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