@@ -244,23 +244,7 @@ async def select(
244244 Raise timeout exception when after this many seconds nothing is found.
245245 :type timeout: float,int
246246 """
247- loop = asyncio .get_running_loop ()
248- start_time = loop .time ()
249- selector = selector .strip ()
250- item = None
251- try :
252- item = await self .query_selector (selector )
253- except (Exception , TypeError ):
254- pass
255- while not item :
256- await self
257- item = await self .query_selector (selector )
258- if loop .time () - start_time > timeout :
259- raise asyncio .TimeoutError (
260- "Time ran out while waiting for: {%s}" % selector
261- )
262- await self .sleep (0.5 )
263- return item
247+ return await self .wait_for (selector = selector , timeout = timeout )
264248
265249 async def find_all (
266250 self ,
@@ -333,6 +317,33 @@ async def select_all(
333317 await self .sleep (0.5 )
334318 return items
335319
320+ async def ad_block (self ):
321+ await self .send (cdp .page .navigate ("about:blank" ))
322+ await self .send (cdp .network .enable ())
323+ await self .send (cdp .network .set_blocked_urls (
324+ urls = [
325+ "*cloudflareinsights.com*" ,
326+ "*googlesyndication.com*" ,
327+ "*googletagmanager.com*" ,
328+ "*google-analytics.com*" ,
329+ "*amazon-adsystem.com*" ,
330+ "*adsafeprotected.com*" ,
331+ "*casalemedia.com*" ,
332+ "*doubleclick.net*" ,
333+ "*admanmedia.com*" ,
334+ "*fastclick.net*" ,
335+ "*snigelweb.com*" ,
336+ "*bidswitch.net*" ,
337+ "*pubmatic.com*" ,
338+ "*ad.turn.com*" ,
339+ "*adnxs.com*" ,
340+ "*openx.net*" ,
341+ "*tapad.com*" ,
342+ "*3lift.com*" ,
343+ "*2mdn.net*" ,
344+ ]
345+ ))
346+
336347 async def get (
337348 self ,
338349 url = "about:blank" ,
@@ -350,13 +361,18 @@ async def get(
350361 :param new_window: open new window
351362 :return: Page
352363 """
364+ _cdp_ad_block = None
365+ if hasattr (sb_config , "ad_block_on" ) and sb_config .ad_block_on :
366+ _cdp_ad_block = sb_config .ad_block_on
353367 if not self .browser :
354368 raise AttributeError (
355369 "This page/tab has no browser attribute, "
356370 "so you can't use get()"
357371 )
358372 if new_window and not new_tab :
359373 new_tab = True
374+ if _cdp_ad_block :
375+ await self .ad_block ()
360376 if new_tab :
361377 if hasattr (sb_config , "incognito" ) and sb_config .incognito :
362378 return await self .browser .get (
@@ -705,10 +721,12 @@ async def evaluate(
705721 raise ProtocolException (errors )
706722 if remote_object :
707723 if return_by_value :
708- if remote_object .value :
724+ if remote_object .value is not None :
709725 return remote_object .value
710726 else :
711- return remote_object , errors
727+ if remote_object .deep_serialized_value is not None :
728+ return remote_object .deep_serialized_value .value
729+ return None
712730
713731 async def js_dumps (
714732 self , obj_name : str , return_by_value : Optional [bool ] = True
@@ -1368,7 +1386,9 @@ def __call__(
13681386 :param selector: css selector string
13691387 :type selector: str
13701388 """
1371- return self .wait_for (text , selector , timeout )
1389+ return self .wait_for (
1390+ selector = selector , text = text , timeout = timeout
1391+ )
13721392
13731393 def __eq__ (self , other : Tab ):
13741394 try :
0 commit comments