pub struct ConnectOverCdpBuilder { /* private fields */ }Expand description
Builder for connecting to a browser via CDP.
This builder supports connecting via:
- HTTP endpoint URL (e.g.,
http://localhost:9222) - auto-discovers WebSocket URL - WebSocket URL (e.g.,
ws://localhost:9222/devtools/browser/...) - direct connection
§Example
use viewpoint_core::Browser;
use std::time::Duration;
// Connect via HTTP endpoint (auto-discovers WebSocket URL)
let browser = Browser::connect_over_cdp("http://localhost:9222")
.timeout(Duration::from_secs(10))
.connect()
.await?;
// Connect with custom headers
let browser = Browser::connect_over_cdp("http://remote-host:9222")
.header("Authorization", "Bearer token")
.connect()
.await?;Implementations§
Source§impl ConnectOverCdpBuilder
impl ConnectOverCdpBuilder
Sourcepub fn timeout(self, timeout: Duration) -> Self
pub fn timeout(self, timeout: Duration) -> Self
Set the connection timeout.
Default is 30 seconds.
Sourcepub fn header(self, name: impl Into<String>, value: impl Into<String>) -> Self
pub fn header(self, name: impl Into<String>, value: impl Into<String>) -> Self
Add a custom header for the WebSocket connection.
Headers are sent during the WebSocket upgrade request.
Sourcepub fn headers(self, headers: HashMap<String, String>) -> Self
pub fn headers(self, headers: HashMap<String, String>) -> Self
Add multiple custom headers for the WebSocket connection.
Sourcepub async fn connect(self) -> Result<Browser, BrowserError>
pub async fn connect(self) -> Result<Browser, BrowserError>
Connect to the browser.
If the endpoint URL is an HTTP URL, this will first discover the WebSocket
URL by fetching /json/version. Then it connects to the browser via WebSocket.
§Errors
Returns an error if:
- The endpoint URL is invalid
- The HTTP endpoint doesn’t expose CDP
- The WebSocket connection fails
- The connection times out
Trait Implementations§
Source§impl Clone for ConnectOverCdpBuilder
impl Clone for ConnectOverCdpBuilder
Source§fn clone(&self) -> ConnectOverCdpBuilder
fn clone(&self) -> ConnectOverCdpBuilder
Returns a duplicate of the value. Read more
1.0.0 · Source§fn clone_from(&mut self, source: &Self)
fn clone_from(&mut self, source: &Self)
Performs copy-assignment from
source. Read moreAuto Trait Implementations§
impl Freeze for ConnectOverCdpBuilder
impl RefUnwindSafe for ConnectOverCdpBuilder
impl Send for ConnectOverCdpBuilder
impl Sync for ConnectOverCdpBuilder
impl Unpin for ConnectOverCdpBuilder
impl UnwindSafe for ConnectOverCdpBuilder
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