pub struct Tab { /* private fields */ }Expand description
Represents a CDP browser tab (target) session.
Implementations§
Source§impl Tab
impl Tab
Sourcepub async fn set_viewport(&self, viewport: &Viewport) -> Result<&Self>
pub async fn set_viewport(&self, viewport: &Viewport) -> Result<&Self>
Sets the viewport size and device scale factor.
This is similar to Puppeteer’s page.setViewport() and is essential
for getting higher resolution screenshots via deviceScaleFactor.
§Example
ⓘ
let viewport = Viewport::new(1920, 1080)
.with_device_scale_factor(2.0); // 2x resolution for sharper images
tab.set_viewport(&viewport).await?;Sourcepub async fn clear_viewport(&self) -> Result<&Self>
pub async fn clear_viewport(&self) -> Result<&Self>
Clears the viewport override, returning to default browser behavior.
Sourcepub async fn set_content(&self, content: &str) -> Result<&Self>
pub async fn set_content(&self, content: &str) -> Result<&Self>
Sets HTML content and waits for the “load” event.
Sourcepub async fn evaluate_as_string(&self, expression: &str) -> Result<String>
pub async fn evaluate_as_string(&self, expression: &str) -> Result<String>
Evaluates JavaScript and returns the result as a string.
Sourcepub async fn find_element(&self, selector: &str) -> Result<Element<'_>>
pub async fn find_element(&self, selector: &str) -> Result<Element<'_>>
Finds the first element matching the given CSS selector.
Sourcepub async fn wait_for_selector(
&self,
selector: &str,
timeout_ms: u64,
) -> Result<Element<'_>>
pub async fn wait_for_selector( &self, selector: &str, timeout_ms: u64, ) -> Result<Element<'_>>
Waits for an element matching the selector to appear in the DOM.
§Arguments
selector- CSS selector to wait fortimeout_ms- Maximum time to wait in milliseconds
Sourcepub async fn screenshot(&self, opts: CaptureOptions) -> Result<String>
pub async fn screenshot(&self, opts: CaptureOptions) -> Result<String>
Sourcepub async fn activate(&self) -> Result<&Self>
pub async fn activate(&self) -> Result<&Self>
Activates the target tab to bring it to the foreground.
Sourcepub async fn goto(&self, url: &str) -> Result<&Self>
pub async fn goto(&self, url: &str) -> Result<&Self>
Navigates the tab to the specified URL and waits for load.
Sourcepub async fn goto_no_wait(&self, url: &str) -> Result<&Self>
pub async fn goto_no_wait(&self, url: &str) -> Result<&Self>
Navigates to URL without waiting for load event.
Sourcepub fn session_id(&self) -> &str
pub fn session_id(&self) -> &str
Returns the session ID for this tab.
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> 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
Mutably borrows from an owned value. Read more
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>
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 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>
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