Skip to main content

BrowserSession

Struct BrowserSession 

Source
pub struct BrowserSession { /* private fields */ }
Available on crate feature browser only.
Expand description

A browser session that wraps thirtyfour’s WebDriver.

This is the core abstraction for browser automation in ADK. It can be shared across multiple tools via Arc<BrowserSession>.

Implementations§

Source§

impl BrowserSession

Source

pub fn new(config: BrowserConfig) -> BrowserSession

Create a new browser session with the given configuration.

Note: This does not start the browser immediately. Call start() to initialize the WebDriver connection.

Source

pub fn with_defaults() -> BrowserSession

Create a browser session with default configuration.

Source

pub async fn start(&self) -> Result<(), AdkError>

Start the browser session by connecting to WebDriver.

Source

pub async fn stop(&self) -> Result<(), AdkError>

Stop the browser session.

Source

pub async fn is_active(&self) -> bool

Check if the session is active by verifying the WebDriver connection is alive.

Source

pub async fn ensure_started(&self) -> Result<(), AdkError>

Ensure the browser session is started, reconnecting if the session died.

Call this instead of checking is_active() manually. If the session exists but is stale (WebDriver died), it will be recreated transparently.

Source

pub async fn page_context(&self) -> Result<Value, AdkError>

Get a snapshot of the current page context (url, title, truncated body text).

Useful for returning page state after interaction tools.

Source

pub fn config(&self) -> &BrowserConfig

Get the configuration.

Source

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

Navigate to a URL.

Source

pub async fn current_url(&self) -> Result<String, AdkError>

Get the current URL.

Source

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

Get the page title.

Source

pub async fn find_element(&self, selector: &str) -> Result<WebElement, AdkError>

Find an element by CSS selector.

Source

pub async fn find_elements( &self, selector: &str, ) -> Result<Vec<WebElement>, AdkError>

Find multiple elements by CSS selector.

Source

pub async fn find_by_xpath(&self, xpath: &str) -> Result<WebElement, AdkError>

Find element by XPath.

Source

pub async fn click(&self, selector: &str) -> Result<(), AdkError>

Click an element by selector.

Source

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

Type text into an element.

Source

pub async fn clear(&self, selector: &str) -> Result<(), AdkError>

Clear an input field.

Source

pub async fn get_text(&self, selector: &str) -> Result<String, AdkError>

Get text content of an element.

Source

pub async fn get_attribute( &self, selector: &str, attribute: &str, ) -> Result<Option<String>, AdkError>

Get an attribute value.

Source

pub async fn screenshot(&self) -> Result<String, AdkError>

Take a screenshot (returns base64-encoded PNG).

Source

pub async fn screenshot_element( &self, selector: &str, ) -> Result<String, AdkError>

Take a screenshot of a specific element.

Source

pub async fn execute_script(&self, script: &str) -> Result<Value, AdkError>

Execute JavaScript and return result.

Source

pub async fn execute_async_script( &self, script: &str, ) -> Result<Value, AdkError>

Execute async JavaScript and return result.

Source

pub async fn wait_for_element( &self, selector: &str, timeout_secs: u64, ) -> Result<WebElement, AdkError>

Wait for an element to be present.

Source

pub async fn wait_for_clickable( &self, selector: &str, timeout_secs: u64, ) -> Result<WebElement, AdkError>

Wait for an element to be clickable.

Source

pub async fn page_source(&self) -> Result<String, AdkError>

Get page source HTML.

Source

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

Go back in history.

Source

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

Go forward in history.

Source

pub async fn refresh(&self) -> Result<(), AdkError>

Refresh the current page.

Source

pub async fn get_all_cookies(&self) -> Result<Vec<Value>, AdkError>

Get all cookies.

Get a cookie by name.

Add a cookie.

Delete a cookie.

Source

pub async fn delete_all_cookies(&self) -> Result<(), AdkError>

Delete all cookies.

Source

