Skip to content

Commit 63bfd92

Browse files
committed
Fix issues with Stealthy Playwright Mode
1 parent d8bf665 commit 63bfd92

2 files changed

Lines changed: 31 additions & 16 deletions

File tree

seleniumbase/core/sb_cdp.py

Lines changed: 4 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -128,6 +128,10 @@ def get(self, url, **kwargs):
128128
)
129129
except asyncio.TimeoutError:
130130
print("Timeout loading %s" % url)
131+
except RuntimeError:
132+
self.loop.run_until_complete(
133+
self.page.get(url, **kwargs)
134+
)
131135
url_protocol = url.split(":")[0]
132136
safe_url = True
133137
if url_protocol not in ["about", "data", "chrome"]:

seleniumbase/undetected/cdp_driver/connection.py

Lines changed: 27 additions & 16 deletions
Original file line numberDiff line numberDiff line change
@@ -305,20 +305,31 @@ async def wait(self, t: Union[int, float] = None):
305305
await self.update_target()
306306
loop = asyncio.get_running_loop()
307307
start_time = loop.time()
308-
try:
309-
if isinstance(t, (int, float)):
310-
await asyncio.wait_for(self.listener.idle.wait(), timeout=t)
311-
while (loop.time() - start_time) < t:
312-
await asyncio.sleep(0.1)
313-
else:
314-
await self.listener.idle.wait()
315-
except asyncio.TimeoutError:
316-
if isinstance(t, (int, float)):
317-
# Explicit time is given, which is now passed, so leave now.
318-
return
319-
except AttributeError:
320-
# No listener created yet.
321-
pass
308+
with warnings.catch_warnings():
309+
warnings.filterwarnings(
310+
action="ignore",
311+
category=RuntimeWarning,
312+
message=".*coroutine.*",
313+
)
314+
try:
315+
if isinstance(t, (int, float)):
316+
try:
317+
await asyncio.wait_for(
318+
self.listener.idle.wait(), timeout=t
319+
)
320+
except RuntimeError:
321+
await self.listener.idle.wait()
322+
while (loop.time() - start_time) < t:
323+
await asyncio.sleep(0.1)
324+
else:
325+
await self.listener.idle.wait()
326+
except asyncio.TimeoutError:
327+
if isinstance(t, (int, float)):
328+
# Explicit time that's given has passed, so leave now.
329+
return
330+
except AttributeError:
331+
# No listener created yet.
332+
pass
322333

323334
async def set_locale(self, locale: Optional[str] = None):
324335
"""Sets the Language Locale code via set_user_agent_override."""
@@ -423,9 +434,9 @@ async def send(
423434
await self.websocket.send(tx.message)
424435
with warnings.catch_warnings():
425436
warnings.filterwarnings(
426-
"ignore",
427-
message="coroutine .* was never awaited",
437+
action="ignore",
428438
category=RuntimeWarning,
439+
message=".*coroutine.*",
429440
)
430441
try:
431442
return await tx

0 commit comments

Comments
 (0)