wkeeling / selenium-wire

Extends Selenium's Python bindings to give you the ability to inspect requests made by the browser.
MIT License
1.9k stars 254 forks source link

Chromeoptions debugger_address #111

Closed lossness closed 4 years ago

lossness commented 4 years ago

OS: Windows 10 1909 CHROME DRIVER: 80 Series CHROME: 81.0.4044.138

using selenium.webdriver.chrome.options Options() and setting the attribute debugger_address "127.0.0.1:9222" breaks capturing requests.

I don't see any threads popping up in the proxy instance on visual studio code debugger either.

When not using debugger address it functions correctly and fills the list.

CHROME_OPTIONS = Options()
CHROME_OPTIONS.debugger_address = "127.0.0.1:9222"

DRIVER = webdriver.Chrome(seleniumwire_options={'verify_ssl': False},
                          options=CHROME_OPTIONS,
                          executable_path=CHROME_DRIVER_PATH)
DRIVER.get("https://github.com/")
for request in DRIVER.requests:
            if request.response:
                print(request.path, request.response.status_code,
                      request.response.body)
wkeeling commented 4 years ago

Thanks - I'll take a look.

lossness commented 4 years ago

Looking at verbose logging, there is a difference in the remote connection POST:

with debugger address enabled:

  1. "firstMatch": [{}] is empty
  2. seems all args are posted twice?
INFO:seleniumwire.proxy.client:Created proxy listening on 127.0.0.1:60742
DEBUG:selenium.webdriver.remote.remote_connection:POST http://127.0.0.1:60743/session {"capabilities": {"firstMatch": [{}], "alwaysMatch": {"browserName": "chrome", "platformName": "any", "proxy": {"proxyType": "manual", "httpProxy": "127.0.0.1:60742", "sslProxy": "127.0.0.1:60742", "noProxy": ""}, "acceptInsecureCerts": true, "goog:chromeOptions": {"extensions": [], "args": [], "debuggerAddress": "127.0.0.1:9222"}}}, "desiredCapabilities": {"browserName": "chrome", "version": "", "platform": "ANY", "proxy": {"proxyType": "manual", "httpProxy": "127.0.0.1:60742", 
"sslProxy": "127.0.0.1:60742", "noProxy": ""}, "acceptInsecureCerts": true, "goog:chromeOptions": {"extensions": [], "args": [], "debuggerAddress": "127.0.0.1:9222"}}}

without debugger address:

INFO:seleniumwire.proxy.client:Created proxy listening on 127.0.0.1:61270
DEBUG:selenium.webdriver.remote.remote_connection:POST http://127.0.0.1:61271/session {"capabilities": {"firstMatch1:61270", "noProxy": ""}, "acceptInsecureCerts": true}}, "desiredCapabilities": {"browserName": "chrome", "version" true}}

Let me know if there's anything I can assist with.

wkeeling commented 4 years ago

Sorry for the delay in coming back on this.

The debugger_address attribute is used to set the address of a Chrome instance that the webdriver should connect to. If there is no Chrome instance listening at that address, then the webdriver will sit and wait. This is the same when using Selenium on it's own, so it is not specific to Selenium Wire.

For the debugger_address to work you first need to manually start a Chrome instance that is listening on the debugger port:

chrome.exe -remote-debugging-port=9222

Now you can start Selenium Wire (or Selenium) using:

CHROME_OPTIONS.debugger_address = "127.0.0.1:9222"