pub struct Browser { /* private fields */ }
Expand description

A Browser is created when chromiumoxide connects to a Chromium instance.

Implementations§

source§

impl Browser

source

pub async fn connect(url: impl Into<String>) -> Result<(Self, Handler)>

Connect to an already running chromium instance via the given URL.

If the URL is a http(s) URL, it will first attempt to retrieve the Websocket URL from the json/version endpoint.

source

pub async fn connect_with_config( url: impl Into<String>, config: HandlerConfig ) -> Result<(Self, Handler)>

If the URL is a http URL, it will first attempt to retrieve the Websocket URL from the json/version endpoint.

source

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

Launches a new instance of chromium in the background and attaches to its debug web socket.

This fails when no chromium executable could be detected.

This fails if no web socket url could be detected from the child processes stderr for more than the configured launch_timeout (20 seconds by default).

source

pub async fn fetch_targets(&mut self) -> Result<Vec<TargetInfo>>

Request to fetch all existing browser targets.

By default, only targets launched after the browser connection are tracked when connecting to a existing browser instance with the devtools websocket url This function fetches existing targets on the browser and adds them as pages internally

The pages are not guaranteed to be ready as soon as the function returns You should wait a few millis if you need to use a page Returns TargetInfo

source

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

Request for the browser to close completely.

If the browser was spawned by Browser::launch, it is recommended to wait for the spawned instance exit, to avoid “zombie” processes (Browser::wait, [Browser::wait_sync], Browser::try_wait). Browser::drop waits automatically if needed.

source

pub async fn wait(&mut self) -> Result<Option<ExitStatus>>

Asynchronously wait for the spawned chromium instance to exit completely.

The instance is spawned by Browser::launch. wait is usually called after Browser::close. You can call this explicitly to collect the process and avoid “zombie” processes.

This call has no effect if this Browser did not spawn any chromium instance (e.g. connected to an existing browser through Browser::connect)

source

pub fn try_wait(&mut self) -> Result<Option<ExitStatus>>

If the spawned chromium instance has completely exited, wait for it.

The instance is spawned by Browser::launch. try_wait is usually called after Browser::close. You can call this explicitly to collect the process and avoid “zombie” processes.

This call has no effect if this Browser did not spawn any chromium instance (e.g. connected to an existing browser through Browser::connect)

source

pub fn get_mut_child(&mut self) -> Option<&mut Child>

Get the spawned chromium instance

The instance is spawned by Browser::launch. The result is a async_process::Child value. It acts as a compat wrapper for an async-std or tokio child process.

You may use async_process::Child::as_mut_inner to retrieve the concrete implementation for the selected runtime.

This call has no effect if this Browser did not spawn any chromium instance (e.g. connected to an existing browser through Browser::connect)

source

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

Forcibly kill the spawned chromium instance

The instance is spawned by Browser::launch. kill will automatically wait for the child process to exit to avoid “zombie” processes.

This method is provided to help if the browser does not close by itself. You should prefer to use Browser::close.

This call has no effect if this Browser did not spawn any chromium instance (e.g. connected to an existing browser through Browser::connect)

source

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

If not launched as incognito this creates a new incognito browser context. After that this browser exists within the incognito session. New pages created while being in incognito mode will also run in the incognito context. Incognito contexts won’t share cookies/cache with other browser contexts.

source

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

If a incognito session was created with Browser::start_incognito_context this disposes this context.

Note This will also dispose all pages that were running within the

incognito context.

source

pub fn websocket_address(&self) -> &String

Returns the address of the websocket this browser is attached to

source

pub fn is_incognito(&self) -> bool

Whether the BrowserContext is incognito.

source

pub fn config(&self) -> Option<&BrowserConfig>

The config of the spawned chromium instance if any.

source

pub async fn new_page( &self, params: impl Into<CreateTargetParams> ) -> Result<Page>

Create a new browser page

source

pub async fn version(&self) -> Result<GetVersionReturns>

Version information about the browser

source

pub async fn user_agent(&self) -> Result<String>

Returns the user agent of the browser

source

pub async fn execute<T: Command>( &self, cmd: T ) -> Result<CommandResponse<T::Response>>

Call a browser method.

source

pub async fn pages(&self) -> Result<Vec<Page>>

Return all of the pages of the browser

source

pub async fn get_page(&self, target_id: TargetId) -> Result<Page>

Return page of given target_id

source

pub async fn event_listener<T: IntoEventKind>(&self) -> Result<EventStream<T>>

Set listener for browser event

source

pub async fn create_browser_context( &self, params: CreateBrowserContextParams ) -> Result<BrowserContextId>

Creates a new empty browser context.

source

pub async fn dispose_browser_context( &self, browser_context_id: impl Into<BrowserContextId> ) -> Result<()>

Deletes a browser context.

Trait Implementations§

source§

impl Debug for Browser

source§

fn fmt(&self, f: &mut Formatter<'_>) -> Result

Formats the value using the given formatter. Read more
source§

impl Drop for Browser

source§

fn drop(&mut self)

Executes the destructor for this type. Read more

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.

source§

impl<T> Instrument for T

source§

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

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

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.

source§

impl<T> Same for T

§

type Output = T

Should always be Self
source§

impl<T, U> TryFrom<U> for T
where U: Into<T>,

§

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

§

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

source§

impl<T> WithSubscriber for T

source§

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
source§

fn with_current_subscriber(self) -> WithDispatch<Self>

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