Skip to content

Commit 601f61b

Browse files
committed
Update UC Mode / CDP Mode
1 parent dbe6fbb commit 601f61b

File tree

11 files changed

+37
-17
lines changed

11 files changed

+37
-17
lines changed

seleniumbase/core/browser_launcher.py

Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -542,6 +542,7 @@ def uc_open_with_cdp_mode(driver, url=None):
542542
driver.cdp_base = loop.run_until_complete(
543543
cdp_util.start(host=cdp_host, port=cdp_port)
544544
)
545+
545546
page = loop.run_until_complete(driver.cdp_base.get(url))
546547
loop.run_until_complete(page.activate())
547548
if not safe_url:

seleniumbase/fixtures/base_case.py

Lines changed: 2 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -4167,13 +4167,13 @@ def get_new_driver(
41674167
device_pixel_ratio=d_p_r,
41684168
browser=browser_name,
41694169
)
4170-
time.sleep(0.2)
4170+
time.sleep(0.16)
41714171
except Exception:
41724172
pass
41734173
finally:
41744174
with suppress(Exception):
41754175
decoy_driver.quit()
4176-
time.sleep(0.1)
4176+
time.sleep(0.08)
41774177
# Launch a web browser
41784178
new_driver = browser_launcher.get_driver(
41794179
browser_name=browser_name,

seleniumbase/plugins/driver_manager.py

Lines changed: 2 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -870,13 +870,13 @@ def Driver(
870870
device_pixel_ratio=d_p_r,
871871
browser=browser_name,
872872
)
873-
time.sleep(0.2)
873+
time.sleep(0.16)
874874
except Exception:
875875
pass
876876
finally:
877877
with suppress(Exception):
878878
decoy_driver.quit()
879-
time.sleep(0.1)
879+
time.sleep(0.08)
880880

881881
driver = browser_launcher.get_driver(
882882
browser_name=browser_name,

seleniumbase/undetected/__init__.py

Lines changed: 13 additions & 6 deletions
Original file line numberDiff line numberDiff line change
@@ -1,4 +1,3 @@
1-
#!/usr/bin/env python3
21
import logging
32
import os
43
import re
@@ -433,10 +432,15 @@ def reconnect(self, timeout=0.1):
433432
time.sleep(timeout)
434433
with suppress(Exception):
435434
self.service.start()
436-
time.sleep(0.012)
437435
with suppress(Exception):
438436
self.start_session()
439-
time.sleep(0.012)
437+
with suppress(Exception):
438+
if self.current_url.startswith("chrome-extension://"):
439+
self.close()
440+
self.service.stop()
441+
self.service.start()
442+
self.start_session()
443+
self._is_connected = True
440444

441445
def disconnect(self):
442446
"""Stops the chromedriver service that runs in the background.
@@ -445,19 +449,22 @@ def disconnect(self):
445449
with suppress(Exception):
446450
self.service.stop()
447451
self._is_connected = False
448-
time.sleep(0.012)
449452

450453
def connect(self):
451454
"""Starts the chromedriver service that runs in the background
452455
and recreates the session."""
453456
if hasattr(self, "service"):
454457
with suppress(Exception):
455458
self.service.start()
456-
time.sleep(0.012)
457459
with suppress(Exception):
458460
self.start_session()
461+
with suppress(Exception):
462+
if self.current_url.startswith("chrome-extension://"):
463+
self.close()
464+
self.service.stop()
465+
self.service.start()
466+
self.start_session()
459467
self._is_connected = True
460-
time.sleep(0.012)
461468

462469
def start_session(self, capabilities=None):
463470
if not capabilities:

seleniumbase/undetected/cdp.py

Lines changed: 0 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -1,4 +1,3 @@
1-
#!/usr/bin/env python3
21
import fasteners
32
import json
43
import logging

seleniumbase/undetected/cdp_driver/config.py

Lines changed: 7 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -5,6 +5,7 @@
55
import sys
66
import tempfile
77
import zipfile
8+
from seleniumbase.config import settings
89
from typing import Union, List, Optional
910

1011
__all__ = [
@@ -101,7 +102,13 @@ def __init__(
101102
# Other keyword args will be accessible by attribute
102103
self.__dict__.update(kwargs)
103104
super().__init__()
105+
start_width = settings.CHROME_START_WIDTH
106+
start_height = settings.CHROME_START_HEIGHT
107+
start_x = settings.WINDOW_START_X
108+
start_y = settings.WINDOW_START_Y
104109
self._default_browser_args = [
110+
"--window-size=%s,%s" % (start_width, start_height),
111+
"--window-position=%s,%s" % (start_x, start_y),
105112
"--remote-allow-origins=*",
106113
"--no-first-run",
107114
"--no-service-autorun",

seleniumbase/undetected/cdp_driver/connection.py

Lines changed: 9 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -292,7 +292,14 @@ async def aclose(self):
292292
if self.listener and self.listener.running:
293293
self.listener.cancel()
294294
self.enabled_domains.clear()
295-
await self.websocket.close()
295+
await asyncio.sleep(0.015)
296+
try:
297+
await self.websocket.close()
298+
except Exception:
299+
logger.debug(
300+
"\n❌ Error closing websocket connection to %s",
301+
self.websocket_url
302+
)
296303
logger.debug(
297304
"\n❌ Closed websocket connection to %s", self.websocket_url
298305
)
@@ -540,6 +547,7 @@ async def listener_loop(self):
540547
self.idle.set()
541548
# Pause for a moment.
542549
# await asyncio.sleep(self.time_before_considered_idle / 10)
550+
await asyncio.sleep(0.015)
543551
continue
544552
except (Exception,) as e:
545553
logger.debug(

seleniumbase/undetected/dprocess.py

Lines changed: 0 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -1,4 +1,3 @@
1-
#!/usr/bin/env python3
21
import os
32
import sys
43
import atexit

seleniumbase/undetected/options.py

Lines changed: 3 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -1,4 +1,3 @@
1-
#!/usr/bin/env python3
21
import json
32
import os
43
from contextlib import suppress
@@ -59,7 +58,9 @@ def handle_prefs(self, user_data_dir):
5958
json.load(f), undot_prefs
6059
)
6160
with suppress(Exception):
62-
with open(prefs_file, encoding="utf-8", mode="w") as f:
61+
with open(
62+
prefs_file, encoding="utf-8", mode="w", errors="ignore"
63+
) as f:
6364
json.dump(undot_prefs, f)
6465
# Remove experimental_options to avoid errors
6566
del self._experimental_options["prefs"]

seleniumbase/undetected/patcher.py

Lines changed: 0 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -1,4 +1,3 @@
1-
#!/usr/bin/env python3
21
import io
32
import logging
43
import os

seleniumbase/undetected/reactor.py

Lines changed: 0 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -1,4 +1,3 @@
1-
#!/usr/bin/env python3
21
import asyncio
32
import json
43
import logging

0 commit comments

Comments
 (0)