pub struct BrowserContext { /* private fields */ }Expand description
A browser context. The default context has browser_context_id == None;
isolated contexts are created via Browser::new_context.
Implementations§
Source§impl BrowserContext
impl BrowserContext
Sourcepub fn browser_context_id(&self) -> Option<&str>
pub fn browser_context_id(&self) -> Option<&str>
The CDP browser-context id, or None for the default context.
Sourcepub async fn add_init_script(&self, script: &str) -> Result<()>
pub async fn add_init_script(&self, script: &str) -> Result<()>
Add a script evaluated before each document load (applied to new pages).
Sourcepub fn set_default_timeout(&self, timeout_ms: u64)
pub fn set_default_timeout(&self, timeout_ms: u64)
Set the default action timeout (ms) for pages in this context.
Sourcepub async fn set_extra_http_headers(&self, headers: Headers) -> Result<()>
pub async fn set_extra_http_headers(&self, headers: Headers) -> Result<()>
Set extra HTTP headers sent on every request (applied to new + existing pages).
Sourcepub fn request(&self) -> APIRequestContext
pub fn request(&self) -> APIRequestContext
Return a standalone HTTP client (APIRequestContext) tied to this
context. Its default headers are seeded (best-effort) from the
context’s extra_http_headers. The client is otherwise independent of
the browser — it makes direct HTTP requests.
Add cookies to this context.
Get cookies for this context.
Clear cookies for this context.
Sourcepub fn on_page<F, Fut>(&self, handler: F)
pub fn on_page<F, Fut>(&self, handler: F)
Register a handler called for each new page in this context.
Sourcepub async fn close(&self) -> Result<()>
pub async fn close(&self) -> Result<()>
Close the context and all its pages. Disposes an isolated context.
Sourcepub async fn grant_permissions(&self, permissions: &[&str]) -> Result<()>
pub async fn grant_permissions(&self, permissions: &[&str]) -> Result<()>
Grant browser permissions (e.g. ["geolocation", "clipboard-read"]).
Applies browser-wide (CDP Browser.grantPermissions is not context-scoped).
Sourcepub async fn clear_permissions(&self) -> Result<()>
pub async fn clear_permissions(&self) -> Result<()>
Reset all granted permissions.
Sourcepub async fn storage_state(&self) -> Result<StorageState>
pub async fn storage_state(&self) -> Result<StorageState>
Snapshot storage state: cookies plus per-origin localStorage.
For each page in the context, localStorage is captured grouped by
location.origin. Pages whose origin is "null" (e.g. about:blank,
data: URLs) are skipped.
Sourcepub async fn set_storage_state(&self, state: &StorageState) -> Result<()>
pub async fn set_storage_state(&self, state: &StorageState) -> Result<()>
Restore storage state previously captured by Self::storage_state:
cookies are added via the Storage domain, and each origin’s localStorage
is set by evaluating localStorage.setItem on a page at that origin
(an existing page if one matches, otherwise a freshly created one).
Sourcepub async fn route<F, Fut>(&self, pattern: &str, handler: F) -> Result<()>
pub async fn route<F, Fut>(&self, pattern: &str, handler: F) -> Result<()>
Register a route that intercepts matching requests on ALL pages in this
context — including pages created after this call. The handler must
continue/fulfill/abort the Route.
A context route is applied to each page by registering the equivalent page-level route on it. Context-level and page-level routes are otherwise independent.
Sourcepub async fn unroute(&self, pattern: &str) -> Result<()>
pub async fn unroute(&self, pattern: &str) -> Result<()>
Remove the first context-level route registered with exactly pattern
and remove the matching page-level route on each page.
Sourcepub async fn unroute_all(&self) -> Result<()>
pub async fn unroute_all(&self) -> Result<()>
Remove all context-level routes and all page-level routes on each page.
Sourcepub fn tracing(&self) -> Tracing
pub fn tracing(&self) -> Tracing
A performance tracing handle bound to the browser-level CDP session.
Mirrors Playwright’s context.tracing(). The Tracing domain is
browser-level; tracing() returns clones of a single shared handle so
[Tracing::start] and [Tracing::stop] operate on the same state.
Trait Implementations§
Source§impl Clone for BrowserContext
impl Clone for BrowserContext
Source§fn clone(&self) -> BrowserContext
fn clone(&self) -> BrowserContext
1.0.0 (const: unstable) · Source§fn clone_from(&mut self, source: &Self)
fn clone_from(&mut self, source: &Self)
source. Read more