seleniumbase 4.37.5__py3-none-any.whl → 4.37.7__py3-none-any.whl

This diff represents the content of publicly available package versions that have been released to one of the supported registries. The information contained in this diff is provided for informational purposes only and reflects changes between package versions as they appear in their respective public registries.
@@ -1,2 +1,2 @@
1
1
  # seleniumbase package
2
- __version__ = "4.37.5"
2
+ __version__ = "4.37.7"
@@ -402,7 +402,8 @@ class Chrome(selenium.webdriver.chrome.webdriver.WebDriver):
402
402
 
403
403
  def add_cdp_listener(self, event_name, callback):
404
404
  if (
405
- self.reactor
405
+ hasattr(self, "reactor")
406
+ and self.reactor
406
407
  and self.reactor is not None
407
408
  and isinstance(self.reactor, Reactor)
408
409
  ):
@@ -411,7 +412,11 @@ class Chrome(selenium.webdriver.chrome.webdriver.WebDriver):
411
412
  return False
412
413
 
413
414
  def clear_cdp_listeners(self):
414
- if self.reactor and isinstance(self.reactor, Reactor):
415
+ if (
416
+ hasattr(self, "reactor")
417
+ and self.reactor
418
+ and isinstance(self.reactor, Reactor)
419
+ ):
415
420
  self.reactor.handlers.clear()
416
421
 
417
422
  def window_new(self, url=None):
@@ -581,7 +586,11 @@ class Chrome(selenium.webdriver.chrome.webdriver.WebDriver):
581
586
  finally:
582
587
  with suppress(Exception):
583
588
  self.service._terminate_process()
584
- if self.reactor and hasattr(self.reactor, "event"):
589
+ if (
590
+ hasattr(self, "reactor")
591
+ and self.reactor
592
+ and hasattr(self.reactor, "event")
593
+ ):
585
594
  logger.debug("Shutting down Reactor")
586
595
  with suppress(Exception):
587
596
  self.reactor.event.set()
@@ -287,10 +287,63 @@ class Browser:
287
287
  connection: tab.Tab = next(
288
288
  filter(lambda item: item.type_ == "page", self.targets)
289
289
  )
290
- # Use the tab to navigate to new url
291
290
  if hasattr(sb_config, "_cdp_locale") and sb_config._cdp_locale:
292
291
  await connection.send(cdp.page.navigate("about:blank"))
293
- await connection.set_locale(sb_config._cdp_locale)
292
+ if (
293
+ hasattr(sb_config, "_cdp_user_agent")
294
+ and sb_config._cdp_user_agent
295
+ ):
296
+ pass
297
+ elif (
298
+ hasattr(sb_config, "_cdp_platform")
299
+ and sb_config._cdp_platform
300
+ ):
301
+ pass
302
+ else:
303
+ await connection.set_locale(sb_config._cdp_locale)
304
+ if hasattr(sb_config, "_cdp_timezone") and sb_config._cdp_timezone:
305
+ await connection.send(cdp.page.navigate("about:blank"))
306
+ await connection.set_timezone(sb_config._cdp_timezone)
307
+ if (
308
+ hasattr(sb_config, "_cdp_user_agent")
309
+ and sb_config._cdp_user_agent
310
+ ):
311
+ await connection.send(cdp.page.navigate("about:blank"))
312
+ if hasattr(sb_config, "_cdp_locale") and sb_config._cdp_locale:
313
+ _cdp_platform = None
314
+ if (
315
+ hasattr(sb_config, "_cdp_platform")
316
+ and sb_config._cdp_platform
317
+ ):
318
+ _cdp_platform = sb_config._cdp_platform
319
+ await connection.set_user_agent(
320
+ sb_config._cdp_user_agent,
321
+ sb_config._cdp_locale,
322
+ _cdp_platform,
323
+ )
324
+ else:
325
+ await connection.set_user_agent(sb_config._cdp_user_agent)
326
+ elif (
327
+ hasattr(sb_config, "_cdp_platform") and sb_config._cdp_platform
328
+ ):
329
+ await connection.send(cdp.page.navigate("about:blank"))
330
+ if hasattr(sb_config, "_cdp_locale") and sb_config._cdp_locale:
331
+ _cdp_platform = sb_config._cdp_platform
332
+ await connection.set_user_agent(
333
+ accept_language=sb_config._cdp_locale,
334
+ platform=_cdp_platform,
335
+ )
336
+ else:
337
+ await connection.set_user_agent(
338
+ platform=sb_config._cdp_platform
339
+ )
340
+ if (
341
+ hasattr(sb_config, "_cdp_geolocation")
342
+ and sb_config._cdp_geolocation
343
+ ):
344
+ await connection.send(cdp.page.navigate("about:blank"))
345
+ await connection.set_geolocation(sb_config._cdp_geolocation)
346
+ # Use the tab to navigate to new url
294
347
  frame_id, loader_id, *_ = await connection.send(
295
348
  cdp.page.navigate(url)
296
349
  )
