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?;