I am trying to capture responses using Selenium and undetected, this is working normally using those two:
import undetected_chromedriver as uc
capabilities = DesiredCapabilities.CHROME
capabilities["goog:loggingPrefs"] = {"performance": "ALL"}
driver = uc.Chrome(headless=False, desired_capabilities=capabilities)
driver.get(url)
time.sleep(5)
logs_raw = driver.get_log("performance")
This is working correctly and it logs all the requests and responses, however it does not work in headless mode, so I switched to use Seleniumbase
from seleniumbase import Driver
driver = Driver(uc=True, log_cdp=True, headless=True)
driver.get(url)
time.sleep(5)
logs_raw = driver.get_log("performance")
print(logs_raw)
As my understanding log_cdp is same as "goog:loggingPrefs" https://github.com/seleniumbase/SeleniumBase/issues/2220, however nothing gets logged, both in headless and non-headless and I am not sure what I am doing wrong.
The page gets loaded bypassing the captcha displaying all the data I need.
seleniumbase 4.33.7
Google Chrome 131.0.6778.85
Windows 11 using WSL Ubuntu 22.0.4 LTS
2
Answers
I solved by not using Seleniumbase and instead reverting to my previous attempt by installing
xvfbwrapper
andxvgb
and change my code like this:
There’s a bit more work involved for that, but SeleniumBase CDP Mode is the key to collecting all the requests/responses. Eg:
P.S. I’m the maintainer of SeleniumBase, so I know a few tricks.