pub async fn list_windows(&self) -> Result<(Vec<String>, String), AdkError>

List all windows/tabs.

Source

pub async fn new_tab(&self) -> Result<String, AdkError>

Open a new tab.

Source

pub async fn new_window(&self) -> Result<String, AdkError>

Open a new window.

Source

pub async fn switch_to_window(&self, handle: &str) -> Result<(), AdkError>

Switch to a window by handle.

Source

pub async fn close_window(&self) -> Result<(), AdkError>

Close the current window.

Source

pub async fn maximize_window(&self) -> Result<(), AdkError>

Maximize window.

Source

pub async fn minimize_window(&self) -> Result<(), AdkError>

Minimize window.

Source

pub async fn set_window_rect( &self, x: i32, y: i32, width: u32, height: u32, ) -> Result<(), AdkError>

Set window size and position.

Source

pub async fn switch_to_frame_by_index(&self, index: u16) -> Result<(), AdkError>

Switch to frame by index.

Source

pub async fn switch_to_frame_by_selector( &self, selector: &str, ) -> Result<(), AdkError>

Switch to frame by selector.

Source

pub async fn switch_to_parent_frame(&self) -> Result<(), AdkError>

Switch to parent frame.

Source

pub async fn switch_to_default_content(&self) -> Result<(), AdkError>

Switch to default content.

Source

pub async fn drag_and_drop( &self, source_selector: &str, target_selector: &str, ) -> Result<(), AdkError>

Drag and drop.

Source

pub async fn right_click(&self, selector: &str) -> Result<(), AdkError>

Right-click (context click).

Source

pub async fn focus_element(&self, selector: &str) -> Result<(), AdkError>

Focus an element.

Source

pub async fn get_element_state( &self, selector: &str, ) -> Result<ElementState, AdkError>

Get element state.

Source

pub async fn press_key( &self, key: &str, selector: Option<&str>, modifiers: &[&str], ) -> Result<(), AdkError>

Press a key, optionally with modifier keys (Ctrl, Alt, Shift, Meta).

Source

pub async fn upload_file( &self, selector: &str, file_path: &str, ) -> Result<(), AdkError>

Upload a file.

Source

pub async fn print_to_pdf( &self, landscape: bool, scale: f64, ) -> Result<String, AdkError>

Print page to PDF.

Trait Implementations§

Source§

impl Drop for BrowserSession

Source§

fn drop(&mut self)

Executes the destructor for this type. Read more

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> FutureExt for T

Source§

fn with_context(self, otel_cx: Context) -> WithContext<Self>

Attaches the provided Context to this type, returning a WithContext wrapper. Read more
Source§

fn with_current_context(self) -> WithContext<Self>

Attaches the current Context to this type, returning a WithContext wrapper. Read more
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> IntoEither for T

Source§

fn into_either(self, into_left: bool) -> Either<Self, Self>

Converts self into a Left variant of Either<Self, Self> if into_left is true. Converts self into a Right variant of Either<Self, Self> otherwise. Read more
Source§

fn into_either_with<F>(self, into_left: F) -> Either<Self, Self>
where F: FnOnce(&Self) -> bool,

Converts self into a Left variant of Either<Self, Self> if into_left(&self) returns true. Converts self into a Right variant of Either<Self, Self> otherwise. Read more
Source§

impl<T> IntoRequest<T> for T

Source§

fn into_request(self) -> Request<T>

Wrap the input message T in a tonic::Request
Source§

impl<Unshared, Shared> IntoShared<Shared> for Unshared
where Shared: FromUnshared<Unshared>,

Source§

fn into_shared(self) -> Shared

Creates a shared type from an unshared type.
Source§

impl<L> LayerExt<L> for L

Source§

fn named_layer<S>(&self, service: S) -> Layered<<L as Layer<S>>::Service, S>
where L: Layer<S>,

Applies the layer to a service and wraps it in Layered.
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> 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 = 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<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