Skip to content

Commit

Permalink
simplify connect
Browse files Browse the repository at this point in the history
  • Loading branch information
mattsse committed Nov 6, 2023
1 parent 2d61cc4 commit efbc73b
Showing 1 changed file with 10 additions and 23 deletions.
33 changes: 10 additions & 23 deletions src/browser.rs
Original file line number Diff line number Diff line change
Expand Up @@ -79,6 +79,16 @@ impl Browser {
///
/// If the URL is a http(s) URL, it will first attempt to retrieve the Websocket URL from the `json/version` endpoint.
pub async fn connect(url: impl Into<String>) -> Result<(Self, Handler)> {
Self::connect_with_config(url, HandlerConfig::default()).await
}

// Connect to an already running chromium instance with a given `HandlerConfig`.
///
/// If the URL is a http(s) URL, it will first attempt to retrieve the Websocket URL from the `json/version` endpoint.
pub async fn connect_with_config(
url: impl Into<String>,
config: HandlerConfig,
) -> Result<(Self, Handler)> {
let mut debug_ws_url = url.into();

if debug_ws_url.starts_with("http") {
Expand Down Expand Up @@ -121,29 +131,6 @@ impl Browser {

let (tx, rx) = channel(1);

let fut = Handler::new(conn, rx, HandlerConfig::default());
let browser_context = fut.default_browser_context().clone();

let browser = Self {
sender: tx,
config: None,
child: None,
debug_ws_url,
browser_context,
};
Ok((browser, fut))
}

// Connect to an already running chromium instance via websocket with HandlerConfig
pub async fn connect_with_config(
debug_ws_url: impl Into<String>,
config: HandlerConfig,
) -> Result<(Self, Handler)> {
let debug_ws_url = debug_ws_url.into();
let conn = Connection::<CdpEventMessage>::connect(&debug_ws_url).await?;

let (tx, rx) = channel(1);

let fut = Handler::new(conn, rx, config);
let browser_context = fut.default_browser_context().clone();

Expand Down

0 comments on commit efbc73b

Please sign in to comment.