Skip to main content

BrowserPage

Struct BrowserPage 

Source
pub struct BrowserPage { /* private fields */ }

Implementations§

Source§

impl BrowserPage

Source

pub fn id(&self) -> &str

Source

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.

Source

pub async fn frames(&self) -> Result<Vec<String>>

Frame ids of every frame in the page (CDP Page.getFrameTree), read-only.

Source

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.

Source

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.

Source

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.

Source

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.

Source

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.

Source

pub fn clear_exceptions(&self)

Source

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.

Source

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.

Source

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.

Source

pub async fn set_user_agent( &self, user_agent: &str, accept_language: Option<&str>, ) -> Result<()>

Override the user agent of this page (Emulation.setUserAgentOverride), and optionally its Accept-Language. Applies to this page’s later requests and scripts. Admitted as an Eval-kind effect (detail user_agent).

Source

pub async fn set_extra_headers( &self, headers: &[(String, String)], ) -> Result<()>

Send headers with every later request of this page (Network.setExtraHTTPHeaders). Each call replaces the previous set; an empty slice clears it. Names are case-insensitive and must be unique; values may not contain control characters. Admitted as an Eval-kind effect whose detail carries the count only: header values are never logged.

Source

pub async fn import_cookies(&self, cookies: &[NetscapeCookie]) -> Result<usize>

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.

Source

pub fn blocked_requests(&self) -> Vec<BlockedRequest>

Requests the network policy refused on this page (redirect hops and subresources included).

Source

pub fn raw(&self) -> &Page

Escape hatch to the underlying chromiumoxide page.

Source

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

Source

pub async fn goto(&self, url: &str) -> Result<()>

Source

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

Source

pub async fn history(&self, delta: i32) -> Result<()>

Source

pub async fn url(&self) -> String

Source

pub async fn title(&self) -> String

Source

pub async fn text(&self) -> Result<String>

Rendered text (document.body.innerText).

Source

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.

Source

pub async fn set_viewport( &self, width: u32, height: u32, scale: f64, ) -> Result<()>

Source

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.

Source

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).

Source

pub async fn observe(&self) -> Result<Observation>

Compact tree of the page’s controls, each with a ref (r<epoch>.<n>). A ref is accepted only in the epoch it was issued in, for the document it was read from, and while the element behind it still has the tag, role and name it had here; see BrowserPage::act.

Source

pub async fn act(&self, node_ref: &str, action: &RefAction) -> Result<ActResult>

Run one action on an observed ref and return what it changed.

Before anything happens the ref is checked: it must be from the page’s current epoch, the document it was read from must still be the page’s document, and the element behind it must still have the tag, role and name it had at observe. Any mismatch is BrowserError::StaleRef. The action is then admitted (the hook sees the ref and the element’s role and name), run under the page lane, and the page is observed again under that same lane hold, so nothing else acts in between. The returned ObservationDiff says what appeared, disappeared or changed; when the epoch moved, earlier refs are refused and the diff carries the new refs of what is new.

The watchdog counts an action that left no diff (or failed) against its ref. After DEFAULT_ACTION_LOOP_LIMIT such repeats (see BrowserPage::set_action_loop_limit) the next identical action is refused with BrowserError::ActionLoop, and so is every action after it until BrowserPage::reset_action_watch.

Source

pub fn set_action_loop_limit(&self, limit: u32) -> Result<()>

Set how many identical no-diff actions BrowserPage::act allows (at least 1).

Source

pub fn reset_action_watch(&self)

Clear the watchdog’s count and its stop. Call it when a person or the host decided the run may go on.

Source

pub async fn hover(&self, target: &Target) -> Result<()>

Source

pub async fn click(&self, target: &Target) -> Result<()>

Source

pub async fn double_click(&self, target: &Target) -> Result<()>

Source

pub async fn drag(&self, from: &Target, to: &Target, steps: u32) -> Result<()>

Press at from, move in steps increments, release at to.

Source

