SeleniumHQ / selenium

A browser automation framework and ecosystem.
https://selenium.dev
Apache License 2.0
30.88k stars 8.22k forks source link

[🐛 Bug]: When starting chromedriver with add_argument(f"--load-extension={extension_load}") - BIDI connection make Page.* commands unavailable #13759

Open HermesNWO opened 8 months ago

HermesNWO commented 8 months ago

What happened?

When starting chromedriver with the load-extension argument, BiDi connection won't makes the Page.* commands available/working.

Below easy step to reproduce

How can we reproduce the issue?

... driver loads
driver_options.add_argument(f"--load-extension={extension_load}")
... driver start no headless

async with self.driver.bidi_connection() as connection:
    self.cdp_bidi_main_session, self.cdp_bidi_main_devtools, self.cdp_cdp = connection.session, connection.devtools, connection.cdp
    await self.cdp_bidi_main_session.execute(self.cdp_bidi_main_devtools.page.enable())

Relevant log output

DEBUG:POST http://localhost:34881/session {'capabilities': {'firstMatch': [{}], 'alwaysMatch': {'browserName': 'chrome', 'pageLoadStrategy': <PageLoadStrategy.normal: 'normal'>, 'goog:chromeOptions': {'prefs': {'credentials_enable_service': False, 'profile.password_manager_enabled': False, 'webrtc.ip_handling_policy': 'disable_non_proxied_udp', 'webrtc.multiple_routes_enabled': False, 'webrtc.nonproxied_udp_enabled': False, 'intl.accept_languages': 'fr-FR', 'intl.timezone': 'Europe/Paris'}, 'excludeSwitches': ['enable-automation'], 'extensions': [], 'args': ['--proxy-server=socks5://127.0.0.1:35001', '--enable-logging=true', '--log-level=3', '--no-sandbox', '--ignore-certificate-errors', '--disable-popup-blocking', '--blink-settings=imagesEnabled=true', '--window-position=0,0', '--window-size=1920,1080', '--remote-debugging-port=9222', '--remote-allow-origins=http://localhost:9222', '--load-extension=/home/bb/Documents/$$$/addons/I-still-don-t-care-about-cookies']}}}}
DEBUG:Remote response: status=200 | data={"value":{"capabilities":{"acceptInsecureCerts":false,"browserName":"chrome","browserVersion":"123.0.6312.86","chrome":{"chromedriverVersion":"123.0.6312.86 (9b72c47a053648d405376c5cf07999ed626728da-refs/branch-heads/6312@{#698})","userDataDir":"/tmp/.org.chromium.Chromium.i2pRuK"},"fedcm:accounts":true,"goog:chromeOptions":{"debuggerAddress":"localhost:9222"},"networkConnectionEnabled":false,"pageLoadStrategy":"normal","platformName":"linux","proxy":{},"setWindowRect":true,"strictFileInteractability":false,"timeouts":{"implicit":0,"pageLoad":300000,"script":30000},"unhandledPromptBehavior":"dismiss and notify","webauthn:extension:credBlob":true,"webauthn:extension:largeBlob":true,"webauthn:extension:minPinLength":true,"webauthn:extension:prf":true,"webauthn:virtualAuthenticators":true},"sessionId":"99448360b81ee3f8688cb4f00b1f6e9a"}} | headers=HTTPHeaderDict({'Content-Length': '846', 'Content-Type': 'application/json; charset=utf-8', 'cache-control': 'no-cache'})
DEBUG:Finished Request
DEBUG:POST http://localhost:34881/session/99448360b81ee3f8688cb4f00b1f6e9a/goog/cdp/execute {'cmd': 'Emulation.setGeolocationOverride', 'params': {'latitude': 48.8582, 'longitude': 2.3387, 'accuracy': 1000}}
DEBUG:Remote response: status=200 | data={"value":{}} | headers=HTTPHeaderDict({'Content-Length': '12', 'Content-Type': 'application/json; charset=utf-8', 'cache-control': 'no-cache'})
DEBUG:Finished Request
DEBUG:POST http://localhost:34881/session/99448360b81ee3f8688cb4f00b1f6e9a/goog/cdp/execute {'cmd': 'Emulation.setLocaleOverride', 'params': {'locale': 'fr-FR'}}
DEBUG:Remote response: status=200 | data={"value":{}} | headers=HTTPHeaderDict({'Content-Length': '12', 'Content-Type': 'application/json; charset=utf-8', 'cache-control': 'no-cache'})
DEBUG:Finished Request
DEBUG:POST http://localhost:34881/session/99448360b81ee3f8688cb4f00b1f6e9a/goog/cdp/execute {'cmd': 'Emulation.setTimezoneOverride', 'params': {'timezoneId': 'Europe/Paris'}}
DEBUG:Remote response: status=200 | data={"value":{}} | headers=HTTPHeaderDict({'Content-Length': '12', 'Content-Type': 'application/json; charset=utf-8', 'cache-control': 'no-cache'})
DEBUG:Finished Request
DEBUG:POST http://localhost:34881/session/99448360b81ee3f8688cb4f00b1f6e9a/goog/cdp/execute {'cmd': 'Page.getFrameTree', 'params': {}}
DEBUG:Remote response: status=200 | data={"value":{"frameTree":{"frame":{"adFrameStatus":{"adFrameType":"none"},"crossOriginIsolatedContextType":"NotIsolated","domainAndRegistry":"","gatedAPIFeatures":[],"id":"3E4BA21EACF4205817657C425061EAEB","loaderId":"B55C2BD04DC8AEBCECC275E95F26F952","mimeType":"text/plain","secureContextType":"InsecureScheme","securityOrigin":"://","url":"data:,"}}}} | headers=HTTPHeaderDict({'Content-Length': '351', 'Content-Type': 'application/json; charset=utf-8', 'cache-control': 'no-cache'})
DEBUG:Finished Request
DEBUG:POST http://localhost:34881/session/99448360b81ee3f8688cb4f00b1f6e9a/goog/cdp/execute {'cmd': 'Page.getFrameTree', 'params': {}}
DEBUG:Remote response: status=200 | data={"value":{"frameTree":{"frame":{"adFrameStatus":{"adFrameType":"none"},"crossOriginIsolatedContextType":"NotIsolated","domainAndRegistry":"","gatedAPIFeatures":[],"id":"3E4BA21EACF4205817657C425061EAEB","loaderId":"B55C2BD04DC8AEBCECC275E95F26F952","mimeType":"text/plain","secureContextType":"InsecureScheme","securityOrigin":"://","url":"data:,"}}}} | headers=HTTPHeaderDict({'Content-Length': '351', 'Content-Type': 'application/json; charset=utf-8', 'cache-control': 'no-cache'})
DEBUG:Finished Request
Exception in thread Thread-2 (__capture_targets_creation):
Traceback (most recent call last):
  File "/usr/lib/python3.11/threading.py", line 1045, in _bootstrap_inner
    self.run()
  File "/usr/lib/python3.11/threading.py", line 982, in run
    self._target(*self._args, **self._kwargs)
  File "/home/bb/Documents/$$$/modules/driver_emulation_injector.py", line 159, in __capture_targets_creation
    trio.run(self.__capture_targets_creation_bidi)
  File "/home/bb/.local/lib/python3.11/site-packages/trio/_core/_run.py", line 2262, in run
    raise runner.main_task_outcome.error
  File "/home/bb/Documents/$$$/modules/driver_emulation_injector.py", line 276, in __capture_targets_creation_bidi
    await self.cdp_bidi_main_session.execute(self.cdp_bidi_main_devtools.page.enable())
  File "/home/bb/.local/lib/python3.11/site-packages/selenium/webdriver/common/bidi/cdp.py", line 226, in execute
    raise response
