pub struct BrowserSession { /* private fields */ }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
impl BrowserSession
Sourcepub fn new(config: BrowserConfig) -> BrowserSession
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.
Sourcepub fn with_defaults() -> BrowserSession
pub fn with_defaults() -> BrowserSession
Create a browser session with default configuration.
Sourcepub async fn start(&self) -> Result<(), AdkError>
pub async fn start(&self) -> Result<(), AdkError>
Start the browser session by connecting to WebDriver.
Sourcepub async fn is_active(&self) -> bool
pub async fn is_active(&self) -> bool
Check if the session is active by verifying the WebDriver connection is alive.
Sourcepub async fn ensure_started(&self) -> Result<(), AdkError>
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.
Sourcepub async fn page_context(&self) -> Result<Value, AdkError>
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.
Sourcepub fn config(&self) -> &BrowserConfig
pub fn config(&self) -> &BrowserConfig
Get the configuration.
Navigate to a URL.
Sourcepub async fn current_url(&self) -> Result<String, AdkError>
pub async fn current_url(&self) -> Result<String, AdkError>
Get the current URL.
Sourcepub async fn find_element(&self, selector: &str) -> Result<WebElement, AdkError>
pub async fn find_element(&self, selector: &str) -> Result<WebElement, AdkError>
Find an element by CSS selector.
Sourcepub async fn find_elements(
&self,
selector: &str,
) -> Result<Vec<WebElement>, AdkError>
pub async fn find_elements( &self, selector: &str, ) -> Result<Vec<WebElement>, AdkError>
Find multiple elements by CSS selector.
Sourcepub async fn find_by_xpath(&self, xpath: &str) -> Result<WebElement, AdkError>
pub async fn find_by_xpath(&self, xpath: &str) -> Result<WebElement, AdkError>
Find element by XPath.
Sourcepub async fn click(&self, selector: &str) -> Result<(), AdkError>
pub async fn click(&self, selector: &str) -> Result<(), AdkError>
Click an element by selector.
Sourcepub async fn type_text(
&self,
selector: &str,
text: &str,
) -> Result<(), AdkError>
pub async fn type_text( &self, selector: &str, text: &str, ) -> Result<(), AdkError>
Type text into an element.
Sourcepub async fn get_text(&self, selector: &str) -> Result<String, AdkError>
pub async fn get_text(&self, selector: &str) -> Result<String, AdkError>
Get text content of an element.
Sourcepub async fn get_attribute(
&self,
selector: &str,
attribute: &str,
) -> Result<Option<String>, AdkError>
pub async fn get_attribute( &self, selector: &str, attribute: &str, ) -> Result<Option<String>, AdkError>
Get an attribute value.
Sourcepub async fn screenshot(&self) -> Result<String, AdkError>
pub async fn screenshot(&self) -> Result<String, AdkError>
Take a screenshot (returns base64-encoded PNG).
Sourcepub async fn screenshot_element(
&self,
selector: &str,
) -> Result<String, AdkError>
pub async fn screenshot_element( &self, selector: &str, ) -> Result<String, AdkError>
Take a screenshot of a specific element.
Sourcepub async fn execute_script(&self, script: &str) -> Result<Value, AdkError>
pub async fn execute_script(&self, script: &str) -> Result<Value, AdkError>
Execute JavaScript and return result.
Sourcepub async fn execute_async_script(
&self,
script: &str,
) -> Result<Value, AdkError>
pub async fn execute_async_script( &self, script: &str, ) -> Result<Value, AdkError>
Execute async JavaScript and return result.
Sourcepub async fn wait_for_element(
&self,
selector: &str,
timeout_secs: u64,
) -> Result<WebElement, AdkError>
pub async fn wait_for_element( &self, selector: &str, timeout_secs: u64, ) -> Result<WebElement, AdkError>
Wait for an element to be present.
Sourcepub async fn wait_for_clickable(
&self,
selector: &str,
timeout_secs: u64,
) -> Result<WebElement, AdkError>
pub async fn wait_for_clickable( &self, selector: &str, timeout_secs: u64, ) -> Result<WebElement, AdkError>
Wait for an element to be clickable.
Sourcepub async fn page_source(&self) -> Result<String, AdkError>
pub async fn page_source(&self) -> Result<String, AdkError>
Get page source HTML.
Get all cookies.
Get a cookie by name.
Add a cookie.
Delete a cookie.
Delete all cookies.
Sourcepub async fn list_windows(&self) -> Result<(Vec<String>, String), AdkError>
pub async fn list_windows(&self) -> Result<(Vec<String>, String), AdkError>
List all windows/tabs.
Sourcepub async fn new_window(&self) -> Result<String, AdkError>
pub async fn new_window(&self) -> Result<String, AdkError>
Open a new window.
Sourcepub async fn switch_to_window(&self, handle: &str) -> Result<(), AdkError>
pub async fn switch_to_window(&self, handle: &str) -> Result<(), AdkError>
Switch to a window by handle.
Sourcepub async fn close_window(&self) -> Result<(), AdkError>
pub async fn close_window(&self) -> Result<(), AdkError>
Close the current window.
Sourcepub async fn maximize_window(&self) -> Result<(), AdkError>
pub async fn maximize_window(&self) -> Result<(), AdkError>
Maximize window.
Sourcepub async fn minimize_window(&self) -> Result<(), AdkError>
pub async fn minimize_window(&self) -> Result<(), AdkError>
Minimize window.
Sourcepub async fn set_window_rect(
&self,
x: i32,
y: i32,
width: u32,
height: u32,
) -> Result<(), AdkError>
pub async fn set_window_rect( &self, x: i32, y: i32, width: u32, height: u32, ) -> Result<(), AdkError>
Set window size and position.
Sourcepub async fn switch_to_frame_by_index(&self, index: u16) -> Result<(), AdkError>
pub async fn switch_to_frame_by_index(&self, index: u16) -> Result<(), AdkError>
Switch to frame by index.
Sourcepub async fn switch_to_frame_by_selector(
&self,
selector: &str,
) -> Result<(), AdkError>
pub async fn switch_to_frame_by_selector( &self, selector: &str, ) -> Result<(), AdkError>
Switch to frame by selector.
Sourcepub async fn switch_to_parent_frame(&self) -> Result<(), AdkError>
pub async fn switch_to_parent_frame(&self) -> Result<(), AdkError>
Switch to parent frame.
Sourcepub async fn switch_to_default_content(&self) -> Result<(), AdkError>
pub async fn switch_to_default_content(&self) -> Result<(), AdkError>
Switch to default content.
Sourcepub async fn drag_and_drop(
&self,
source_selector: &str,
target_selector: &str,
) -> Result<(), AdkError>
pub async fn drag_and_drop( &self, source_selector: &str, target_selector: &str, ) -> Result<(), AdkError>
Drag and drop.
Sourcepub async fn right_click(&self, selector: &str) -> Result<(), AdkError>
pub async fn right_click(&self, selector: &str) -> Result<(), AdkError>
Right-click (context click).
Sourcepub async fn get_element_state(
&self,
selector: &str,
) -> Result<ElementState, AdkError>
pub async fn get_element_state( &self, selector: &str, ) -> Result<ElementState, AdkError>
Get element state.
Sourcepub async fn press_key(
&self,
key: &str,
selector: Option<&str>,
modifiers: &[&str],
) -> Result<(), AdkError>
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).
Trait Implementations§
Auto Trait Implementations§
impl !Freeze for BrowserSession
impl !RefUnwindSafe for BrowserSession
impl Send for BrowserSession
impl Sync for BrowserSession
impl Unpin for BrowserSession
impl UnsafeUnpin for BrowserSession
impl !UnwindSafe for BrowserSession
Blanket Implementations§
Source§impl<T> BorrowMut<T> for Twhere
T: ?Sized,
impl<T> BorrowMut<T> for Twhere
T: ?Sized,
Source§fn borrow_mut(&mut self) -> &mut T
fn borrow_mut(&mut self) -> &mut T
Source§impl<T> FutureExt for T
impl<T> FutureExt for T
Source§fn with_context(self, otel_cx: Context) -> WithContext<Self>
fn with_context(self, otel_cx: Context) -> WithContext<Self>
Source§fn with_current_context(self) -> WithContext<Self>
fn with_current_context(self) -> WithContext<Self>
Source§impl<T> Instrument for T
impl<T> Instrument for T
Source§fn instrument(self, span: Span) -> Instrumented<Self> ⓘ
fn instrument(self, span: Span) -> Instrumented<Self> ⓘ
Source§fn in_current_span(self) -> Instrumented<Self> ⓘ
fn in_current_span(self) -> Instrumented<Self> ⓘ
Source§impl<T> IntoEither for T
impl<T> IntoEither for T
Source§fn into_either(self, into_left: bool) -> Either<Self, Self>
fn into_either(self, into_left: bool) -> Either<Self, Self>
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 moreSource§fn into_either_with<F>(self, into_left: F) -> Either<Self, Self>
fn into_either_with<F>(self, into_left: F) -> Either<Self, Self>
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 moreSource§impl<T> IntoRequest<T> for T
impl<T> IntoRequest<T> for T
Source§fn into_request(self) -> Request<T>
fn into_request(self) -> Request<T>
T in a tonic::Request