@@ -10,8 +10,10 @@ import types
10
10
  import typing
11
11
  from contextlib import suppress
12
12
  from seleniumbase import config as sb_config
13
+ from seleniumbase import extensions
13
14
  from seleniumbase.config import settings
14
15
  from seleniumbase.core import detect_b_ver
16
+ from seleniumbase.core import download_helper
15
17
  from seleniumbase.core import proxy_helper
16
18
  from seleniumbase.fixtures import constants
17
19
  from seleniumbase.fixtures import shared_utils
@@ -25,7 +27,10 @@ import mycdp as cdp
25
27
 
26
28
  logger = logging.getLogger(__name__)
27
29
  IS_LINUX = shared_utils.is_linux()
30
+ DOWNLOADS_FOLDER = download_helper.get_downloads_folder()
28
31
  PROXY_DIR_LOCK = proxy_helper.PROXY_DIR_LOCK
32
+ EXTENSIONS_DIR = os.path.dirname(os.path.realpath(extensions.__file__))
33
+ AD_BLOCK_ZIP_PATH = os.path.join(EXTENSIONS_DIR, "ad_block.zip")
29
34
  T = typing.TypeVar("T")
30
35
 
31
36
 
@@ -168,6 +173,19 @@ def __add_chrome_ext_dir(extension_dir, dir_path):
168
173
  return extension_dir
169
174
 
170
175
 