selenium.webdriver.common.bidi.cdp.BrowserError: BrowserError<code=-32601 message='Page.enable' wasn't found> None

Operating System

Linux

Selenium version

4.19.0

What are the browser(s) and version(s) where you see this issue?

Chromedriver 123 - 122

What are the browser driver(s) and version(s) where you see this issue?

Chromedriver 123 - 122

Are you using Selenium Grid?

No response

github-actions[bot] commented 8 months ago

@HermesNWO, thank you for creating this issue. We will troubleshoot it as soon as we can.


Info for maintainers

Triage this issue by using labels.

If information is missing, add a helpful comment and then I-issue-template label.

If the issue is a question, add the I-question label.

If the issue is valid but there is no time to troubleshoot it, consider adding the help wanted label.

If the issue requires changes or fixes from an external project (e.g., ChromeDriver, GeckoDriver, MSEdgeDriver, W3C), add the applicable G-* label, and it will provide the correct link and auto-close the issue.

After troubleshooting the issue, please add the R-awaiting answer label.

Thank you!

diemol commented 8 months ago

Was this working before, or are you trying this for the first time? I believe our BiDi support in Python needs work.

@AutomatedTester do you know if this should be working?

HermesNWO commented 8 months ago

I have also tried with Selenium 4.16.0 and Chromedriver 122 and then updated to see if any chance of work but nothing... And this is the first time I implement BIDI for Target. related, and it doesn't work... For others like Network. it also doesn't work and don't start.

HermesNWO commented 8 months ago

Actually with my different tries, it happen only with this extension : https://chromewebstore.google.com/detail/i-still-dont-care-about-c/edibdbjcniadpccecjdfdjjppcpchdlm, for the others it works.

diemol commented 8 months ago

It seems to be an issue with the extension, as mentioned in the extension reviews.

I will close this as the root cause is outside Selenium.

HermesNWO commented 8 months ago

No this is a real issue, for example it also stop working with this extensions : https://chromewebstore.google.com/detail/ember-inspector/bmdblncegkenkacieihfhpjfppoconhi

HermesNWO commented 8 months ago

Okay I have found the solution : after reading cdps logs, we can see that the initial BiDi session is using the first target found in the list to make a general session. Indeed we don't want to attach to the first but the last element of the list :

Modify async def bidi_connection(self): in webdriver.py and use -1 instead of 0

github-actions[bot] commented 4 months ago

This issue is looking for contributors.

Please comment below or reach out to us through our IRC/Slack/Matrix channels if you are interested.

Delta456 commented 1 month ago

@HermesNWO Hi, can the issue still be reproduced, if so can you share the whole code snippet? I believe I am still missing something so I can't reproduce.