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
impl Browser
Sourcepub async fn connect(url: impl Into<String>) -> Result<(Self, Handler)>
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.
Sourcepub async fn connect_with_config(
url: impl Into<String>,
config: HandlerConfig,
) -> Result<(Self, Handler)>
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.
Sourcepub async fn launch(config: BrowserConfig) -> Result<(Self, Handler)>
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).
Sourcepub async fn fetch_targets(&mut self) -> Result<Vec<TargetInfo>>
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
Sourcepub async fn close(&mut self) -> Result<CloseReturns>
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.
Sourcepub async fn wait(&mut self) -> Result<Option<ExitStatus>>
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
)
Sourcepub fn try_wait(&mut self) -> Result<Option<ExitStatus>>
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
)
Sourcepub fn get_mut_child(&mut self) -> Option<&mut Child>
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
)
Sourcepub async fn kill(&mut self) -> Option<Result<()>>
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
)
Sourcepub async fn start_incognito_context(&mut self) -> Result<&mut Self>
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.
Sourcepub async fn quit_incognito_context(&mut self) -> Result<&mut Self>
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.
Sourcepub fn websocket_address(&self) -> &String
pub fn websocket_address(&self) -> &String
Returns the address of the websocket this browser is attached to
Sourcepub fn is_incognito(&self) -> bool
pub fn is_incognito(&self) -> bool
Whether the BrowserContext is incognito.
Sourcepub fn config(&self) -> Option<&BrowserConfig>
pub fn config(&self) -> Option<&BrowserConfig>
The config of the spawned chromium instance if any.
Sourcepub async fn new_page(
&self,
params: impl Into<CreateTargetParams>,
) -> Result<Page>
pub async fn new_page( &self, params: impl Into<CreateTargetParams>, ) -> Result<Page>
Create a new browser page
Sourcepub async fn version(&self) -> Result<GetVersionReturns>
pub async fn version(&self) -> Result<GetVersionReturns>
Version information about the browser
Sourcepub async fn user_agent(&self) -> Result<String>
pub async fn user_agent(&self) -> Result<String>
Returns the user agent of the browser
Sourcepub async fn execute<T: Command>(
&self,
cmd: T,
) -> Result<CommandResponse<T::Response>>
pub async fn execute<T: Command>( &self, cmd: T, ) -> Result<CommandResponse<T::Response>>
Call a browser method.
Sourcepub async fn get_page(&self, target_id: TargetId) -> Result<Page>
pub async fn get_page(&self, target_id: TargetId) -> Result<Page>
Return page of given target_id
Sourcepub async fn event_listener<T: IntoEventKind>(&self) -> Result<EventStream<T>>
pub async fn event_listener<T: IntoEventKind>(&self) -> Result<EventStream<T>>
Set listener for browser event
Sourcepub async fn create_browser_context(
&mut self,
params: CreateBrowserContextParams,
) -> Result<BrowserContextId>
pub async fn create_browser_context( &mut self, params: CreateBrowserContextParams, ) -> Result<BrowserContextId>
Creates a new empty browser context.
Sourcepub async fn send_new_context(
&mut self,
browser_context_id: BrowserContextId,
) -> Result<()>
pub async fn send_new_context( &mut self, browser_context_id: BrowserContextId, ) -> Result<()>
Send a new empty browser context.
Sourcepub async fn dispose_browser_context(
&self,
browser_context_id: impl Into<BrowserContextId>,
) -> Result<()>
pub async fn dispose_browser_context( &self, browser_context_id: impl Into<BrowserContextId>, ) -> Result<()>
Deletes a browser context.
Clears cookies.
Returns all browser cookies.
Sets given cookies.
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
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>
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>
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