BrowserInstance

Struct BrowserInstance 

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

A managed browser instance with health tracking.

Wraps a chromiumoxide [Browser] and an async handler task. Always call BrowserInstance::shutdown (or drop) after use to release OS resources.

Implementations§

Source§

impl BrowserInstance

Source

pub async fn launch(config: BrowserConfig) -> Result<Self>

Launch a new browser instance using the provided BrowserConfig.

All configured anti-detection arguments (see BrowserConfig::effective_args) are passed at launch time.

§Errors
§Example
use stygian_browser::{BrowserConfig, browser::BrowserInstance};

let instance = BrowserInstance::launch(BrowserConfig::default()).await?;
Source

pub const fn is_healthy_cached(&self) -> bool

Returns true if the browser is currently considered healthy.

This is a cached value updated by BrowserInstance::health_check.

Source

pub async fn is_healthy(&mut self) -> bool

Actively probe the browser with a CDP request.

Sends Browser.getVersion and waits up to cdp_timeout. Updates the internal healthy flag and returns the result.

§Example
use stygian_browser::{BrowserConfig, browser::BrowserInstance};

let mut instance = BrowserInstance::launch(BrowserConfig::default()).await?;
assert!(instance.is_healthy().await);
Source

pub async fn health_check(&mut self) -> Result<()>

Run a health check and return a structured Result.

Pings the browser with the CDP Browser.getVersion RPC.

Source

pub const fn browser(&self) -> &Browser

Access the underlying chromiumoxide [Browser].

Source

pub const fn browser_mut(&mut self) -> &mut Browser

Mutable access to the underlying chromiumoxide [Browser].

Source

pub fn id(&self) -> &str

Instance ID (ULID) for log correlation.

Source

pub fn uptime(&self) -> Duration

How long has this instance been alive.

Source

pub const fn config(&self) -> &BrowserConfig

The config snapshot used at launch.

Source

pub async fn shutdown(self) -> Result<()>

Gracefully close the browser.

Sends Browser.close and waits up to cdp_timeout. Any errors during tear-down are logged but not propagated so the caller can always clean up.

§Example
use stygian_browser::{BrowserConfig, browser::BrowserInstance};

let mut instance = BrowserInstance::launch(BrowserConfig::default()).await?;
instance.shutdown().await?;
Source

pub async fn new_page(&self) -> Result<PageHandle>

Open a new tab and return a crate::page::PageHandle.

The handle closes the tab automatically when dropped.

§Errors

Returns BrowserError::CdpError if a new page cannot be created.

§Example
use stygian_browser::{BrowserConfig, browser::BrowserInstance};

let mut instance = BrowserInstance::launch(BrowserConfig::default()).await?;
let page = instance.new_page().await?;
drop(page);
instance.shutdown().await?;

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.

§

impl<T> Instrument for T

§

fn instrument(self, span: Span) -> Instrumented<Self>

Instruments this type with the provided [Span], returning an Instrumented wrapper. Read more
§

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.

§

impl<T> PolicyExt for T
where T: ?Sized,

§

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
§

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

impl<V, T> VZip<V> for T
where V: MultiLane<T>,

§

fn vzip(self) -> V

§

impl<T> WithSubscriber for T

§

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
§

fn with_current_subscriber(self) -> WithDispatch<Self>

Attaches the current default Subscriber to this type, returning a [WithDispatch] wrapper. Read more