Skip to content

Commit c91ebdf

Browse files
shbenzernavin772diemol
authored
[py] Adding Note to enable_webextensions() regarding CDP (plus gen docstring updates) (#15927)
* [py] Adding Note to enable_webextensions() regarding CDP (plus some docstring updates) * format.sh * update error message * Update py/selenium/webdriver/chromium/options.py Per @navin772 suggestions Co-authored-by: Navin Chandra <[email protected]> --------- Co-authored-by: Navin Chandra <[email protected]> Co-authored-by: Diego Molina <[email protected]>
1 parent 093fd7f commit c91ebdf

File tree

2 files changed

+41
-23
lines changed

2 files changed

+41
-23
lines changed

py/selenium/webdriver/chromium/options.py

Lines changed: 34 additions & 19 deletions
Original file line numberDiff line numberDiff line change
@@ -44,8 +44,9 @@ def binary_location(self) -> str:
4444
def binary_location(self, value: str) -> None:
4545
"""Allows you to set where the chromium binary lives.
4646
47-
:Args:
48-
- value: path to the Chromium binary
47+
Parameters:
48+
----------
49+
value: path to the Chromium binary
4950
"""
5051
if not isinstance(value, str):
5152
raise TypeError(self.BINARY_LOCATION_ERROR)
@@ -61,8 +62,9 @@ def debugger_address(self, value: str) -> None:
6162
"""Allows you to set the address of the remote devtools instance that
6263
the ChromeDriver instance will try to connect to during an active wait.
6364
64-
:Args:
65-
- value: address of remote devtools instance if any (hostname[:port])
65+
Parameters:
66+
----------
67+
value: address of remote devtools instance if any (hostname[:port])
6668
"""
6769
if not isinstance(value, str):
6870
raise TypeError("Debugger Address must be a string")
@@ -89,8 +91,9 @@ def add_extension(self, extension: str) -> None:
8991
"""Adds the path to the extension to a list that will be used to
9092
extract it to the ChromeDriver.
9193
92-
:Args:
93-
- extension: path to the \\*.crx file
94+
Parameters:
95+
----------
96+
extension: path to the \\*.crx file
9497
"""
9598
if extension:
9699
extension_to_add = os.path.abspath(os.path.expanduser(extension))
@@ -105,8 +108,9 @@ def add_encoded_extension(self, extension: str) -> None:
105108
"""Adds Base64 encoded string with extension data to a list that will
106109
be used to extract it to the ChromeDriver.
107110
108-
:Args:
109-
- extension: Base64 encoded string with extension data
111+
Parameters:
112+
----------
113+
extension: Base64 encoded string with extension data
110114
"""
111115
if extension:
112116
self._extensions.append(extension)
@@ -121,30 +125,37 @@ def experimental_options(self) -> dict:
121125
def add_experimental_option(self, name: str, value: Union[str, int, dict, list[str]]) -> None:
122126
"""Adds an experimental option which is passed to chromium.
123127
124-
:Args:
128+
Parameters:
129+
----------
125130
name: The experimental option name.
126131
value: The option value.
127132
"""
128133
self._experimental_options[name] = value
129134

130135
@property
131136
def enable_webextensions(self) -> bool:
132-
"""Returns whether webextension support is enabled for Chromium-based browsers.
133-
134-
:Returns: True if webextension support is enabled, False otherwise.
137+
""":Returns: Whether webextension support is enabled for Chromium-based browsers.
138+
True if webextension support is enabled, False otherwise.
135139
"""
136140
return self._enable_webextensions
137141

138142
@enable_webextensions.setter
139143
def enable_webextensions(self, value: bool) -> None:
140144
"""Enables or disables webextension support for Chromium-based browsers.
141145
142-
When enabled, this automatically adds the required Chromium flags:
143-
- --enable-unsafe-extension-debugging
144-
- --remote-debugging-pipe
145-
146-
:Args:
147-
- value: True to enable webextension support, False to disable.
146+
Parameters:
147+
----------
148+
value : bool
149+
True to enable webextension support, False to disable.
150+
151+
Notes:
152+
-----
153+
- When enabled, this automatically adds the required Chromium flags:
154+
- --enable-unsafe-extension-debugging
155+
- --remote-debugging-pipe
156+
- Enabling --remote-debugging-pipe makes the connection b/w chromedriver
157+
and the browser use a pipe instead of a port, disabling many CDP functionalities
158+
like devtools
148159
"""
149160
self._enable_webextensions = value
150161
if value:
@@ -162,7 +173,11 @@ def enable_webextensions(self, value: bool) -> None:
162173

163174
def to_capabilities(self) -> dict:
164175
"""Creates a capabilities with all the options that have been set
165-
:Returns: A dictionary with everything."""
176+
177+
Returns:
178+
-------
179+
dict : a dictionary with all set options
180+
"""
166181
caps = self._caps
167182
chrome_options = self.experimental_options.copy()
168183
if self.mobile_options:

py/selenium/webdriver/remote/webdriver.py

Lines changed: 7 additions & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -1396,10 +1396,13 @@ def _get_cdp_details(self):
13961396
import urllib3
13971397

13981398
http = urllib3.PoolManager()
1399-
if self.caps.get("browserName") == "chrome":
1400-
debugger_address = self.caps.get("goog:chromeOptions").get("debuggerAddress")
1401-
elif self.caps.get("browserName") == "MicrosoftEdge":
1402-
debugger_address = self.caps.get("ms:edgeOptions").get("debuggerAddress")
1399+
try:
1400+
if self.caps.get("browserName") == "chrome":
1401+
debugger_address = self.caps.get("goog:chromeOptions").get("debuggerAddress")
1402+
elif self.caps.get("browserName") == "MicrosoftEdge":
1403+
debugger_address = self.caps.get("ms:edgeOptions").get("debuggerAddress")
1404+
except AttributeError:
1405+
raise WebDriverException("Can't get debugger address.")
14031406

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

0 commit comments

Comments
 (0)