I need help on how to use proxy that has authentication in selenium-webdriver in javascript. If the proxy only use host:port
, the webdriver works fine. But if i use proxy like user:pass@host:port
, the webdriver cant reach the url.
const webdriver = require('selenium-webdriver');
const chrome = require('selenium-webdriver/chrome');
(async function example() {
const proxyUrl = `http://user:pass@host:port`;
const opts = new chrome.Options()
.addArguments(
`--proxy-server=${proxyUrl}`,
);
const driver = new webdriver.Builder()
.forBrowser('chrome')
.setChromeOptions(opts)
.build();
try {
await driver.get("https://ipinfo.io/json");
const pageSource = await driver.getPageSource();
console.log(pageSource);
} finally {
await driver.quit();
}
}());
And this is what i got when i use proxy that has auth:
<script jstcache="0">
var loadTimeDataRaw = {
"details": "Details",
"errorCode": "ERR_NO_SUPPORTED_PROXIES",
"fontfamily": "'Segoe UI', Tahoma, sans-serif",
"fontfamilyMd": "'Segoe UI', Tahoma, sans-serif",
"fontsize": "75%",
"heading": {
"hostName": "ipinfo.io",
"msg": "This site can’t be reached"
},
"hideDetails": "Hide details",
"iconClass": "icon-generic",
"language": "en",
"suggestionsDetails": [],
"suggestionsSummaryList": [],
"summary": {
"failedUrl": "https://ipinfo.io/json",
"hostName": "ipinfo.io",
"msg": "The webpage at u003Cstrong jscontent="failedUrl">u003C/strong> might be temporarily down or it may have moved permanently to a new web address."
},
"textdirection": "ltr",
"title": "ipinfo.io"
};
</script>undefined</body>undefined</html>