Trying to use proxies and selenium-wire with an exsiting browser to capture requests. It works when not using the proxies but when i add an argument to the command line it doesn’t capture any requests. Proxies also work without capturing requests.
Command to launch the chrome browser:
chrome --remote-debugging-port=9231 --proxy-server=localhost:12345 --user-data-dir="path/to/chromeprofile" --load-extension="path/to/proxyfiles"
Example code:
from seleniumwire import webdriver
from webdriver_manager.chrome import ChromeDriverManager
from selenium.webdriver.chrome.service import Service
links = ['https://www.google.com/', 'https://www.twitter.com/']
service = Service(executable_path=ChromeDriverManager().install())
chrome_options = webdriver.ChromeOptions()
chrome_options.add_experimental_option("debuggerAddress", "127.0.0.1:9231")
sw_options = {"port": 65535}
driver = webdriver.Chrome(chrome_options=chrome_options,seleniumwire_options=sw_options)
for index, link in enumerate(links):
driver.get(link)
for request in driver.requests:
print(request.url)
driver.quit()
Also, the proxy files that the chrome command is pointing to is:
background.js
var config = {
mode: "fixed_servers",
rules: {
singleProxy: {
scheme: "http",
host: "HOST",
port: PORT
},
bypassList: ["localhost"]
}
};
chrome.proxy.settings.set({value: config, scope: "regular"}, function() {});
function callbackFn(details) {
return {
authCredentials: {
username: "USERNAME",
password: "PASSWORD"
}
};
}
chrome.webRequest.onAuthRequired.addListener(
callbackFn,
{urls: ["<all_urls>"]},
['blocking']
);
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"
}
Thanks for any help in advance.
scone is a new contributor to this site. Take care in asking for clarification, commenting, and answering.
Check out our Code of Conduct.