-
|
Hello. I've been running into an issue with SeleniumBase for a while where the driver doesn't always receive responses in the CDP listener function (which Is why I have been stuck using an old SB version). There have been a few peculiarities that have made this difficult for me to diagnose what exactly the issue is:
I've been able to work this out into a minimal example to reproduce (provided below). I narrowed it down to be added in this commit: 902929a (upgrading to the newest version with this code removed makes the code work perfectly fine--no missed responses). My driver version is 142, so this code path does run. The Do you have any ideas on what I could be doing wrong here with SeleniumBase? Perhaps quitting the driver without doing other cleanup steps (the examples really only show script.pyimport time
from seleniumbase import Driver
urls1 = set()
urls2 = set()
run = 0
def get_driver():
driver = Driver(
undetectable=True, uc_cdp_events=True, driver_version="keep", headless1=True, incognito=True
)
driver.add_cdp_listener("Network.responseReceived", response_received)
driver.get("https://example.com")
return driver
def response_received(data):
url = data["params"]["response"]["url"]
if run == 0:
urls1.add(url)
else:
urls2.add(url)
print("--------------------- Initializing driver ---------------------")
driver = get_driver()
driver.get("https://seleniumbase.io/")
driver.quit()
time.sleep(5)
run = 1
print("--------------------- Initializing driver again ---------------------")
driver = get_driver()
driver.get("https://seleniumbase.io/")
driver.quit()
print()
print("URL comparison")
only_in_first = urls1 - urls2
only_in_second = urls2 - urls1
print(f"URLs only in first run ({len(only_in_first)}):")
for url in only_in_first:
print(f" {url}")
print(f"URLs only in second run ({len(only_in_second)}):")
for url in only_in_second:
print(f" {url}")requirements.txtDockerfileFROM python:3.14-alpine3.22
WORKDIR /app
RUN apk add --update --no-cache chromium chromium-chromedriver uv
RUN adduser -D testuser -h /app
RUN chown -R testuser:testuser /app
USER testuser
COPY requirements.txt ./
RUN uv venv /app/.venv \
&& uv pip install --python /app/.venv/bin/python --no-cache -r requirements.txt
# Make sure the Python virtual environment is used
ENV PATH="/app/.venv/bin:$PATH"
COPY script.py script.py
ENTRYPOINT ["python3", "-u", "script.py"] |
Beta Was this translation helpful? Give feedback.
Replies: 1 comment 7 replies
-
|
Interesting, when I removed the part specific to 133+, it picked up several internal URLs that weren't part of the websites visited: I don't think I can remove it without chrome extensions appearing as window_handles in From what I can tell, the missed responses are only the internal chrome URLs not related to the URLs I'm actually visiting, which is what I would be interested in. Do you have an example where responses were missed that weren't internal chrome URLs? |
Beta Was this translation helpful? Give feedback.
The update is ready. Upgrade to
4.45.8and use the workaround as needed.