Seleniumwire not logging all requests in chrome headless mode

2.6k views Asked by At

I'm trying to capture all network logs using seleniumwire. When chromedriver is in normal mode, it is able to capture all requests. But when it is in headless mode, it is not capturing all requests.

I tried adding sleep(10), assert driver.last_request.response.status_code == 200 but neither helped.

Since seleniumwire is not that popular, I'm adding a sample guide below in the hope of getting people with knowledge of selenium to try a hand to help me fix the problem.

Working with seleniumwire

Installing seleniumwire

pip install seleniumwire

Sample script:

from seleniumwire import webdriver  # Import from seleniumwire

# Create a new instance of the Chrome driver
driver = webdriver.Chrome()

# Go to the YouTube homepage.
driver.get('https://www.youtube.com')

# Access requests via the `requests` attribute
for request in driver.requests:
    if request.response:
        print(
            request.path,
            request.response.status_code,
            request.response.headers['Content-Type']
        )
1

There are 1 answers

0
Kshitiz Mishra On

try to capture all requests

options = {
'ignore_http_methods': []  # Capture all requests, including OPTIONS requests
}
driver = webdriver.Chrome("C:\chromedriver.exe",seleniumwire_options=options)

In default it ignores OPTIONS method