pub struct Browser { /* private fields */ }Expand description
A handle to a Chrome/Chromium browser instance.
§Example
use ferrous_browser::{Browser, WaitUntil};
#[tokio::main]
async fn main() -> Result<(), Box<dyn std::error::Error>> {
let browser = Browser::launch_chrome(None).await?;
let page = browser.new_page().await?;
page.goto("https://example.com", WaitUntil::Load).await?;
Ok(())
}Implementations§
Source§impl Browser
impl Browser
Sourcepub async fn launch_chrome(config: Option<BrowserConfig>) -> Result<Self>
pub async fn launch_chrome(config: Option<BrowserConfig>) -> Result<Self>
Launch Chrome/Chromium and connect to it automatically.
Pass None to use BrowserConfig::default.
§Example
use ferrous_browser::{Browser, BrowserConfig};
let browser = Browser::launch_chrome(None).await?;
let config = BrowserConfig { headless: false, ..Default::default() };
let browser = Browser::launch_chrome(Some(config)).await?;Sourcepub async fn connect(ws_url: String) -> Result<Self>
pub async fn connect(ws_url: String) -> Result<Self>
Connect to a CDP WebSocket URL directly.
§Example
use ferrous_browser::Browser;
let browser = Browser::connect("ws://localhost:9222".to_string()).await?;Sourcepub async fn launch() -> Result<Self>
pub async fn launch() -> Result<Self>
Connect to a Chrome instance already running on localhost:9222.
§Example
use ferrous_browser::Browser;
let browser = Browser::launch().await?;Sourcepub async fn page_count(&self) -> usize
pub async fn page_count(&self) -> usize
Get the number of open pages/tabs.
Trait Implementations§
Auto Trait Implementations§
impl Freeze for Browser
impl !RefUnwindSafe for Browser
impl Send for Browser
impl Sync for Browser
impl Unpin for Browser
impl UnsafeUnpin for Browser
impl !UnwindSafe for Browser
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
Mutably borrows from an owned value. Read more
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>
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 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>
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