pub struct Browser { /* private fields */ }Expand description
A browser instance connected via CDP.
Implementations§
Source§impl Browser
impl Browser
Sourcepub fn launch() -> BrowserBuilder
pub fn launch() -> BrowserBuilder
Create a browser builder for launching a new browser.
§Example
use viewpoint_core::Browser;
let browser = Browser::launch()
.headless(true)
.launch()
.await?;Sourcepub async fn new_context(&self) -> Result<BrowserContext, BrowserError>
pub async fn new_context(&self) -> Result<BrowserContext, BrowserError>
Create a new isolated browser context.
Browser contexts are isolated environments within the browser, similar to incognito windows. They have their own cookies, cache, and storage.
§Errors
Returns an error if context creation fails.
Sourcepub fn new_context_builder(&self) -> NewContextBuilder<'_>
pub fn new_context_builder(&self) -> NewContextBuilder<'_>
Create a new context options builder.
Use this to create a browser context with custom configuration.
§Example
use viewpoint_core::{Browser, Permission};
let browser = Browser::launch().headless(true).launch().await?;
let context = browser.new_context_builder()
.geolocation(37.7749, -122.4194)
.permissions(vec![Permission::Geolocation])
.offline(false)
.build()
.await?;Sourcepub async fn new_context_with_options(
&self,
options: ContextOptions,
) -> Result<BrowserContext, BrowserError>
pub async fn new_context_with_options( &self, options: ContextOptions, ) -> Result<BrowserContext, BrowserError>
Create a new isolated browser context with options.
§Errors
Returns an error if context creation fails.
Sourcepub async fn close(&self) -> Result<(), BrowserError>
pub async fn close(&self) -> Result<(), BrowserError>
Close the browser.
If this browser was launched by us, the process will be terminated. If it was connected to, only the WebSocket connection is closed.
§Errors
Returns an error if closing fails.
Sourcepub fn connection(&self) -> &Arc<CdpConnection>
pub fn connection(&self) -> &Arc<CdpConnection>
Get a reference to the CDP connection.
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 !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