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
impl BrowserInstance
Sourcepub async fn launch(config: BrowserConfig) -> Result<Self>
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
BrowserError::LaunchFailedif the process does not start withinconfig.launch_timeout.BrowserError::Timeoutif the browser doesn’t respond in time.
§Example
use stygian_browser::{BrowserConfig, browser::BrowserInstance};
let instance = BrowserInstance::launch(BrowserConfig::default()).await?;Sourcepub const fn is_healthy_cached(&self) -> bool
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.
Sourcepub async fn is_healthy(&mut self) -> bool
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);Sourcepub async fn health_check(&mut self) -> Result<()>
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.
Sourcepub const fn browser_mut(&mut self) -> &mut Browser
pub const fn browser_mut(&mut self) -> &mut Browser
Mutable access to the underlying chromiumoxide Browser.
Sourcepub const fn config(&self) -> &BrowserConfig
pub const fn config(&self) -> &BrowserConfig
The config snapshot used at launch.
Sourcepub async fn shutdown(self) -> Result<()>
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?;Sourcepub async fn new_page(&self) -> Result<PageHandle>
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§
impl Freeze for BrowserInstance
impl !RefUnwindSafe for BrowserInstance
impl Send for BrowserInstance
impl Sync for BrowserInstance
impl Unpin for BrowserInstance
impl UnsafeUnpin for BrowserInstance
impl !UnwindSafe for BrowserInstance
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