@@ -296,6 +296,7 @@ async def get(
296296 :param new_window: Open new window
297297 :return: Page
298298 """
299+ await asyncio .sleep (0.005 )
299300 if url and ":" not in url :
300301 url = "https://" + url
301302 if new_tab or new_window :
@@ -307,7 +308,9 @@ async def get(
307308 )
308309 connection : tab .Tab = next (
309310 filter (
310- lambda item : item .type_ == "page" and item .target_id == target_id , # noqa
311+ lambda item : (
312+ item .type_ == "page" and item .target_id == target_id
313+ ),
311314 self .targets ,
312315 )
313316 )
@@ -317,164 +320,166 @@ async def get(
317320 connection : tab .Tab = next (
318321 filter (lambda item : item .type_ == "page" , self .targets )
319322 )
320- _cdp_timezone = None
321- _cdp_user_agent = ""
322- _cdp_locale = None
323- _cdp_platform = None
324- _cdp_disable_csp = None
325- _cdp_geolocation = None
326- _cdp_recorder = None
327- _cdp_ad_block = None
328- if (
329- hasattr (sb_config , "_cdp_timezone" ) and sb_config ._cdp_timezone
330- ):
331- _cdp_timezone = sb_config ._cdp_timezone
332- if (
333- hasattr (sb_config , "_cdp_user_agent" )
334- and sb_config ._cdp_user_agent
335- ):
336- _cdp_user_agent = sb_config ._cdp_user_agent
337- if hasattr (sb_config , "_cdp_locale" ) and sb_config ._cdp_locale :
338- _cdp_locale = sb_config ._cdp_locale
339- if hasattr (sb_config , "_cdp_platform" ) and sb_config ._cdp_platform :
340- _cdp_platform = sb_config ._cdp_platform
323+ await connection .sleep (0.005 )
324+ _cdp_timezone = None
325+ _cdp_user_agent = ""
326+ _cdp_locale = None
327+ _cdp_platform = None
328+ _cdp_disable_csp = None
329+ _cdp_geolocation = None
330+ _cdp_recorder = None
331+ _cdp_ad_block = None
332+ if (
333+ hasattr (sb_config , "_cdp_timezone" ) and sb_config ._cdp_timezone
334+ ):
335+ _cdp_timezone = sb_config ._cdp_timezone
336+ if (
337+ hasattr (sb_config , "_cdp_user_agent" )
338+ and sb_config ._cdp_user_agent
339+ ):
340+ _cdp_user_agent = sb_config ._cdp_user_agent
341+ if hasattr (sb_config , "_cdp_locale" ) and sb_config ._cdp_locale :
342+ _cdp_locale = sb_config ._cdp_locale
343+ if hasattr (sb_config , "_cdp_platform" ) and sb_config ._cdp_platform :
344+ _cdp_platform = sb_config ._cdp_platform
345+ if (
346+ hasattr (sb_config , "_cdp_geolocation" )
347+ and sb_config ._cdp_geolocation
348+ ):
349+ _cdp_geolocation = sb_config ._cdp_geolocation
350+ if (
351+ hasattr (sb_config , "ad_block_on" )
352+ and sb_config .ad_block_on
353+ ):
354+ _cdp_ad_block = sb_config .ad_block_on
355+ if "timezone" in kwargs :
356+ _cdp_timezone = kwargs ["timezone" ]
357+ elif "tzone" in kwargs :
358+ _cdp_timezone = kwargs ["tzone" ]
359+ if "user_agent" in kwargs :
360+ _cdp_user_agent = kwargs ["user_agent" ]
361+ elif "agent" in kwargs :
362+ _cdp_user_agent = kwargs ["agent" ]
363+ if "locale" in kwargs :
364+ _cdp_locale = kwargs ["locale" ]
365+ elif "lang" in kwargs :
366+ _cdp_locale = kwargs ["lang" ]
367+ elif "locale_code" in kwargs :
368+ _cdp_locale = kwargs ["locale_code" ]
369+ if "platform" in kwargs :
370+ _cdp_platform = kwargs ["platform" ]
371+ elif "plat" in kwargs :
372+ _cdp_platform = kwargs ["plat" ]
373+ if "disable_csp" in kwargs :
374+ _cdp_disable_csp = kwargs ["disable_csp" ]
375+ elif hasattr (sb_config , "disable_csp" ):
376+ _cdp_disable_csp = sb_config .disable_csp
377+ if "geolocation" in kwargs :
378+ _cdp_geolocation = kwargs ["geolocation" ]
379+ elif "geoloc" in kwargs :
380+ _cdp_geolocation = kwargs ["geoloc" ]
381+ if "recorder" in kwargs :
382+ _cdp_recorder = kwargs ["recorder" ]
383+ await connection .sleep (0.01 )
384+ await connection .send (cdp .network .enable ())
385+ await connection .sleep (0.01 )
386+ if _cdp_timezone :
387+ await connection .set_timezone (_cdp_timezone )
388+ if _cdp_locale :
389+ await connection .set_locale (_cdp_locale )
390+ if _cdp_user_agent or _cdp_locale or _cdp_platform :
391+ await connection .set_user_agent (
392+ user_agent = _cdp_user_agent ,
393+ accept_language = _cdp_locale ,
394+ platform = _cdp_platform ,
395+ )
396+ if _cdp_ad_block :
397+ await connection .send (cdp .network .set_blocked_urls (
398+ urls = [
399+ "*.cloudflareinsights.com*" ,
400+ "*.googlesyndication.com*" ,
401+ "*.googletagmanager.com*" ,
402+ "*.google-analytics.com*" ,
403+ "*.amazon-adsystem.com*" ,
404+ "*.adsafeprotected.com*" ,
405+ "*.ads.linkedin.com*" ,
406+ "*.casalemedia.com*" ,
407+ "*.doubleclick.net*" ,
408+ "*.admanmedia.com*" ,
409+ "*.quantserve.com*" ,
410+ "*.fastclick.net*" ,
411+ "*.snigelweb.com*" ,
412+ "*.bidswitch.net*" ,
413+ "*.360yield.com*" ,
414+ "*.adthrive.com*" ,
415+ "*.pubmatic.com*" ,
416+ "*.id5-sync.com*" ,
417+ "*.dotomi.com*" ,
418+ "*.adsrvr.org*" ,
419+ "*.atmtd.com*" ,
420+ "*.liadm.com*" ,
421+ "*.loopme.me*" ,
422+ "*.adnxs.com*" ,
423+ "*.openx.net*" ,
424+ "*.tapad.com*" ,
425+ "*.3lift.com*" ,
426+ "*.turn.com*" ,
427+ "*.2mdn.net*" ,
428+ "*.cpx.to*" ,
429+ "*.ad.gt*" ,
430+ ]
431+ ))
432+ if _cdp_geolocation :
433+ await connection .set_geolocation (_cdp_geolocation )
434+ if _cdp_disable_csp :
435+ await connection .send (cdp .page .set_bypass_csp (enabled = True ))
436+ # (The code below is for the Chrome 142 extension fix)
437+ if (
438+ hasattr (sb_config , "_cdp_proxy" )
439+ and sb_config ._cdp_proxy
440+ and "@" in sb_config ._cdp_proxy
441+ and "auth" not in kwargs
442+ ):
443+ username_and_password = sb_config ._cdp_proxy .split ("@" )[0 ]
444+ proxy_user = username_and_password .split (":" )[0 ]
445+ proxy_pass = username_and_password .split (":" )[1 ]
341446 if (
342- hasattr (sb_config , "_cdp_geolocation " )
343- and sb_config . _cdp_geolocation
447+ hasattr (self . main_tab , "_last_auth " )
448+ and self . main_tab . _last_auth == username_and_password
344449 ):
345- _cdp_geolocation = sb_config ._cdp_geolocation
450+ pass # Auth was already set
451+ else :
452+ self .main_tab ._last_auth = username_and_password
453+ await self .set_auth (proxy_user , proxy_pass , self .tabs [0 ])
454+ time .sleep (0.25 )
455+ if "auth" in kwargs and kwargs ["auth" ] and ":" in kwargs ["auth" ]:
456+ username_and_password = kwargs ["auth" ]
457+ proxy_user = username_and_password .split (":" )[0 ]
458+ proxy_pass = username_and_password .split (":" )[1 ]
346459 if (
347- hasattr (sb_config , "ad_block_on " )
348- and sb_config . ad_block_on
460+ hasattr (self . main_tab , "_last_auth " )
461+ and self . main_tab . _last_auth == username_and_password
349462 ):
350- _cdp_ad_block = sb_config .ad_block_on
351- if "timezone" in kwargs :
352- _cdp_timezone = kwargs ["timezone" ]
353- elif "tzone" in kwargs :
354- _cdp_timezone = kwargs ["tzone" ]
355- if "user_agent" in kwargs :
356- _cdp_user_agent = kwargs ["user_agent" ]
357- elif "agent" in kwargs :
358- _cdp_user_agent = kwargs ["agent" ]
359- if "locale" in kwargs :
360- _cdp_locale = kwargs ["locale" ]
361- elif "lang" in kwargs :
362- _cdp_locale = kwargs ["lang" ]
363- elif "locale_code" in kwargs :
364- _cdp_locale = kwargs ["locale_code" ]
365- if "platform" in kwargs :
366- _cdp_platform = kwargs ["platform" ]
367- elif "plat" in kwargs :
368- _cdp_platform = kwargs ["plat" ]
369- if "disable_csp" in kwargs :
370- _cdp_disable_csp = kwargs ["disable_csp" ]
371- elif hasattr (sb_config , "disable_csp" ):
372- _cdp_disable_csp = sb_config .disable_csp
373- if "geolocation" in kwargs :
374- _cdp_geolocation = kwargs ["geolocation" ]
375- elif "geoloc" in kwargs :
376- _cdp_geolocation = kwargs ["geoloc" ]
377- if "recorder" in kwargs :
378- _cdp_recorder = kwargs ["recorder" ]
379- await connection .sleep (0.01 )
380- await connection .send (cdp .network .enable ())
381- await connection .sleep (0.01 )
382- if _cdp_timezone :
383- await connection .set_timezone (_cdp_timezone )
384- if _cdp_locale :
385- await connection .set_locale (_cdp_locale )
386- if _cdp_user_agent or _cdp_locale or _cdp_platform :
387- await connection .set_user_agent (
388- user_agent = _cdp_user_agent ,
389- accept_language = _cdp_locale ,
390- platform = _cdp_platform ,
391- )
392- if _cdp_ad_block :
393- await connection .send (cdp .network .set_blocked_urls (
394- urls = [
395- "*.cloudflareinsights.com*" ,
396- "*.googlesyndication.com*" ,
397- "*.googletagmanager.com*" ,
398- "*.google-analytics.com*" ,
399- "*.amazon-adsystem.com*" ,
400- "*.adsafeprotected.com*" ,
401- "*.ads.linkedin.com*" ,
402- "*.casalemedia.com*" ,
403- "*.doubleclick.net*" ,
404- "*.admanmedia.com*" ,
405- "*.quantserve.com*" ,
406- "*.fastclick.net*" ,
407- "*.snigelweb.com*" ,
408- "*.bidswitch.net*" ,
409- "*.360yield.com*" ,
410- "*.adthrive.com*" ,
411- "*.pubmatic.com*" ,
412- "*.id5-sync.com*" ,
413- "*.dotomi.com*" ,
414- "*.adsrvr.org*" ,
415- "*.atmtd.com*" ,
416- "*.liadm.com*" ,
417- "*.loopme.me*" ,
418- "*.adnxs.com*" ,
419- "*.openx.net*" ,
420- "*.tapad.com*" ,
421- "*.3lift.com*" ,
422- "*.turn.com*" ,
423- "*.2mdn.net*" ,
424- "*.cpx.to*" ,
425- "*.ad.gt*" ,
426- ]
427- ))
428- if _cdp_geolocation :
429- await connection .set_geolocation (_cdp_geolocation )
430- if _cdp_disable_csp :
431- await connection .send (cdp .page .set_bypass_csp (enabled = True ))
463+ pass # Auth was already set
464+ else :
465+ self .main_tab ._last_auth = username_and_password
466+ await self .set_auth (proxy_user , proxy_pass , self .tabs [0 ])
467+ time .sleep (0.25 )
468+ await connection .sleep (0.15 )
469+ frame_id , loader_id , * _ = await connection .send (
470+ cdp .page .navigate (url )
471+ )
472+ if _cdp_recorder :
432473 # (The code below is for the Chrome 142 extension fix)
433- if (
434- hasattr (sb_config , "_cdp_proxy" )
435- and sb_config ._cdp_proxy
436- and "@" in sb_config ._cdp_proxy
437- and "auth" not in kwargs
438- ):
439- username_and_password = sb_config ._cdp_proxy .split ("@" )[0 ]
440- proxy_user = username_and_password .split (":" )[0 ]
441- proxy_pass = username_and_password .split (":" )[1 ]
442- if (
443- hasattr (self .main_tab , "_last_auth" )
444- and self .main_tab ._last_auth == username_and_password
445- ):
446- pass # Auth was already set
447- else :
448- self .main_tab ._last_auth = username_and_password
449- await self .set_auth (proxy_user , proxy_pass , self .tabs [0 ])
450- time .sleep (0.25 )
451- if "auth" in kwargs and kwargs ["auth" ] and ":" in kwargs ["auth" ]:
452- username_and_password = kwargs ["auth" ]
453- proxy_user = username_and_password .split (":" )[0 ]
454- proxy_pass = username_and_password .split (":" )[1 ]
455- if (
456- hasattr (self .main_tab , "_last_auth" )
457- and self .main_tab ._last_auth == username_and_password
458- ):
459- pass # Auth was already set
460- else :
461- self .main_tab ._last_auth = username_and_password
462- await self .set_auth (proxy_user , proxy_pass , self .tabs [0 ])
463- time .sleep (0.25 )
464- await connection .sleep (0.15 )
465- frame_id , loader_id , * _ = await connection .send (
466- cdp .page .navigate (url )
474+ from seleniumbase .js_code .recorder_js import recorder_js
475+ recorder_code = (
476+ """window.onload = function() { %s };""" % recorder_js
467477 )
468- if _cdp_recorder :
469- # (The code below is for the Chrome 142 extension fix)
470- from seleniumbase .js_code .recorder_js import recorder_js
471- recorder_code = (
472- """window.onload = function() { %s };""" % recorder_js
473- )
474- await connection .send (cdp .runtime .evaluate (recorder_code ))
475- # Update the frame_id on the tab
476- connection .frame_id = frame_id
477- connection .browser = self
478+ await connection .send (cdp .runtime .evaluate (recorder_code ))
479+ # Update the frame_id on the tab
480+ connection .frame_id = frame_id
481+ connection .browser = self
482+ # Give settings time to take effect
478483 await connection .sleep (0.25 )
479484 await self .wait (0.05 )
480485 return connection
0 commit comments