pub async fn wheel(&self, at: Option<&Target>, dx: f64, dy: f64) -> Result<()>

Mouse-wheel scroll at the target (or viewport centre when None).

Source

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.

Source

pub async fn press(&self, spec: &str) -> Result<()>

Press a key or chord (Enter, Tab, Control+a) on the focused element.

Source

pub async fn type_text(&self, text: &str) -> Result<()>

Type text one key event at a time into the focused element.

Source

pub async fn fill(&self, target: &Target, text: &str, clear: bool) -> Result<()>

Click the target to focus it, then type.

Source

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).

Source

pub async fn upload(&self, target: &Target, file: &Path) -> Result<()>

Source

pub async fn wait_for(&self, selector: &str, timeout: Duration) -> Result<()>

Source

pub async fn wait_eval(&self, expr: &str, timeout: Duration) -> Result<()>

Poll a JS expression until truthy.

Source

pub async fn screenshot(&self) -> Result<Vec<u8>>

Source

pub async fn screenshot_with( &self, options: ScreenshotOptions, ) -> Result<Vec<u8>>

PNG screenshot of the viewport with options; ScreenshotOptions::default() matches BrowserPage::screenshot.

Source

pub async fn screenshot_to(&self, path: &Path) -> Result<()>

Source

pub async fn console(&self) -> Vec<ConsoleLine>

Source

pub async fn clear_console(&self)

Auto Trait Implementations§

§

impl !Freeze for BrowserPage

§

impl !RefUnwindSafe for BrowserPage

§

impl !UnwindSafe for BrowserPage

§

impl Forget for BrowserPage

§

impl Move for BrowserPage

§

impl Send for BrowserPage
where RawVecInner: Send, Arc<PageInner>: Send, Arc<Mutex<Vec<ConsoleLine>>>: Send, Mutex<ObsState>: Send, Mutex<(f64, f64)>: Send, Mutex<i64>: Send, Mutex<()>: Send, Mutex<Vec<JoinHandle<()>>>: Send, Arc<Guard>: Send, Arc<Mutex<Vec<BlockedRequest>>>: Send, Arc<InterceptStats>: Send, Arc<Mutex<Option<Arc<dyn Fn(InterceptedRequest) -> Pin<Box<dyn Future<Output = InterceptDecision> + Send>> + Sync + Send>>>>: Send, Atomic<bool>: Send, Arc<Mutex<Vec<PageException>>>: Send, Arc<Shared<PageException>>: Send, Arc<NativeGestureLatch>: Send, Mutex<Option<ExecutionContextId>>: Send, Mutex<ActionWatch>: Send,

§

impl Sync for BrowserPage
where RawVecInner: Sync, Arc<PageInner>: Sync, Arc<Mutex<Vec<ConsoleLine>>>: Sync, Mutex<ObsState>: Sync, Mutex<(f64, f64)>: Sync, Mutex<i64>: Sync, Mutex<()>: Sync, Mutex<Vec<JoinHandle<()>>>: Sync, Arc<Guard>: Sync, Arc<Mutex<Vec<BlockedRequest>>>: Sync, Arc<InterceptStats>: Sync, Arc<Mutex<Option<Arc<dyn Fn(InterceptedRequest) -> Pin<Box<dyn Future<Output = InterceptDecision> + Send>> + Sync + Send>>>>: Sync, Atomic<bool>: Sync, Arc<Mutex<Vec<PageException>>>: Sync, Arc<Shared<PageException>>: Sync, Arc<NativeGestureLatch>: Sync, Mutex<Option<ExecutionContextId>>: Sync, Mutex<ActionWatch>: Sync,

§

