pub struct Browser {
pub user_agent: String,
/* private fields */
}Expand description
A browser-level CDP connection used to drive one page inside an
isolated browser context (Target.createBrowserContext): its own
cookie jar and storage, shared with no other tab, so nothing else in the
browser can log it out and it can’t disturb the user’s tabs.
Contexts are created with disposeOnDetach: false, so the context and
its tab survive this process exiting; a later process reconnects by id.
Fields§
§user_agent: StringThe browser’s User-Agent.
Implementations§
Source§impl Browser
impl Browser
pub async fn connect(base: &str) -> Result<Self>
Sourcepub async fn call(
&mut self,
session: Option<&str>,
method: &str,
params: Value,
) -> Result<Value>
pub async fn call( &mut self, session: Option<&str>, method: &str, params: Value, ) -> Result<Value>
Raw CDP call, optionally on an attached page session.
Sourcepub async fn create_context(&mut self) -> Result<String>
pub async fn create_context(&mut self) -> Result<String>
Create an isolated context that outlives this connection.
pub async fn context_exists(&mut self, context: &str) -> Result<bool>
Sourcepub async fn dispose_context(&mut self, context: &str) -> Result<()>
pub async fn dispose_context(&mut self, context: &str) -> Result<()>
Dispose a context we created (closes its tabs, drops its cookies).
Sourcepub async fn open_tab(&mut self, context: &str, url: &str) -> Result<String>
pub async fn open_tab(&mut self, context: &str, url: &str) -> Result<String>
Open url in a new background tab of context.
Sourcepub async fn tab_in_context(
&mut self,
context: &str,
target: &str,
) -> Result<bool>
pub async fn tab_in_context( &mut self, context: &str, target: &str, ) -> Result<bool>
Whether target is still a page in context.
Sourcepub async fn attach(&mut self, target: &str) -> Result<String>
pub async fn attach(&mut self, target: &str) -> Result<String>
Attach to a tab (flattened session) and make it behave like a focused,
visible page: a background tab otherwise never runs
requestAnimationFrame, and the login SPA stays on its spinner.
Sourcepub async fn eval(&mut self, session: &str, expression: &str) -> Result<Value>
pub async fn eval(&mut self, session: &str, expression: &str) -> Result<Value>
Evaluate expression in the page (promises awaited) and return its
JSON value. Callers must not log values that are credentials.
Navigate the attached page.
Sourcepub async fn click_at(&mut self, session: &str, x: f64, y: f64) -> Result<()>
pub async fn click_at(&mut self, session: &str, x: f64, y: f64) -> Result<()>
A trusted left click at viewport coordinates (as a user’s would be).
Sourcepub async fn type_digits(&mut self, session: &str, digits: &str) -> Result<()>
pub async fn type_digits(&mut self, session: &str, digits: &str) -> Result<()>
Type ASCII digits into the focused element, one key at a time.
The grab.com cookies of one browser context.
The grab.com cookies of the browser’s default context (the user’s
normal tabs), as opposed to context_cookies.
Sourcepub async fn drain_events(&mut self, wait: Duration) -> Result<usize>
pub async fn drain_events(&mut self, wait: Duration) -> Result<usize>
Drain buffered CDP events (e.g. after a navigation), waiting up to
wait for more. Returns how many were seen.