pub struct Tab { /* private fields */ }Expand description
A handle to a browser tab.
Tabs provide methods for navigation, scripting, and element interaction.
Implementations§
Source§impl Tab
impl Tab
Source§impl Tab
impl Tab
Sourcepub async fn switch_to_frame(&self, iframe: &Element) -> Result<Tab>
pub async fn switch_to_frame(&self, iframe: &Element) -> Result<Tab>
Sourcepub async fn switch_to_frame_by_index(&self, index: usize) -> Result<Tab>
pub async fn switch_to_frame_by_index(&self, index: usize) -> Result<Tab>
Sourcepub async fn switch_to_frame_by_url(&self, url_pattern: &str) -> Result<Tab>
pub async fn switch_to_frame_by_url(&self, url_pattern: &str) -> Result<Tab>
Switches to a frame by URL pattern.
Supports wildcards (* for any characters, ? for single character).
§Arguments
url_pattern- URL pattern with optional wildcards
Sourcepub async fn switch_to_parent_frame(&self) -> Result<Tab>
pub async fn switch_to_parent_frame(&self) -> Result<Tab>
Switches to the parent frame.
Sourcepub fn switch_to_main_frame(&self) -> Tab
pub fn switch_to_main_frame(&self) -> Tab
Switches to the main (top-level) frame.
Sourcepub async fn get_frame_count(&self) -> Result<usize>
pub async fn get_frame_count(&self) -> Result<usize>
Gets the count of direct child frames.
Sourcepub async fn get_all_frames(&self) -> Result<Vec<FrameInfo>>
pub async fn get_all_frames(&self) -> Result<Vec<FrameInfo>>
Gets information about all frames in the tab.
Sourcepub fn is_main_frame(&self) -> bool
pub fn is_main_frame(&self) -> bool
Checks if currently in the main frame.
Source§impl Tab
impl Tab
Sourcepub async fn set_block_rules(&self, patterns: &[&str]) -> Result<()>
pub async fn set_block_rules(&self, patterns: &[&str]) -> Result<()>
Sourcepub async fn clear_block_rules(&self) -> Result<()>
pub async fn clear_block_rules(&self) -> Result<()>
Clears all URL block rules.
Sourcepub async fn intercept_request<F>(&self, callback: F) -> Result<InterceptId>
pub async fn intercept_request<F>(&self, callback: F) -> Result<InterceptId>
Sourcepub async fn intercept_request_headers<F>(
&self,
callback: F,
) -> Result<InterceptId>
pub async fn intercept_request_headers<F>( &self, callback: F, ) -> Result<InterceptId>
Intercepts request headers with a callback.
Sourcepub async fn intercept_request_body<F>(
&self,
callback: F,
) -> Result<InterceptId>
pub async fn intercept_request_body<F>( &self, callback: F, ) -> Result<InterceptId>
Intercepts request body for logging (read-only).
Sourcepub async fn intercept_response<F>(&self, callback: F) -> Result<InterceptId>
pub async fn intercept_response<F>(&self, callback: F) -> Result<InterceptId>
Intercepts response headers with a callback.
Sourcepub async fn intercept_response_body<F>(
&self,
callback: F,
) -> Result<InterceptId>
pub async fn intercept_response_body<F>( &self, callback: F, ) -> Result<InterceptId>
Intercepts response body with a callback.
Sourcepub async fn stop_intercept(&self, intercept_id: &InterceptId) -> Result<()>
pub async fn stop_intercept(&self, intercept_id: &InterceptId) -> Result<()>
Stops network interception.
§Arguments
intercept_id- The intercept ID returned from intercept methods
Source§impl Tab
impl Tab
Sourcepub async fn set_proxy(&self, config: ProxyConfig) -> Result<()>
pub async fn set_proxy(&self, config: ProxyConfig) -> Result<()>
Sourcepub async fn clear_proxy(&self) -> Result<()>
pub async fn clear_proxy(&self) -> Result<()>
Clears the proxy for this tab.
Source§impl Tab
impl Tab
Sourcepub async fn local_storage_get(&self, key: &str) -> Result<Option<String>>
pub async fn local_storage_get(&self, key: &str) -> Result<Option<String>>
Gets a value from localStorage.
Sourcepub async fn local_storage_set(&self, key: &str, value: &str) -> Result<()>
pub async fn local_storage_set(&self, key: &str, value: &str) -> Result<()>
Sets a value in localStorage.
Sourcepub async fn local_storage_delete(&self, key: &str) -> Result<()>
pub async fn local_storage_delete(&self, key: &str) -> Result<()>
Deletes a key from localStorage.
Sourcepub async fn local_storage_clear(&self) -> Result<()>
pub async fn local_storage_clear(&self) -> Result<()>
Clears all localStorage.
Source§impl Tab
impl Tab
Sourcepub async fn session_storage_get(&self, key: &str) -> Result<Option<String>>
pub async fn session_storage_get(&self, key: &str) -> Result<Option<String>>
Gets a value from sessionStorage.
Sourcepub async fn session_storage_set(&self, key: &str, value: &str) -> Result<()>
pub async fn session_storage_set(&self, key: &str, value: &str) -> Result<()>
Sets a value in sessionStorage.
Sourcepub async fn session_storage_delete(&self, key: &str) -> Result<()>
pub async fn session_storage_delete(&self, key: &str) -> Result<()>
Deletes a key from sessionStorage.
Sourcepub async fn session_storage_clear(&self) -> Result<()>
pub async fn session_storage_clear(&self) -> Result<()>
Clears all sessionStorage.
Source§impl Tab
impl Tab
Sourcepub async fn execute_script(&self, script: &str) -> Result<Value>
pub async fn execute_script(&self, script: &str) -> Result<Value>
Sourcepub async fn execute_async_script(&self, script: &str) -> Result<Value>
pub async fn execute_async_script(&self, script: &str) -> Result<Value>
Executes asynchronous JavaScript in the page context.
The script should return a Promise or use async/await.
Source§impl Tab
impl Tab
Sourcepub async fn find_element(&self, selector: &str) -> Result<Element>
pub async fn find_element(&self, selector: &str) -> Result<Element>
Finds a single element by CSS selector.
§Errors
Returns Error::ElementNotFound if no matching element exists.
Source§impl Tab
impl Tab
Sourcepub async fn wait_for_element(&self, selector: &str) -> Result<Element>
pub async fn wait_for_element(&self, selector: &str) -> Result<Element>
Waits for an element matching the selector to appear.
Uses MutationObserver (no polling). Times out after 30 seconds.
§Errors
Returns Timeout if element doesn’t appear within 30 seconds.
Sourcepub async fn wait_for_element_timeout(
&self,
selector: &str,
timeout_duration: Duration,
) -> Result<Element>
pub async fn wait_for_element_timeout( &self, selector: &str, timeout_duration: Duration, ) -> Result<Element>
Waits for an element with a custom timeout.
§Arguments
selector- CSS selector to watch fortimeout_duration- Maximum time to wait
Sourcepub async fn on_element_added<F>(
&self,
selector: &str,
callback: F,
) -> Result<SubscriptionId>
pub async fn on_element_added<F>( &self, selector: &str, callback: F, ) -> Result<SubscriptionId>
Registers a callback for when elements matching the selector appear.
§Returns
Subscription ID for later unsubscription.
Sourcepub async fn on_element_removed<F>(
&self,
element_id: &ElementId,
callback: F,
) -> Result<()>
pub async fn on_element_removed<F>( &self, element_id: &ElementId, callback: F, ) -> Result<()>
Registers a callback for when a specific element is removed.
Sourcepub async fn unsubscribe(&self, subscription_id: &SubscriptionId) -> Result<()>
pub async fn unsubscribe(&self, subscription_id: &SubscriptionId) -> Result<()>
Unsubscribes from element observation.