176
+ def __unzip_to_new_folder(zip_file, folder):
177
+ proxy_dir_lock = fasteners.InterProcessLock(PROXY_DIR_LOCK)
178
+ with proxy_dir_lock:
179
+ with suppress(Exception):
180
+ shared_utils.make_writable(PROXY_DIR_LOCK)
181
+ if not os.path.exists(folder):
182
+ import zipfile
183
+ zip_ref = zipfile.ZipFile(zip_file, "r")
184
+ os.makedirs(folder)
185
+ zip_ref.extractall(folder)
186
+ zip_ref.close()
187
+
188
+
171
189
  def __add_chrome_proxy_extension(
172
190
  extension_dir,
173
191
  proxy_string,
@@ -231,6 +249,7 @@ async def start(
231
249
  browser_executable_path: Optional[PathLike] = None,
232
250
  browser_args: Optional[List[str]] = None,
233
251
  xvfb_metrics: Optional[List[str]] = None, # "Width,Height" for Linux
252
+ ad_block: Optional[bool] = False,
234
253
  sandbox: Optional[bool] = True,
235
254
  lang: Optional[str] = None, # Set the Language Locale Code
236
255
  host: Optional[str] = None, # Chrome remote-debugging-host
@@ -238,7 +257,10 @@ async def start(
238
257
  xvfb: Optional[int] = None, # Use a special virtual display on Linux
239
258
  headed: Optional[bool] = None, # Override default Xvfb mode on Linux
240
259
  expert: Optional[bool] = None, # Open up closed Shadow-root elements
260
+ agent: Optional[str] = None, # Set the user-agent string
241
261
  proxy: Optional[str] = None, # "host:port" or "user:pass@host:port"
262
+ tzone: Optional[str] = None, # Eg "America/New_York", "Asia/Kolkata"
263
+ geoloc: Optional[list | tuple] = None, # Eg (48.87645, 2.26340)
242
264
  extension_dir: Optional[str] = None, # Chrome extension directory
243
265
  **kwargs: Optional[dict],
244
266
  ) -> Browser:
@@ -296,6 +318,13 @@ async def start(
296
318
  proxy_user,
297
319
  proxy_pass,
298
320
  )
321
+ if ad_block:
322
+ incognito = False
323
+ guest = False
324
+ ad_block_zip = AD_BLOCK_ZIP_PATH
325
+ ad_block_dir = os.path.join(DOWNLOADS_FOLDER, "ad_block")
326
+ __unzip_to_new_folder(ad_block_zip, ad_block_dir)
327
+ extension_dir = __add_chrome_ext_dir(extension_dir, ad_block_dir)
299
328
  if not config:
300
329
  config = Config(
301
330
  user_data_dir,
@@ -329,6 +358,26 @@ async def start(
329
358
  sb_config._cdp_locale = kwargs["locale_code"]
330
359
  else:
331
360
  sb_config._cdp_locale = None
361
+ if tzone:
362
+ sb_config._cdp_timezone = tzone
363
+ elif "timezone" in kwargs:
364
+ sb_config._cdp_timezone = kwargs["timezone"]
365
+ else:
366
+ sb_config._cdp_timezone = None
367
+ if geoloc:
368
+ sb_config._cdp_geolocation = geoloc
369
+ elif "geolocation" in kwargs:
370
+ sb_config._cdp_geolocation = kwargs["geolocation"]
371
+ else:
372
+ sb_config._cdp_geolocation = None
373
+ if agent:
374
+ sb_config._cdp_user_agent = agent
375
+ elif "user_agent" in kwargs:
376
+ sb_config._cdp_user_agent = kwargs["user_agent"]
377
+ else:
378
+ sb_config._cdp_user_agent = None
379
+ if "platform" in kwargs:
380
+ sb_config._cdp_platform = kwargs["platform"]
332
381
  return driver
333
382
 
334
383
 
@@ -292,9 +292,6 @@ class Connection(metaclass=CantTouchThis):
292
292
  Closes the websocket connection. Shouldn't be called manually by users.
293
293
  """
294
294
  if self.websocket and self.websocket.state is not State.CLOSED:
295
- if self.listener and self.listener.running:
296
- self.listener.cancel()
297
- self.enabled_domains.clear()
298
295
  try:
299
296
  await self.websocket.close()
300
297
  except Exception:
@@ -302,6 +299,9 @@ class Connection(metaclass=CantTouchThis):
302
299
  "\n❌ Error closing websocket connection to %s",
303
300
  self.websocket_url
304
301
  )
302
+ if self.listener and self.listener.running:
303
+ self.listener.cancel()
304
+ self.enabled_domains.clear()
305
305
  logger.debug(
306
306
  "\n❌ Closed websocket connection to %s", self.websocket_url
307
307
  )
@@ -348,7 +348,37 @@ class Connection(metaclass=CantTouchThis):
348
348
 
349
349
  async def set_locale(self, locale: Optional[str] = None):
350
350
  """Sets the Language Locale code via set_user_agent_override."""
351
- await self.send(cdp.network.set_user_agent_override("", locale))
351
+ await self.set_user_agent(user_agent="", accept_language=locale)
352
+
353
+ async def set_timezone(self, timezone: Optional[str] = None):
354
+ """Sets the Timezone via set_timezone_override."""
355
+ await self.send(cdp.emulation.set_timezone_override(timezone))
356
+
357
+ async def set_user_agent(
358
+ self,
359
+ user_agent: Optional[str] = "",
360
+ accept_language: Optional[str] = None,
361
+ platform: Optional[str] = None, # navigator.platform
362
+ ):
363
+ """Sets the User Agent via set_user_agent_override."""
364
+ if not user_agent:
365
+ user_agent = ""
366
+ await self.send(cdp.network.set_user_agent_override(
367
+ user_agent=user_agent,
368
+ accept_language=accept_language,
369
+ platform=platform,
370
+ ))
371
+
372
+ async def set_geolocation(self, geolocation: Optional[tuple] = None):
373
+ """Sets the User Agent via set_geolocation_override."""
374
+ await self.send(cdp.browser.grant_permissions(
375
+ permissions=["geolocation"],
376
+ ))
377
+ await self.send(cdp.emulation.set_geolocation_override(
378
+ latitude=geolocation[0],
379
+ longitude=geolocation[1],
380
+ accuracy=100,
381
+ ))
352
382
 
353
383
  def __getattr__(self, item):
354
384
  """:meta private:"""
@@ -549,8 +579,7 @@ class Listener:
549
579
  except asyncio.TimeoutError:
550
580
  self.idle.set()
551
581
  # Pause for a moment.
552
- # await asyncio.sleep(self.time_before_considered_idle / 10)
553
- await asyncio.sleep(0.015)
582
+ await asyncio.sleep(self.time_before_considered_idle / 10)
554
583
  continue
555
584
  except (Exception,) as e:
556
585
  logger.debug(
@@ -1,6 +1,6 @@
1
1
  Metadata-Version: 2.4
2
2
  Name: seleniumbase
3
- Version: 4.37.5
3
+ Version: 4.37.7
4
4
  Summary: A complete web automation framework for end-to-end testing.
5
5
  Home-page: https://github.com/seleniumbase/SeleniumBase
6
6
  Author: Michael Mintz
@@ -62,7 +62,7 @@ License-File: LICENSE
62
62
  Requires-Dist: pip>=25.0.1
63
63
  Requires-Dist: packaging>=25.0
64
64
  Requires-Dist: setuptools~=70.2; python_version < "3.10"
65
- Requires-Dist: setuptools>=79.0.0; python_version >= "3.10"
65
+ Requires-Dist: setuptools>=79.0.1; python_version >= "3.10"
66
66
  Requires-Dist: wheel>=0.45.1
67
67
  Requires-Dist: attrs>=25.3.0
68
68
  Requires-Dist: certifi>=2025.1.31
@@ -72,7 +72,7 @@ Requires-Dist: websockets>=15.0.1; python_version >= "3.9"
72
72
  Requires-Dist: filelock~=3.16.1; python_version < "3.9"
73
73
  Requires-Dist: filelock>=3.18.0; python_version >= "3.9"
74
74
  Requires-Dist: fasteners>=0.19
75
- Requires-Dist: mycdp>=1.1.1
75
+ Requires-Dist: mycdp>=1.2.0
76
76
  Requires-Dist: pynose>=1.5.4
77
77
  Requires-Dist: platformdirs>=4.3.6; python_version < "3.9"
78
78
  Requires-Dist: platformdirs>=4.3.7; python_version >= "3.9"
@@ -97,7 +97,7 @@ Requires-Dist: urllib3<2,>=1.26.20; python_version < "3.10"
97
97
  Requires-Dist: urllib3<2.5.0,>=1.26.20; python_version >= "3.10"
98
98
  Requires-Dist: requests==2.32.3
99
99
  Requires-Dist: sniffio==1.3.1
100
- Requires-Dist: h11==0.14.0
100
+ Requires-Dist: h11==0.16.0
101
101
  Requires-Dist: outcome==1.3.0.post0
102
102
  Requires-Dist: trio==0.27.0; python_version < "3.9"
103
103
  Requires-Dist: trio==0.30.0; python_version >= "3.9"
@@ -3,7 +3,7 @@ sbase/__main__.py,sha256=G0bVB1-DM4PGwQ1KyOupaWCs4ePbChZNNWuX2htim5U,647
3
3
  sbase/steps.py,sha256=_WvAjydKqZfTdnZW9LPKkRty-g-lfdUPmLqnZj6ulcs,43013
4
4
  seleniumbase/__init__.py,sha256=JFEY9P5QJqsa1M6ghzLMH2eIPQyh85iglCaQwg8Y8z4,2498
5
5
  seleniumbase/__main__.py,sha256=dn1p6dgCchmcH1zzTzzQvFwwdQQqnTGH6ULV9m4hv24,654
6
- seleniumbase/__version__.py,sha256=EdOfmZ-Mk9HJpcoyHvSLoCXg-QkbXXcMFikUwtu_L7k,46
6
+ seleniumbase/__version__.py,sha256=ZU4HNYoq3elduI1j6IgiPolitwipkaMBnUux0Mq5m68,46
7
7
  seleniumbase/behave/__init__.py,sha256=47DEQpj8HBSa-_TImW-5JCeuQeRkm5NMpJWZG3hSuFU,0
8
8
  seleniumbase/behave/behave_helper.py,sha256=elkl8P9eLulRAioLstE9baYNM9N_PHBmAOcajX-pH_Y,24198
9
9
  seleniumbase/behave/behave_sb.py,sha256=qQF85LoohJBfrPK5ZcPi50v-pWtOrC9qcN1B3Ki_3tY,59401
@@ -106,7 +106,7 @@ seleniumbase/translate/portuguese.py,sha256=x3P4qxp56UiI41GoaL7JbUvFRYsgXU1EKjTg
106
106
  seleniumbase/translate/russian.py,sha256=TyN9n0b4GRWDEYnHRGw1rfNAscdDmP3F3Y3aySM3C7s,27978
107
107
  seleniumbase/translate/spanish.py,sha256=hh3xgW1Pq122SHYVvJAxFaXhFrjniOVncVbJbfWqOUM,25528
108
108
  seleniumbase/translate/translator.py,sha256=wPhZH6e5NhmebYL1kP2eGxUcVy1gfTb6XCH8ATEPpxE,49238
109
- seleniumbase/undetected/__init__.py,sha256=5TPgl94SdYCLMRqINx0P4BSfRuJZdCh6hGDl54EOZ9g,26738
109
+ seleniumbase/undetected/__init__.py,sha256=95SyFC9vLCHhtT13TIgC2-eIcTiIQNLNvIf70FxyphU,26942
110
110
  seleniumbase/undetected/cdp.py,sha256=G6nLStm1l8PmZlKIyMnFcYMV7HD5kiGb-9BaqPjVP3I,5497
111
111
  seleniumbase/undetected/dprocess.py,sha256=83EV8ZHJWHG1TSUv9JNClBhdgiBXlkCc6mJ--HsoP3k,1681
112
112
  seleniumbase/undetected/options.py,sha256=BoNuwhrG7oOvuLvTwkvsWCF36pMkS1tHCG-XpP4_EkI,3001
@@ -115,10 +115,10 @@ seleniumbase/undetected/reactor.py,sha256=NropaXcO54pzmDq6quR27qPJxab6636H7LRAaq
115
115
  seleniumbase/undetected/webelement.py,sha256=OOpUYbEiOG52KsYYyuDW9tYLdA2SMnukvwQHUdPVn9E,1389
116
116
  seleniumbase/undetected/cdp_driver/__init__.py,sha256=Ga9alwuaZZy4_XOShc0HjgFnNqpPdrcbjAicz5gE7a4,215
117
117
  seleniumbase/undetected/cdp_driver/_contradict.py,sha256=lP4b0h5quAy573ETn_TBbYV889cL1AuPLVInpJ0ZkiU,3183
118
- seleniumbase/undetected/cdp_driver/browser.py,sha256=c-9EWqpD2ZtpDg8edMuw9hYa6GuyOP1qxorNjtsWe1U,30457
119
- seleniumbase/undetected/cdp_driver/cdp_util.py,sha256=oKUEHx220PEFvHLW4dz18i4j1Q6HPTdkKx9QOKAVZ3I,21821
118
+ seleniumbase/undetected/cdp_driver/browser.py,sha256=5nlLQE58JvwooyUVAXQMosr6C-vj2iSpzyldnLZCnLM,32914
119
+ seleniumbase/undetected/cdp_driver/cdp_util.py,sha256=MhiRNf49G_Ee6JkslES-WegTfY2U4uSS3hTNP-GlcGc,23807
120
120
  seleniumbase/undetected/cdp_driver/config.py,sha256=t8KV1Vqa5SQRBq3-gjkHHmj9h85AplAM01asO3AWufs,12507
121
- seleniumbase/undetected/cdp_driver/connection.py,sha256=06yJHDAnQnkxooZDBAJJfPz2Fjn6IIg0eUSbCJ_9JLw,23467
121
+ seleniumbase/undetected/cdp_driver/connection.py,sha256=jccGcDt-TqgknvMNQYpRbhrSMC_74tYs-9YH1NK5UGU,24572
122
122
  seleniumbase/undetected/cdp_driver/element.py,sha256=FIC6v7OmumLCT-_vIc3H4oju_oBbaLpWJUJIKm2c_q4,40467
123
123
  seleniumbase/undetected/cdp_driver/tab.py,sha256=bxkCFKDejQ1xKsX3740RvvrYfC4OBv1mlQ4yWJM6As4,52260
124
124
  seleniumbase/utilities/__init__.py,sha256=47DEQpj8HBSa-_TImW-5JCeuQeRkm5NMpJWZG3hSuFU,0
@@ -135,9 +135,9 @@ seleniumbase/utilities/selenium_grid/start-grid-hub.bat,sha256=Ftq-GrAKRYH2ssDPr
135
135
  seleniumbase/utilities/selenium_grid/start-grid-hub.sh,sha256=KADv0RUHONLL2_I443QFK8PryBpDmKn5Gy0s4o0vDSM,106
136
136
  seleniumbase/utilities/selenium_ide/__init__.py,sha256=47DEQpj8HBSa-_TImW-5JCeuQeRkm5NMpJWZG3hSuFU,0
137
137
  seleniumbase/utilities/selenium_ide/convert_ide.py,sha256=pZFnqEJQEKZPyNFjkLD29s2HPQgCrWW9XJWpCPhWOoM,31691
138
- seleniumbase-4.37.5.dist-info/licenses/LICENSE,sha256=BRblZsX7HyPUjQmYTiyWr_e9tzWvmR3R4SFclM2R3W0,1085
139
- seleniumbase-4.37.5.dist-info/METADATA,sha256=pcoo_2CkyWe5W9TU8X5XQfP81T8h2JGVQDhIqh9XCyE,86879
140
- seleniumbase-4.37.5.dist-info/WHEEL,sha256=pxyMxgL8-pra_rKaQ4drOZAegBVuX-G_4nRHjjgWbmo,91
141
- seleniumbase-4.37.5.dist-info/entry_points.txt,sha256=CNrh2EKNaHYEhO6pP1RJyVLB99LkDDYX7TnUK8xfjqk,623
142
- seleniumbase-4.37.5.dist-info/top_level.txt,sha256=4N97aBOQ8ETCnDnokBsWb07lJfTaq3C1ZzYRxvLMxqU,19
143
- seleniumbase-4.37.5.dist-info/RECORD,,
138
+ seleniumbase-4.37.7.dist-info/licenses/LICENSE,sha256=BRblZsX7HyPUjQmYTiyWr_e9tzWvmR3R4SFclM2R3W0,1085
139
+ seleniumbase-4.37.7.dist-info/METADATA,sha256=62USFVvtKAkiB_nfh6y_ms0lcAW1cl-DQyy-oU2j_qs,86879
140
+ seleniumbase-4.37.7.dist-info/WHEEL,sha256=SmOxYU7pzNKBqASvQJ7DjX3XGUF92lrGhMb3R6_iiqI,91
141
+ seleniumbase-4.37.7.dist-info/entry_points.txt,sha256=CNrh2EKNaHYEhO6pP1RJyVLB99LkDDYX7TnUK8xfjqk,623
142
+ seleniumbase-4.37.7.dist-info/top_level.txt,sha256=4N97aBOQ8ETCnDnokBsWb07lJfTaq3C1ZzYRxvLMxqU,19
143
+ seleniumbase-4.37.7.dist-info/RECORD,,
@@ -1,5 +1,5 @@
1
1
  Wheel-Version: 1.0
2
- Generator: setuptools (79.0.0)
2
+ Generator: setuptools (79.0.1)
3
3
  Root-Is-Purelib: true
4
4
  Tag: py3-none-any
5
5