Skip to main content

Browser

Struct Browser 

Source
pub struct Browser { /* private fields */ }
Expand description

Browser instance. Manages contexts, pages, and browser lifecycle.

Clone is cheap — all clones share the same underlying browser process and state via Arc. This enables exposing browser as a test fixture.

Implementations§

Source§

impl Browser

Source

pub fn from_state(state: BrowserState) -> Browser

Infra constructor: wrap a BrowserState whose ensure_browser() has already completed. BrowserType::launch is the user-facing path; this entry point exists for ferridriver-internal callers (the test runner / test fixtures / MCP server) that build a crate::options::LaunchPlan directly and need a matching Browser handle.

§Safety contract

The caller MUST have awaited state.ensure_browser() (or an equivalent ensure_instance(...) call) before handing the state in — otherwise version() will return "Unknown" until a subsequent ensure.

Source

pub fn from_shared_state(state: Arc<RwLock<BrowserState>>) -> Browser

Wrap an existing shared state as a Browser handle. Used by MCP server and other contexts that already manage browser state.

The version string is read once from the state’s default instance; if the instance has not been launched yet, version() returns "Unknown" until a subsequent ensure_browser fills it in.

Source

pub fn new_context(&self, options: Option<BrowserContextOptions>) -> ContextRef

Create a new isolated browser context. Mirrors Playwright’s browser.newContext(options?)/tmp/playwright/packages/playwright-core/types/types.d.ts:22229. Pass None for the no-options case (Playwright’s zero-arg form).

Options are stored on the shared crate::state::BrowserState::context_options registry keyed by composite session key and consumed by ContextRef::new_page as each page is opened. The registry itself is a plain std::sync::Mutex clone-handle on self so this setter stays sync regardless of whether an async writer holds the outer RwLock<BrowserState>.

Source

pub fn default_context(&self) -> ContextRef

Get the default browser context.

Source

pub fn supports_isolated_contexts(&self) -> bool

Whether this backend exposes isolated browser contexts (i.e. new_context() actually opens a fresh container vs. silently returning a handle that resolves to the persistent default).

Mirrors Playwright’s behaviour where chromium, firefox, and webkit all support multiple contexts. Stock WKWebView (ferridriver’s WebKit backend) only exposes the persistent default context — there’s no public API for additional containers without a private framework or a custom WKProcessPool fork. Callers that need to share the persistent default in that case can branch on this method.

Source

pub fn backend_kind(&self) -> BackendKind

Backend kind cached at construction. The state’s backend_kind is set once at with_plan and never mutated, so this always matches the live state.

Source

pub fn is_headless(&self) -> bool

Whether the browser was launched in headless mode. Cached at construction; the launch plan never flips this after the fact.

Source

pub async fn new_page(&self) -> Result<Arc<Page>, FerriError>

Shorthand: create a new page in the default context. Equivalent to browser.default_context().new_page().

§Errors

Returns an error if page creation fails.

Source

pub async fn new_page_with_url( &self, url: &str, ) -> Result<Arc<Page>, FerriError>

Shorthand: create a new page and navigate to URL.

§Errors

Returns an error if page creation or navigation fails.

Source

pub async fn page(&self) -> Result<Arc<Page>, FerriError>

Shorthand: get the active page in the default context. Creates a page if none exists.

§Errors

Returns an error if page creation or retrieval fails.

Source

pub async fn close( &self, opts: Option<BrowserCloseOptions>, ) -> Result<(), FerriError>

Close the browser.

Close the browser. Accepts Option<crate::options::BrowserCloseOptions> — mirrors Playwright’s browser.close({ reason }). The reason, if set, is surfaced on TargetClosed errors emitted to any in-flight operation on pages/contexts from this browser. Pass None for the common no-options case.

§Errors

Returns an error if the browser cannot be closed cleanly.

Source

pub fn state(&self) -> &Arc<RwLock<BrowserState>>

Access the internal state (for MCP server integration).

Source

pub fn contexts(&self) -> Vec<ContextRef>

List all browser contexts. Sync — mirrors Playwright’s browser.contexts(): BrowserContext[]. Reads the in-memory name registry (default + every new_context); no state lock, no per-page round-trip.

Source

pub fn version(&self) -> &str

Real product version string for the running browser — mirrors Playwright’s synchronous browser.version().

Captured once from CDP Browser.getVersion().product at handshake (e.g. "HeadlessChrome/120.0.6099.109" or "Chrome/120.0.6099.109"). For WebKit returns "WebKit" until we plumb WKWebView’s version through the IPC; for BiDi returns "Firefox". Returns "Unknown" if the handshake did not complete before the Browser handle was constructed.

Source

pub fn is_connected(&self) -> bool

Whether the browser is connected. Sync — mirrors Playwright’s browser.isConnected(): boolean.

Trait Implementations§

Source§

impl Clone for Browser

Source§

fn clone(&self) -> Browser

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> FromRef<T> for T
where T: Clone,

Source§

fn from_ref(input: &T) -> T

Converts to this type from a reference to the input type.
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> PolicyExt for T
where T: ?Sized,

Source§

fn and<P, B, E>(self, other: P) -> And<T, P>
where T: 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: 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
Source§

impl<A, B, T> HttpServerConnExec<A, B> for T
where B: Body,