diff --git a/thirtyfour/Cargo.toml b/thirtyfour/Cargo.toml index 6be29eb..02097fd 100644 --- a/thirtyfour/Cargo.toml +++ b/thirtyfour/Cargo.toml @@ -1,6 +1,6 @@ [package] name = "thirtyfour" -version = "0.33.0" +version = "0.33.1" authors = ["Steve Pryde ", "Vrtgs"] edition = "2021" license = "MIT OR Apache-2.0" diff --git a/thirtyfour/src/error.rs b/thirtyfour/src/error.rs index bc697ba..6ef4328 100644 --- a/thirtyfour/src/error.rs +++ b/thirtyfour/src/error.rs @@ -143,6 +143,8 @@ pub enum WebDriverError { InsecureCertificate(WebDriverErrorInfo), #[error("An argument passed to the WebDriver server was invalid: {0}")] InvalidArgument(WebDriverErrorInfo), + #[error("An argument passed to the WebDriver server was invalid: {0}")] + InvalidUrl(url::ParseError), #[error("Invalid cookie domain: {0}")] InvalidCookieDomain(WebDriverErrorInfo), #[error("The element is in an invalid state: {0}")] diff --git a/thirtyfour/src/session/handle.rs b/thirtyfour/src/session/handle.rs index a138093..81dac16 100644 --- a/thirtyfour/src/session/handle.rs +++ b/thirtyfour/src/session/handle.rs @@ -10,7 +10,7 @@ use tokio::fs::File; use tokio::io::AsyncWriteExt; use tokio::runtime::RuntimeFlavor; use tokio::sync::OnceCell; -use url::Url; +use url::{ParseError, Url}; use crate::action_chain::ActionChain; use crate::common::command::{Command, FormatRequestData}; @@ -190,10 +190,17 @@ impl SessionHandle { /// # } /// ``` pub async fn goto(&self, url: impl IntoArcStr) -> WebDriverResult<()> { - let mut url = url.into(); - if !url.starts_with("http") { - url = format!("https://{url}").into(); - } + let url = url.into(); + + let parse_url = |url: Arc| Url::parse(&url).map(|_| url); + let url = parse_url(url.clone()) + .or_else(|e| match e { + ParseError::RelativeUrlWithoutBase => { + parse_url(("https://".to_string() + &*url).into()) + } + e => Err(e), + }) + .map_err(WebDriverError::InvalidUrl)?; self.cmd(Command::NavigateTo(url)).await?; Ok(()) }