Skip to content

[py] Adding Note to enable_webextensions() regarding CDP (plus gen docstring updates) #15927

New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Merged
merged 7 commits into from
Jun 23, 2025
Merged
Show file tree
Hide file tree
Changes from 3 commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
53 changes: 34 additions & 19 deletions py/selenium/webdriver/chromium/options.py
Original file line number Diff line number Diff line change
Expand Up @@ -44,8 +44,9 @@ def binary_location(self) -> str:
def binary_location(self, value: str) -> None:
"""Allows you to set where the chromium binary lives.

:Args:
- value: path to the Chromium binary
Parameters:
----------
value: path to the Chromium binary
"""
if not isinstance(value, str):
raise TypeError(self.BINARY_LOCATION_ERROR)
Expand All @@ -61,8 +62,9 @@ def debugger_address(self, value: str) -> None:
"""Allows you to set the address of the remote devtools instance that
the ChromeDriver instance will try to connect to during an active wait.

:Args:
- value: address of remote devtools instance if any (hostname[:port])
Parameters:
----------
value: address of remote devtools instance if any (hostname[:port])
"""
if not isinstance(value, str):
raise TypeError("Debugger Address must be a string")
Expand All @@ -89,8 +91,9 @@ def add_extension(self, extension: str) -> None:
"""Adds the path to the extension to a list that will be used to
extract it to the ChromeDriver.

:Args:
- extension: path to the \\*.crx file
Parameters:
----------
extension: path to the \\*.crx file
"""
if extension:
extension_to_add = os.path.abspath(os.path.expanduser(extension))
Expand All @@ -105,8 +108,9 @@ def add_encoded_extension(self, extension: str) -> None:
"""Adds Base64 encoded string with extension data to a list that will
be used to extract it to the ChromeDriver.

:Args:
- extension: Base64 encoded string with extension data
Parameters:
----------
extension: Base64 encoded string with extension data
"""
if extension:
self._extensions.append(extension)
Expand All @@ -121,30 +125,37 @@ def experimental_options(self) -> dict:
def add_experimental_option(self, name: str, value: Union[str, int, dict, list[str]]) -> None:
"""Adds an experimental option which is passed to chromium.

:Args:
Parameters:
----------
name: The experimental option name.
value: The option value.
"""
self._experimental_options[name] = value

@property
def enable_webextensions(self) -> bool:
"""Returns whether webextension support is enabled for Chromium-based browsers.

:Returns: True if webextension support is enabled, False otherwise.
""":Returns: Whether webextension support is enabled for Chromium-based browsers.
True if webextension support is enabled, False otherwise.
"""
return self._enable_webextensions

@enable_webextensions.setter
def enable_webextensions(self, value: bool) -> None:
"""Enables or disables webextension support for Chromium-based browsers.

When enabled, this automatically adds the required Chromium flags:
- --enable-unsafe-extension-debugging
- --remote-debugging-pipe

:Args:
- value: True to enable webextension support, False to disable.
Parameters:
----------
value : bool
True to enable webextension support, False to disable.

Notes:
-----
- When enabled, this automatically adds the required Chromium flags:
- --enable-unsafe-extension-debugging
- --remote-debugging-pipe
- Enabling --remote-debugging-pipe makes the connection b/w chromedriver
and the browser a pipe instead of a port, disabling many CDP functionalities
like devtools
"""
self._enable_webextensions = value
if value:
Expand All @@ -162,7 +173,11 @@ def enable_webextensions(self, value: bool) -> None:

def to_capabilities(self) -> dict:
"""Creates a capabilities with all the options that have been set
:Returns: A dictionary with everything."""

Returns:
-------
dict : a dictionary with all set options
"""
caps = self._caps
chrome_options = self.experimental_options.copy()
if self.mobile_options:
Expand Down
11 changes: 7 additions & 4 deletions py/selenium/webdriver/remote/webdriver.py
Original file line number Diff line number Diff line change
Expand Up @@ -1396,10 +1396,13 @@ def _get_cdp_details(self):
import urllib3

http = urllib3.PoolManager()
if self.caps.get("browserName") == "chrome":
debugger_address = self.caps.get("goog:chromeOptions").get("debuggerAddress")
elif self.caps.get("browserName") == "MicrosoftEdge":
debugger_address = self.caps.get("ms:edgeOptions").get("debuggerAddress")
try:
if self.caps.get("browserName") == "chrome":
debugger_address = self.caps.get("goog:chromeOptions").get("debuggerAddress")
elif self.caps.get("browserName") == "MicrosoftEdge":
debugger_address = self.caps.get("ms:edgeOptions").get("debuggerAddress")
except AttributeError:
raise WebDriverException("Can't get debugger address.")

res = http.request("GET", f"http://{debugger_address}/json/version")
data = json.loads(res.data)
Expand Down
Loading