Skip to main content

Session

Struct Session 

Source
pub struct Session { /* private fields */ }
Expand description

A browser session that owns its browser and page. This is the primary API for most use cases.

Implementations§

Source§

impl Session

Source

pub async fn launch() -> Result<Self>

Launch a new browser and create an owned agent page.

Source

pub async fn launch_with_config(stealth: StealthConfig) -> Result<Self>

Launch with custom stealth config.

Source

pub fn set_observe_config(&mut self, config: ObserveConfig)

Set observation config.

Source

pub fn page(&self) -> &Page

Get reference to underlying page.

Source

pub fn browser(&self) -> &Browser

Get reference to browser.

Source

pub async fn observe(&mut self) -> Result<&[InteractiveElement]>

Snapshot the page: enumerate all interactive elements.

Source

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

Take an annotated screenshot with numbered boxes on each element.

Source

pub fn element_list(&self) -> String

Compact text list for LLM consumption.

Source

pub fn get(&self, index: usize) -> Option<&InteractiveElement>

Get element info by index.

Source

pub fn elements(&self) -> &[InteractiveElement]

Get all observed elements.

Source

pub fn len(&self) -> usize

Number of observed elements.

Source

pub fn is_empty(&self) -> bool

Whether the element list is empty.

Source

pub fn find_by_text(&self, needle: &str) -> Option<usize>

Find first element whose text contains the given substring (case-insensitive).

Source

pub async fn click(&mut self, index: usize) -> Result<()>

Click an element, auto-recovering if stale. Clears element cache since clicks often trigger navigation/DOM changes.

Source

pub async fn fill(&mut self, index: usize, text: &str) -> Result<()>

Fill an element, auto-recovering if stale. Does NOT clear element cache (typing rarely changes DOM structure).

Source

pub async fn select(&mut self, index: usize, value: &str) -> Result<()>

Select a dropdown option, auto-recovering if stale. Clears element cache since onChange handlers may modify DOM.

Source

pub async fn hover(&mut self, index: usize) -> Result<()>

Hover over element.

Source

pub async fn scroll_to(&mut self, index: usize) -> Result<()>

Scroll element into view.

Source

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

Navigate to a URL.

Source

pub async fn back(&mut self) -> Result<()>

Go back in history.

Source

pub async fn forward(&mut self) -> Result<()>

Go forward in history.

Source

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

Get the current URL.

Source

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

Get the page title.

Source

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

Get visible text content of the page.

Source

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

Scroll down by approximately one viewport height.

Source

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

Scroll up by approximately one viewport height.

Source

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

Scroll to top.

Source

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

Scroll to bottom.

Source

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

Wait for the page to stabilize after an action. Waits up to 2s for network idle, then 50ms for DOM settle. Intentionally succeeds even if network doesn’t fully idle (some sites never stop polling).

Source

pub async fn wait(&self, ms: u64)

Fixed delay in milliseconds.

Source

pub async fn press_key(&self, key: &str) -> Result<()>

Press a key.

Source

pub async fn eval<T: DeserializeOwned>(&self, js: &str) -> Result<T>

Evaluate JavaScript and return the result.

Source

pub async fn exec(&self, js: &str) -> Result<()>

Execute JavaScript (no return value).

Source

pub async fn spa_info(&self) -> Result<SpaRouterInfo>

Detect the SPA router type and current route state.

Source

pub async fn spa_navigate(&mut self, path: &str) -> Result<String>

Navigate the SPA to a new path without page reload. Automatically detects the router type and uses the appropriate navigation method. Clears element cache since the DOM will change.

Source

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

Navigate browser history by delta steps. delta = -1 goes back, delta = 1 goes forward. Clears element cache since the DOM will change.

Source

pub async fn close(self) -> Result<()>

Close the browser.

Auto Trait Implementations§

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<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: 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: 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, U> TryFrom<U> for T
where U: Into<T>,

Source§

type Error = Infallible

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

fn try_from(value: U) -> Result<T, <T as TryFrom<U>>::Error>

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