Tab

Struct Tab 

Source
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

Source

pub fn tab_id(&self) -> TabId

Returns the tab ID.

Source

pub fn frame_id(&self) -> FrameId

Returns the current frame ID.

Source

pub fn session_id(&self) -> SessionId

Returns the session ID.

Source§

impl Tab

Source

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

Navigates to a URL.

§Arguments
  • url - The URL to navigate to
§Errors

Returns an error if navigation fails.

Source

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

Alias for goto.

Source

pub async fn load_html(&self, html: &str) -> Result<()>

Loads HTML content directly into the page.

Useful for testing with inline HTML without needing a server.

§Arguments
  • html - HTML content to load
§Example
tab.load_html("<html><body><h1>Test</h1></body></html>").await?;
Source

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

Reloads the current page.

Source

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

Navigates back in history.

Source

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

Navigates forward in history.

Source

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

Gets the current page title.

Source

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

Gets the current URL.

Source

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

Focuses this tab (makes it active).

Source

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

Focuses the window containing this tab.

Source

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

Closes this tab.

Source§

impl Tab

Source

pub async fn switch_to_frame(&self, iframe: &Element) -> Result<Tab>

Switches to a frame by iframe element.

Returns a new Tab handle with the updated frame context.

§Arguments
  • iframe - Element reference to an iframe
§Example
let iframe = tab.find_element("iframe#content").await?;
let frame_tab = tab.switch_to_frame(&iframe).await?;
Source

pub async fn switch_to_frame_by_index(&self, index: usize) -> Result<Tab>

Switches to a frame by index (0-based).

§Arguments
  • index - Zero-based index of the frame
Source

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
Source

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

Switches to the parent frame.

Source

pub fn switch_to_main_frame(&self) -> Tab

Switches to the main (top-level) frame.

Source

pub async fn get_frame_count(&self) -> Result<usize>

Gets the count of direct child frames.

Source

pub async fn get_all_frames(&self) -> Result<Vec<FrameInfo>>

Gets information about all frames in the tab.

Source

pub fn is_main_frame(&self) -> bool

Checks if currently in the main frame.

Source§

impl Tab

Source

pub async fn set_block_rules(&self, patterns: &[&str]) -> Result<()>

Sets URL patterns to block.

Patterns support wildcards (*).

§Example
tab.set_block_rules(&["*ads*", "*tracking*"]).await?;
Source

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

Clears all URL block rules.

Source

pub async fn intercept_request<F>(&self, callback: F) -> Result<InterceptId>
where F: Fn(InterceptedRequest) -> RequestAction + Send + Sync + 'static,

Intercepts network requests with a callback.

§Returns

An InterceptId that can be used to stop this intercept.

§Example
use firefox_webdriver::RequestAction;

let id = tab.intercept_request(|req| {
    if req.url.contains("ads") {
        RequestAction::block()
    } else {
        RequestAction::allow()
    }
}).await?;
Source

pub async fn intercept_request_headers<F>( &self, callback: F, ) -> Result<InterceptId>
where F: Fn(InterceptedRequestHeaders) -> HeadersAction + Send + Sync + 'static,

Intercepts request headers with a callback.

Source

pub async fn intercept_request_body<F>( &self, callback: F, ) -> Result<InterceptId>
where F: Fn(InterceptedRequestBody) + Send + Sync + 'static,

Intercepts request body for logging (read-only).

Source

pub async fn intercept_response<F>(&self, callback: F) -> Result<InterceptId>
where F: Fn(InterceptedResponse) -> HeadersAction + Send + Sync + 'static,

Intercepts response headers with a callback.

Source

pub async fn intercept_response_body<F>( &self, callback: F, ) -> Result<InterceptId>
where F: Fn(InterceptedResponseBody) -> BodyAction + Send + Sync + 'static,

Intercepts response body with a callback.

Source

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

Source

pub async fn set_proxy(&self, config: ProxyConfig) -> Result<()>

Sets a proxy for this tab.

Tab-level proxy overrides window-level proxy for this tab only.

§Example
use firefox_webdriver::ProxyConfig;

tab.set_proxy(ProxyConfig::http("proxy.example.com", 8080)).await?;
Source

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

Clears the proxy for this tab.

Source§

impl Tab

Gets a cookie by name.

Sets a cookie.

§Example
use firefox_webdriver::Cookie;

tab.set_cookie(Cookie::new("session", "abc123")).await?;

Deletes a cookie by name.

Source

pub async fn get_all_cookies(&self) -> Result<Vec<Cookie>>

Gets all cookies for the current page.

Source§

impl Tab

Source

pub async fn local_storage_get(&self, key: &str) -> Result<Option<String>>

Gets a value from localStorage.

Source

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

Sets a value in localStorage.

Source

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

Deletes a key from localStorage.

Source

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

Clears all localStorage.

Source§

impl Tab

Source

pub async fn session_storage_get(&self, key: &str) -> Result<Option<String>>

Gets a value from sessionStorage.

Source

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

Sets a value in sessionStorage.

Source

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

Deletes a key from sessionStorage.

Source

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

Clears all sessionStorage.

Source§

impl Tab

Source

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

Executes synchronous JavaScript in the page context.

The script should use return to return a value.

§Example
let title = tab.execute_script("return document.title").await?;
Source

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

Source

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

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

Finds all elements matching a CSS selector.

Source§

impl Tab

Source

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.

Source

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 for
  • timeout_duration - Maximum time to wait
Source

pub async fn on_element_added<F>( &self, selector: &str, callback: F, ) -> Result<SubscriptionId>
where F: Fn(Element) + Send + Sync + 'static,

Registers a callback for when elements matching the selector appear.

§Returns

Subscription ID for later unsubscription.

Source

pub async fn on_element_removed<F>( &self, element_id: &ElementId, callback: F, ) -> Result<()>
where F: Fn() + Send + Sync + 'static,

Registers a callback for when a specific element is removed.

Source

pub async fn unsubscribe(&self, subscription_id: &SubscriptionId) -> Result<()>

Unsubscribes from element observation.

Trait Implementations§

Source§

impl Clone for Tab

Source§

fn clone(&self) -> Tab

Returns a duplicate of the value. Read more
1.0.0 · Source§

fn clone_from(&mut self, source: &Self)

Performs copy-assignment from source. Read more
Source§

impl Debug for Tab

Source§

fn fmt(&self, f: &mut Formatter<'_>) -> Result

Formats the value using the given formatter. Read more

Auto Trait Implementations§

§

impl Freeze for Tab

§

impl !RefUnwindSafe for Tab

§

impl Send for Tab

§

impl Sync for Tab

§

impl Unpin for Tab

§

impl !UnwindSafe for Tab

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> CloneToUninit for T
where T: Clone,

Source§

unsafe fn clone_to_uninit(&self, dest: *mut u8)

🔬This is a nightly-only experimental API. (clone_to_uninit)
Performs copy-assignment from self to dest. 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> Same for T

Source§

type Output = T

Should always be Self
Source§

impl<T> ToOwned for T
where T: Clone,

Source§

type Owned = T

The resulting type after obtaining ownership.
Source§

fn to_owned(&self) -> T

Creates owned data from borrowed data, usually by cloning. Read more
Source§

fn clone_into(&self, target: &mut T)

Uses borrowed data to replace owned data, usually by cloning. 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<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