chromiumoxide::browser

Struct Browser

Source
pub struct Browser {
    pub browser_context: BrowserContext,
    /* private fields */
}
Expand description

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

Fields§

§browser_context: BrowserContext

The context of the browser

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 fn has_child(&self) -> bool

Has a browser instance launched on system.

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( &mut self, params: CreateBrowserContextParams, ) -> Result<BrowserContextId>

Creates a new empty browser context.

Source

pub async fn send_new_context( &mut self, browser_context_id: BrowserContextId, ) -> Result<()>

Send a new empty browser context.

Source

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

Deletes a browser context.

Source

pub async fn clear_cookies(&self) -> Result<()>

Clears cookies.

Source

pub async fn get_cookies(&self) -> Result<Vec<Cookie>>

Returns all browser cookies.

Source

pub async fn set_cookies(&self, cookies: Vec<CookieParam>) -> Result<&Self>

Sets given cookies.

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> IntoEither for T

Source§

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 more
Source§

fn into_either_with<F>(self, into_left: F) -> Either<Self, Self>
where F: FnOnce(&Self) -> bool,

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

impl<T> Same for T

Source§

type Output = T

Should always be Self
Source§

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

Source§

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

Source§

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.
Source§

impl<V, T> VZip<V> for T
where V: MultiLane<T>,

Source§

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

impl<T> ErasedDestructor for T
where T: 'static,

Source§

impl<T> MaybeSendSync for T