Skip to content

Commit dd03551

Browse files
committed
Make ad_block=True work again on Chrome 142+
1 parent 905c5b7 commit dd03551

File tree

2 files changed

+23
-0
lines changed

2 files changed

+23
-0
lines changed

seleniumbase/undetected/cdp_driver/browser.py

Lines changed: 22 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -293,6 +293,7 @@ async def get(
293293
_cdp_platform = None
294294
_cdp_geolocation = None
295295
_cdp_recorder = None
296+
_cdp_ad_block = None
296297
if (
297298
hasattr(sb_config, "_cdp_timezone") and sb_config._cdp_timezone
298299
):
@@ -311,6 +312,11 @@ async def get(
311312
and sb_config._cdp_geolocation
312313
):
313314
_cdp_geolocation = sb_config._cdp_geolocation
315+
if (
316+
hasattr(sb_config, "ad_block_on")
317+
and sb_config.ad_block_on
318+
):
319+
_cdp_ad_block = sb_config.ad_block_on
314320
if "timezone" in kwargs:
315321
_cdp_timezone = kwargs["timezone"]
316322
elif "tzone" in kwargs:
@@ -347,6 +353,22 @@ async def get(
347353
accept_language=_cdp_locale,
348354
platform=_cdp_platform,
349355
)
356+
if _cdp_ad_block:
357+
await connection.send(cdp.page.navigate("about:blank"))
358+
await connection.send(cdp.network.enable())
359+
await connection.send(cdp.network.set_blocked_urls(
360+
urls=[
361+
"*googlesyndication.com*",
362+
"*googletagmanager.com*",
363+
"*google-analytics.com*",
364+
"*amazon-adsystem.com*",
365+
"*adsafeprotected.com*",
366+
"*doubleclick.net*",
367+
"*fastclick.net*",
368+
"*snigelweb.com*",
369+
"*2mdn.net*",
370+
]
371+
))
350372
if _cdp_geolocation:
351373
await connection.send(cdp.page.navigate("about:blank"))
352374
await connection.set_geolocation(_cdp_geolocation)

seleniumbase/undetected/cdp_driver/cdp_util.py

Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -548,6 +548,7 @@ async def start(
548548
proxy_scheme,
549549
)
550550
if ad_block:
551+
sb_config.ad_block_on = True
551552
incognito = False
552553
guest = False
553554
ad_block_zip = AD_BLOCK_ZIP_PATH

0 commit comments

Comments
 (0)