pub struct BrowserPage { /* private fields */ }Implementations§
Source§impl BrowserPage
impl BrowserPage
pub fn id(&self) -> &str
Sourcepub fn target_id(&self) -> &str
pub fn target_id(&self) -> &str
The CDP target id of this tab. Unlike BrowserPage::id, it is Chrome’s own identity
for the tab and does not change when the session renumbers pages.
Sourcepub async fn frames(&self) -> Result<Vec<String>>
pub async fn frames(&self) -> Result<Vec<String>>
Frame ids of every frame in the page (CDP Page.getFrameTree), read-only.
Sourcepub async fn set_request_interceptor(
&self,
hook: Option<RequestInterceptor>,
) -> Result<()>
pub async fn set_request_interceptor( &self, hook: Option<RequestInterceptor>, ) -> Result<()>
Install (or with None, remove) a caller hook that answers every request this page
makes: continue, continue with changes, fulfil from memory, or fail. Redirect hops arrive
as separate requests with InterceptedRequest::redirected_from set, so a hook that pins
an origin revalidates each hop.
The session’s network policy runs first and its refusals are final; the hook only
narrows what the policy allows. A hook that takes longer than 30 s fails the request.
Turns on Fetch interception for this page when the policy had not (an unrestricted
session); requests already in flight are not affected. Removing the hook lets requests
through unchanged but leaves interception running. Not available on a fixture page, whose
session owns Fetch: returns BrowserError::Invalid.
Sourcepub async fn accessibility_tree(&self) -> Result<Vec<AxNode>>
pub async fn accessibility_tree(&self) -> Result<Vec<AxNode>>
The page’s full accessibility tree (Accessibility.getFullAXTree), root frame, in CDP
order. Ignored nodes are included and flagged. Read-only.
Sourcepub async fn accessibility_tree_with(&self, depth: u32) -> Result<Vec<AxNode>>
pub async fn accessibility_tree_with(&self, depth: u32) -> Result<Vec<AxNode>>
The accessibility tree cut off below depth (root is depth 0). Use it on heavy pages,
where the full tree costs too much. Read-only, like BrowserPage::accessibility_tree.
Sourcepub async fn set_transparent_background(&self, transparent: bool) -> Result<()>
pub async fn set_transparent_background(&self, transparent: bool) -> Result<()>
Make the page background transparent (Emulation.setDefaultBackgroundColorOverride
with alpha 0), or restore Chrome’s default with false. Pair with
BrowserPage::screenshot_with and omit_background to capture alpha. Like
BrowserPage::set_page_scale, this changes rendering only and is not admitted.
Sourcepub fn exceptions(&self) -> Vec<PageException>
pub fn exceptions(&self) -> Vec<PageException>
Uncaught exceptions and unhandled rejections seen so far (Runtime.exceptionThrown),
oldest first, at most MAX_EXCEPTIONS. Collected from the moment
the page exists, so nothing from its first navigation is missed.
pub fn clear_exceptions(&self)
Sourcepub fn subscribe_exceptions(&self) -> Receiver<PageException>
pub fn subscribe_exceptions(&self) -> Receiver<PageException>
Live stream of exceptions from now on. The page exists before its first navigation, so a
subscriber taken before goto sees every exception it raises. A receiver that falls more
than 64 behind gets RecvError::Lagged; BrowserPage::exceptions still has them.
Sourcepub async fn set_page_scale(&self, scale: f64) -> Result<()>
pub async fn set_page_scale(&self, scale: f64) -> Result<()>
Set the page scale factor (pinch zoom, Emulation.setPageScaleFactor). Must be positive
and finite. Distinct from the device scale factor of BrowserPage::set_viewport.
Sourcepub async fn set_download_behavior(
&self,
behavior: &DownloadBehavior,
) -> Result<()>
pub async fn set_download_behavior( &self, behavior: &DownloadBehavior, ) -> Result<()>
Choose what happens to downloads (Browser.setDownloadBehavior). Allow and
AllowAndName need an absolute, existing directory; downloads go nowhere else.
Admitted as an Eval-kind effect (detail download_behavior ...) because it lets pages
write files. Applies to the browser’s default context, so it covers every page of a
session; a later call replaces an earlier one.
Set cookies in the browser profile this page belongs to (Network.setCookies) and
return how many were set. The cookies apply to the whole profile, not to this page, and
persist with a named or directory profile. A subdomain-matching cookie gets a leading dot
on its domain; a host-only cookie does not. Chrome rejects the whole batch if one cookie
is invalid (for example a __Secure- name without secure); the error then sets none
and its text never contains a cookie value.
Domain filtering, user consent and file selection belong to the caller: this sets exactly
what it is given. Admitted as an Eval-kind effect (detail import_cookies, the count
and the distinct domains; never names or values). An empty slice returns Ok(0) without
contacting the browser; more than MAX_COOKIES is refused.
Sourcepub fn blocked_requests(&self) -> Vec<BlockedRequest>
pub fn blocked_requests(&self) -> Vec<BlockedRequest>
Requests the network policy refused on this page (redirect hops and subresources included).
pub async fn bring_to_front(&self) -> Result<()>
pub async fn goto(&self, url: &str) -> Result<()>
pub async fn reload(&self) -> Result<()>
pub async fn history(&self, delta: i32) -> Result<()>
pub async fn url(&self) -> String
pub async fn title(&self) -> String
Sourcepub async fn eval(&self, expr: &str) -> Result<Value>
pub async fn eval(&self, expr: &str) -> Result<Value>
Evaluate a JS expression and return its JSON value. Script can navigate and act, so it is admitted like any other effect.
pub async fn set_viewport( &self, width: u32, height: u32, scale: f64, ) -> Result<()>
Sourcepub async fn enable_design_mode(&self, nonce: &str) -> Result<DesignModeSession>
pub async fn enable_design_mode(&self, nonce: &str) -> Result<DesignModeSession>
Enable the element picker for the current document. It runs in a fresh isolated world
and reports through a Runtime.addBinding function bound only to that world, so page
script can neither see nor forge picker messages. Prompt submissions are delivered only
when one native input gesture (a pointer press or key down this page dispatched)
authorizes them; see DesignModeBridge. Call once per document; navigation ends the
picker and requires a new call with a new nonce.
Sourcepub async fn design_mode_result(
&self,
id: u64,
ok: bool,
message: &str,
) -> Result<()>
pub async fn design_mode_result( &self, id: u64, ok: bool, message: &str, ) -> Result<()>
Show the outcome of a submission in the picker popup (window.__omniOnDesignResult
in the picker’s isolated world).
pub async fn observe(&self) -> Result<Observation>
pub async fn hover(&self, target: &Target) -> Result<()>
pub async fn click(&self, target: &Target) -> Result<()>
pub async fn double_click(&self, target: &Target) -> Result<()>
Sourcepub async fn drag(&self, from: &Target, to: &Target, steps: u32) -> Result<()>
pub async fn drag(&self, from: &Target, to: &Target, steps: u32) -> Result<()>
Press at from, move in steps increments, release at to.
Sourcepub async fn wheel(&self, at: Option<&Target>, dx: f64, dy: f64) -> Result<()>
pub async fn wheel(&self, at: Option<&Target>, dx: f64, dy: f64) -> Result<()>
Mouse-wheel scroll at the target (or viewport centre when None).
Sourcepub async fn scroll_by(
&self,
target: Option<&Target>,
dx: f64,
dy: f64,
) -> Result<()>
pub async fn scroll_by( &self, target: Option<&Target>, dx: f64, dy: f64, ) -> Result<()>
Programmatic scroll (scrollBy) of the element at target, or of the window when
None. Use it where a wheel event at the element’s centre is wrong: a covered element,
or one that is not scrollable under the pointer. Selectors and refs must resolve to one
element; a point scrolls the element under it. No element at a point is an error.
Sourcepub async fn press(&self, spec: &str) -> Result<()>
pub async fn press(&self, spec: &str) -> Result<()>
Press a key or chord (Enter, Tab, Control+a) on the focused element.
Sourcepub async fn type_text(&self, text: &str) -> Result<()>
pub async fn type_text(&self, text: &str) -> Result<()>
Type text one key event at a time into the focused element.
Sourcepub async fn fill(&self, target: &Target, text: &str, clear: bool) -> Result<()>
pub async fn fill(&self, target: &Target, text: &str, clear: bool) -> Result<()>
Click the target to focus it, then type.
Sourcepub async fn select_option(&self, target: &Target, value: &str) -> Result<()>
pub async fn select_option(&self, target: &Target, value: &str) -> Result<()>
Choose a <select> option by value/label. Native popups cannot be driven
over CDP, so this sets the value and fires input/change (documented gap).
pub async fn upload(&self, target: &Target, file: &Path) -> Result<()>
pub async fn wait_for(&self, selector: &str, timeout: Duration) -> Result<()>
Sourcepub async fn wait_eval(&self, expr: &str, timeout: Duration) -> Result<()>
pub async fn wait_eval(&self, expr: &str, timeout: Duration) -> Result<()>
Poll a JS expression until truthy.
pub async fn screenshot(&self) -> Result<Vec<u8>>
Sourcepub async fn screenshot_with(
&self,
options: ScreenshotOptions,
) -> Result<Vec<u8>>
pub async fn screenshot_with( &self, options: ScreenshotOptions, ) -> Result<Vec<u8>>
PNG screenshot of the viewport with options; ScreenshotOptions::default() matches
BrowserPage::screenshot.