Я работаю с Selenium (драйвером Chrome) для тестирования, и мне нужно добавить прокси с аутентификацией . Теперь я использую локальный файл chromedriver и эту инструкцию для авторизации прокси
Но когда я пытаюсь подключиться к удаленному драйверу (используйте standalone-chrome docker)
Что я пытался
Я пытался использовать ту же инструкцию для удаленного драйвера, что и для локального
Создание возможностей:
Это код для создания расширения
def create_extension():
"""
Create extension for auth proxy
"""
manifest_json = """
{
"version": "1.0.0",
"manifest_version": 2,
"name": "Chrome Proxy",
"permissions": [
"proxy",
"tabs",
"unlimitedStorage",
"storage",
"<all_urls>",
"webRequest",
"webRequestBlocking"
],
"background": {
"scripts": ["background.js"]
},
"minimum_chrome_version":"22.0.0"
}
"""
background_js = """
var config = {
mode: "fixed_servers",
rules: {
singleProxy: {
scheme: "http",
host: "%s",
port: parseInt(%s)
},
bypassList: ["localhost"]
}
};
chrome.proxy.settings.set({value: config, scope: "regular"}, function() {});
function callbackFn(details) {
return {
authCredentials: {
username: "%s",
password: "%s"
}
};
}
chrome.webRequest.onAuthRequired.addListener(
callbackFn,
{urls: ["<all_urls>"]},
['blocking']
);
""" % ('proxy_host', 'proxy_port', 'proxy_login', 'proxy_pass')
pluginfile = '/tmp/proxy_auth_plugin.zip'
logger.info("Saving zip plugin file to {}".format(pluginfile))
with zipfile.ZipFile(pluginfile, 'w') as zp:
zp.writestr("manifest.json", manifest_json)
zp.writestr("background.js", background_js)
return pluginfile
def get_chrome_options():
"""
:return: ChromeOptions
"""
extension_path = self.create_extension()
chrome_options = webdriver.ChromeOptions()
chrome_options.add_extension(extension_path)
chrome_options.add_argument("--ignore-certificate-errors")
chrome_options.add_argument("--disable-notifications")
chrome_options.add_argument("--disable-gpu")
chrome_options.add_argument("--disable-dev-shm-usage")
chrome_options.add_argument("--no-sandbox")
chrome_options.add_argument("--headless")
capabilities = chrome_options.to_capabilities()
return chrome_options, capabilities
А как мне запустить драйвер
chrome_options, capabilities = get_chrome_options()
driver = webdriver.Remote(command_executor='localhost:4444/wd/hub', desired_capabilities=capabilities)
И у меня есть ошибки:
selenium.common.exceptions.SessionNotCreatedException: Message: Unable to create session from {
"desiredCapabilities": {
"browserName": "chrome",
"goog:chromeOptions": {
"args": [
"--ignore-certificate-errors",
"--disable-notifications",
"--disable-gpu",
"--disable-dev-shm-usage",
"--no-sandbox",
"--headless"
],
"extensions": "\u002ftmp\u002fproxy_auth_plugin.zip"
},
"version": "",
"platform": "ANY"
},
"capabilities": {
"firstMatch": [
{
"browserName": "chrome",
"goog:chromeOptions": {
"args": [
"--ignore-certificate-errors",
"--disable-notifications",
"--disable-gpu",
"--disable-dev-shm-usage",
"--no-sandbox",
"--headless"
],
"extensions": "\u002ftmp\u002fproxy_auth_plugin.zip"
}
},
{
"browserName": "chrome",
"platformName": "any",
"goog:chromeOptions": {
"args": [
"--ignore-certificate-errors",
"--disable-notifications",
"--disable-gpu",
"--disable-dev-shm-usage",
"--no-sandbox",
"--headless"
],
"extensions": "\u002ftmp\u002fproxy_auth_plugin.zip"
}
}
]
}
}
Build info: version: '3.141.59', revision: 'e82be7d358', time: '2018-11-14T08:25:53'
System info: host: '6b342da0476d', os.name: 'Linux', os.arch: 'amd64', os.version: '4.9.125-linuxkit', java.version: '1.8.0_191'
Driver info: driver.version: unknown
Stacktrace:
at org.openqa.selenium.remote.server.NewSessionPipeline.lambda$null$4 (NewSessionPipeline.java:76)
at java.util.Optional.orElseThrow (Optional.java:290)
at org.openqa.selenium.remote.server.NewSessionPipeline.lambda$createNewSession$5 (NewSessionPipeline.java:75)
at java.util.Optional.orElseGet (Optional.java:267)
at org.openqa.selenium.remote.server.NewSessionPipeline.createNewSession (NewSessionPipeline.java:73)
at org.openqa.selenium.remote.server.commandhandler.BeginSession.execute (BeginSession.java:65)
at org.openqa.selenium.remote.server.WebDriverServlet.lambda$handle$0 (WebDriverServlet.java:235)
at java.util.concurrent.Executors$RunnableAdapter.call (Executors.java:511)
at java.util.concurrent.FutureTask.run (FutureTask.java:266)
at java.util.concurrent.ThreadPoolExecutor.runWorker (ThreadPoolExecutor.java:1149)
at java.util.concurrent.ThreadPoolExecutor$Worker.run (ThreadPoolExecutor.java:624)
at java.lang.Thread.run (Thread.java:748)
С возможностями
proxy = {'address': 'host:port',
'username': 'login',
'password': 'pass'}
capabilities = dict(DesiredCapabilities.CHROME)
capabilities['proxy'] = {'proxyType': 'MANUAL',
'httpProxy': proxy['address'],
'ftpProxy': proxy['address'],
'sslProxy': proxy['address'],
'noProxy': '',
'class': "org.openqa.selenium.Proxy",
'autodetect': False}
capabilities['proxy']['socksUsername'] = proxy['username']
capabilities['proxy']['socksPassword'] = proxy['password']
driver = webdriver.Remote(
command_executor='localhost:4444/wd/hub',
desired_capabilities=capabilities
)
Нет ответа от удаленного браузера с этими возможностями
Я пытался отключить ток goog:chromeOptions
, но это не влияет
Я ожидал авторизации прокси для Удаленного драйвера