impl Unpin for BrowserPage
where *const u8 is !null: Unpin, Arc<PageInner>: Unpin, Arc<Mutex<Vec<ConsoleLine>>>: Unpin, Align4<u32>: Unpin, Align1<u8>: Unpin, *const Waiter is !null: Unpin, Align8<usize>: Unpin, JoinHandle<()>: Unpin, Arc<Guard>: Unpin, Arc<Mutex<Vec<BlockedRequest>>>: Unpin, Arc<InterceptStats>: Unpin, Arc<Mutex<Option<Arc<dyn Fn(InterceptedRequest) -> Pin<Box<dyn Future<Output = InterceptDecision> + Send>> + Sync + Send>>>>: Unpin, Arc<Mutex<Vec<PageException>>>: Unpin, Arc<Shared<PageException>>: Unpin, Arc<NativeGestureLatch>: Unpin,

§

impl UnsafeUnpin for BrowserPage
where *const u8 is !null: UnsafeUnpin, PhantomData<u8>: UnsafeUnpin, *const ArcInner<PageInner> is !null: UnsafeUnpin, PhantomData<ArcInner<PageInner>>: UnsafeUnpin, *const ArcInner<Mutex<Vec<ConsoleLine>>> is !null: UnsafeUnpin, PhantomData<ArcInner<Mutex<Vec<ConsoleLine>>>>: UnsafeUnpin, Align4<u32>: UnsafeUnpin, Align1<u8>: UnsafeUnpin, PhantomData<(String, RefEntry)>: UnsafeUnpin, PhantomData<(String, String)>: UnsafeUnpin, PhantomData<(String, u64)>: UnsafeUnpin, PhantomData<(String, NodeState)>: UnsafeUnpin, *const Waiter is !null: UnsafeUnpin, Align8<usize>: UnsafeUnpin, PhantomData<JoinHandle<()>>: UnsafeUnpin, *const ArcInner<Guard> is !null: UnsafeUnpin, PhantomData<ArcInner<Guard>>: UnsafeUnpin, *const ArcInner<Mutex<Vec<BlockedRequest>>> is !null: UnsafeUnpin, PhantomData<ArcInner<Mutex<Vec<BlockedRequest>>>>: UnsafeUnpin, *const ArcInner<InterceptStats> is !null: UnsafeUnpin, PhantomData<ArcInner<InterceptStats>>: UnsafeUnpin, *const ArcInner<Mutex<Option<Arc<dyn Fn(InterceptedRequest) -> Pin<Box<dyn Future<Output = InterceptDecision> + Send>> + Sync + Send>>>> is !null: UnsafeUnpin, PhantomData<ArcInner<Mutex<Option<Arc<dyn Fn(InterceptedRequest) -> Pin<Box<dyn Future<Output = InterceptDecision> + Send>> + Sync + Send>>>>>: UnsafeUnpin, *const ArcInner<Mutex<Vec<PageException>>> is !null: UnsafeUnpin, PhantomData<ArcInner<Mutex<Vec<PageException>>>>: UnsafeUnpin, *const ArcInner<Shared<PageException>> is !null: UnsafeUnpin, PhantomData<ArcInner<Shared<PageException>>>: UnsafeUnpin, *const ArcInner<NativeGestureLatch> is !null: UnsafeUnpin, PhantomData<ArcInner<NativeGestureLatch>>: UnsafeUnpin,

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<ST, DT> CastableFrom<ST, Initialized, Initialized> for DT
where ST: ?Sized, DT: ?Sized,

Source§

impl<ST, DT> CastableFrom<ST, Uninit, Uninit> for DT
where ST: ?Sized, DT: ?Sized,

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> PolicyExt for T
where T: ?Sized,

Source§

fn and<P, B, E>(self, other: P) -> And<T, P>
where T: Sized + Policy<B, E>, P: Policy<B, E>,

Create a new Policy that returns Action::Follow only if self and other return Action::Follow. Read more
Source§

fn or<P, B, E>(self, other: P) -> Or<T, P>
where T: Sized + Policy<B, E>, P: Policy<B, E>,

Create a new Policy that returns Action::Follow if either self or other returns Action::Follow. Read more
Source§

impl<T> Read<Exclusive, BecauseExclusive> for T
where T: ?Sized,

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 = !

The type returned in the event of a conversion error.
Source§

fn try_from(value: U) -> Result<T, !>

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