I have some code which initializes a selenium webdriver and opens a chrome page to my router. The router requires basic http authentication which selenium doesn't support. I have managed to discover a way to bypass this authentication with the use of a chrome extension (see below)
background.js
function callbackFn(details) {
return {
authCredentials: {
username: "user",
password: "pass"
}
};
}
chrome.webRequest.onAuthRequired.addListener(
callbackFn,
{urls: ["<all_urls>"]},
['blocking']
);
manifest.json
{
"version": "1.0.0",
"manifest_version": 2,
"name": "Chrome Auto Login",
"permissions": [
"proxy",
"tabs",
"unlimitedStorage",
"storage",
"<all_urls>",
"webRequest",
"webRequestBlocking"
],
"background": {
"scripts": ["background.js"]
},
"minimum_chrome_version":"22.0.0"
}
To verify this functionality I enable the above extension in chrome. I go to my router page with the authentication and it completely bypasses the screen. Which is great as I no longer need selenium to handle this login process.
However, once I add the extension via selenium, I get entirely different results and the code doesn't work the same in automated chrome, as it does in standard chrome.
private class ChromeOptionsEx : ChromeOptions
{
public override ICapabilities ToCapabilities()
{
var r = (DesiredCapabilities)base.ToCapabilities();
r.SetCapability("pageLoadStrategy", "none");
AddExtension(@"ChromeAutoLoginExt.crx");
return r;
}
}
ChromeOptionsEx opt = new ChromeOptionsEx();
m_Driver = new ChromeDriver(opt);
//extension appears but does not bypass router login
m_Driver.Navigate().GoToUrl("chrome://extensions");
The extension appears and its enabled when I launch chrome via selenium but it does not have the same desired results.
Can anyone help?