jonhoo / fantoccini

A high-level API for programmatically interacting with web pages through WebDriver.
Apache License 2.0
1.67k stars 123 forks source link

Proxy with authentication is not supported #112

Closed ghost closed 2 years ago

ghost commented 3 years ago

Hello,

Is there a way to use proxy with authorization. The following code is used for Client configuration

let mut caps = serde_json::map::Map::new();
let opts = serde_json::json!({ "args": ["--headless"] });
caps.insert("moz:firefoxOptions".to_string(), opts.clone());
caps.insert(
    "proxy".to_string(),
    serde_json::json!({
        "proxyType": "manual",
        "httpProxy": proxy,
        "sslProxy": proxy,
    }),
);

let mut client = fantoccini::Client::with_capabilities("http://0.0.0.0:4444", caps).await?;

I tried to pass proxy value in two ways:

Webdriver documentation says that it is possible to include credentials into url. (link to docs)

Also I've found the solution how to pass credentials to alert into geckodriver using Java lib, but I didn't find the way to do it from fantoccini. Maybe it would be useful for solution. (link to comment)

jonhoo commented 3 years ago

Hmm, this seems like it's a bug in geckodriver (or maybe in the webdriver crate), since we don't really do anything "special" with the credentials beyond passing them to the browser backend. Maybe it gets tripped up on capitalization in some way that the Java library deals with automatically? Does it work if you try to run it against chromedriver instead?

jonhoo commented 2 years ago

I'm going to close this under the assumption that this is a driver problem, and not a fantoccini bug.

Niedzwiedzw commented 1 year ago

Hello,

Is there a way to use proxy with authorization. The following code is used for Client configuration

let mut caps = serde_json::map::Map::new();
let opts = serde_json::json!({ "args": ["--headless"] });
caps.insert("moz:firefoxOptions".to_string(), opts.clone());
caps.insert(
    "proxy".to_string(),
    serde_json::json!({
        "proxyType": "manual",
        "httpProxy": proxy,
        "sslProxy": proxy,
    }),
);

let mut client = fantoccini::Client::with_capabilities("http://0.0.0.0:4444", caps).await?;

I tried to pass proxy value in two ways:

* When `proxy = "username:password@45.159.84.222:53002"` I get the following error:
  **`unexpected webdriver error; webdriver returned error: httpProxy is not of the form host[:port]: username:password@45.159.84.222:53002`**

* When `proxy = "45.159.84.222:53002"` (without username and password):
  **`WebDriverError { error: UnexpectedAlertOpen, message: \"Dismissed user prompt dialog: The proxy moz-proxy://45.159.84.222:53002 is requesting a username and password. The site says: “proxy”\", stack: \"\", delete_session: false }`**

* When `proxy = "45.159.84.222:53002"` and proxy config has the following format
{
    "proxyType": "manual",
    "httpProxy": proxy,
    "sslProxy": proxy,
    "socksUsername": "mi892oPJjV",
    "socksPassword": "EoxIdfl910",
}

this error is received unexpected webdriver error; webdriver returned error: Invalid proxy configuration entry: socksPassword

Webdriver documentation says that it is possible to include credentials into url. (link to docs)

Also I've found the solution how to pass credentials to alert into geckodriver using Java lib, but I didn't find the way to do it from fantoccini. Maybe it would be useful for solution. (link to comment)

hey, have you found a solution to this?

maxcountryman commented 5 months ago

This seems like an issue with webdriver, specifically these checks are not to spec, which says: "The host may include credentials."