|
28 | 28 | os.environ["PATH"] = DRIVER_DIR + os.pathsep + os.environ["PATH"]
|
29 | 29 | EXTENSIONS_DIR = os.path.dirname(os.path.realpath(extensions.__file__))
|
30 | 30 | DISABLE_CSP_ZIP_PATH = "%s/%s" % (EXTENSIONS_DIR, "disable_csp.zip")
|
| 31 | +AD_BLOCK_ZIP_PATH = "%s/%s" % (EXTENSIONS_DIR, "ad_block.zip") |
31 | 32 | RECORDER_ZIP_PATH = "%s/%s" % (EXTENSIONS_DIR, "recorder.zip")
|
32 | 33 | PROXY_ZIP_PATH = proxy_helper.PROXY_ZIP_PATH
|
33 | 34 | PROXY_ZIP_PATH_2 = proxy_helper.PROXY_ZIP_PATH_2
|
@@ -199,8 +200,17 @@ def _add_chrome_disable_csp_extension(chrome_options):
|
199 | 200 | return chrome_options
|
200 | 201 |
|
201 | 202 |
|
| 203 | +def _add_chrome_ad_block_extension(chrome_options): |
| 204 | + """Block Ads on Chromium Browsers with a browser extension. |
| 205 | + See https://github.com/slingamn/simpleblock for details.""" |
| 206 | + ad_block_zip = AD_BLOCK_ZIP_PATH |
| 207 | + chrome_options.add_extension(ad_block_zip) |
| 208 | + return chrome_options |
| 209 | + |
| 210 | + |
202 | 211 | def _add_chrome_recorder_extension(chrome_options):
|
203 |
| - """The SeleniumBase Recorder Chromium extension.""" |
| 212 | + """The SeleniumBase Recorder Chrome/Edge extension. |
| 213 | + https://seleniumbase.io/help_docs/recorder_mode/""" |
204 | 214 | recorder_zip = RECORDER_ZIP_PATH
|
205 | 215 | chrome_options.add_extension(recorder_zip)
|
206 | 216 | return chrome_options
|
@@ -228,6 +238,7 @@ def _set_chrome_options(
|
228 | 238 | devtools,
|
229 | 239 | remote_debug,
|
230 | 240 | swiftshader,
|
| 241 | + ad_block_on, |
231 | 242 | block_images,
|
232 | 243 | chromium_arg,
|
233 | 244 | user_data_dir,
|
@@ -322,10 +333,10 @@ def _set_chrome_options(
|
322 | 333 | chrome_options.add_experimental_option(
|
323 | 334 | "mobileEmulation", emulator_settings
|
324 | 335 | )
|
325 |
| - chrome_options.add_argument("--enable-sync") |
326 | 336 | if (
|
327 | 337 | not proxy_auth
|
328 | 338 | and not disable_csp
|
| 339 | + and not ad_block_on |
329 | 340 | and not recorder_ext
|
330 | 341 | and (not extension_zip and not extension_dir)
|
331 | 342 | ):
|
@@ -391,7 +402,8 @@ def _set_chrome_options(
|
391 | 402 | # Headless Chrome doesn't support extensions, which are required
|
392 | 403 | # for disabling the Content Security Policy on Chrome
|
393 | 404 | chrome_options = _add_chrome_disable_csp_extension(chrome_options)
|
394 |
| - chrome_options.add_argument("--enable-sync") |
| 405 | + if ad_block_on and not headless: |
| 406 | + chrome_options = _add_chrome_ad_block_extension(chrome_options) |
395 | 407 | if recorder_ext and not headless:
|
396 | 408 | chrome_options = _add_chrome_recorder_extension(chrome_options)
|
397 | 409 | if proxy_string:
|
@@ -687,6 +699,7 @@ def get_driver(
|
687 | 699 | devtools=None,
|
688 | 700 | remote_debug=None,
|
689 | 701 | swiftshader=None,
|
| 702 | + ad_block_on=None, |
690 | 703 | block_images=None,
|
691 | 704 | chromium_arg=None,
|
692 | 705 | firefox_arg=None,
|
@@ -760,6 +773,7 @@ def get_driver(
|
760 | 773 | devtools,
|
761 | 774 | remote_debug,
|
762 | 775 | swiftshader,
|
| 776 | + ad_block_on, |
763 | 777 | block_images,
|
764 | 778 | chromium_arg,
|
765 | 779 | firefox_arg,
|
@@ -796,6 +810,7 @@ def get_driver(
|
796 | 810 | devtools,
|
797 | 811 | remote_debug,
|
798 | 812 | swiftshader,
|
| 813 | + ad_block_on, |
799 | 814 | block_images,
|
800 | 815 | chromium_arg,
|
801 | 816 | firefox_arg,
|
@@ -836,6 +851,7 @@ def get_remote_driver(
|
836 | 851 | devtools,
|
837 | 852 | remote_debug,
|
838 | 853 | swiftshader,
|
| 854 | + ad_block_on, |
839 | 855 | block_images,
|
840 | 856 | chromium_arg,
|
841 | 857 | firefox_arg,
|
@@ -900,6 +916,7 @@ def get_remote_driver(
|
900 | 916 | devtools,
|
901 | 917 | remote_debug,
|
902 | 918 | swiftshader,
|
| 919 | + ad_block_on, |
903 | 920 | block_images,
|
904 | 921 | chromium_arg,
|
905 | 922 | user_data_dir,
|
@@ -1053,6 +1070,7 @@ def get_local_driver(
|
1053 | 1070 | devtools,
|
1054 | 1071 | remote_debug,
|
1055 | 1072 | swiftshader,
|
| 1073 | + ad_block_on, |
1056 | 1074 | block_images,
|
1057 | 1075 | chromium_arg,
|
1058 | 1076 | firefox_arg,
|
@@ -1220,6 +1238,7 @@ def get_local_driver(
|
1220 | 1238 | devtools,
|
1221 | 1239 | remote_debug,
|
1222 | 1240 | swiftshader,
|
| 1241 | + ad_block_on, |
1223 | 1242 | block_images,
|
1224 | 1243 | chromium_arg,
|
1225 | 1244 | user_data_dir,
|
@@ -1307,7 +1326,6 @@ def get_local_driver(
|
1307 | 1326 | edge_options.add_experimental_option(
|
1308 | 1327 | "mobileEmulation", emulator_settings
|
1309 | 1328 | )
|
1310 |
| - edge_options.add_argument("--enable-sync") |
1311 | 1329 | if user_data_dir:
|
1312 | 1330 | abs_path = os.path.abspath(user_data_dir)
|
1313 | 1331 | edge_options.add_argument("user-data-dir=%s" % abs_path)
|
@@ -1342,10 +1360,10 @@ def get_local_driver(
|
1342 | 1360 | # Headless Edge doesn't support extensions, which are required
|
1343 | 1361 | # for disabling the Content Security Policy on Edge
|
1344 | 1362 | edge_options = _add_chrome_disable_csp_extension(edge_options)
|
1345 |
| - edge_options.add_argument("--enable-sync") |
| 1363 | + if ad_block_on and not headless: |
| 1364 | + edge_options = _add_chrome_ad_block_extension(edge_options) |
1346 | 1365 | if recorder_ext and not headless:
|
1347 | 1366 | edge_options = _add_chrome_recorder_extension(edge_options)
|
1348 |
| - edge_options.add_argument("--enable-sync") |
1349 | 1367 | if proxy_string:
|
1350 | 1368 | if proxy_auth:
|
1351 | 1369 | edge_options = _add_chrome_proxy_extension(
|
@@ -1431,6 +1449,7 @@ def get_local_driver(
|
1431 | 1449 | devtools,
|
1432 | 1450 | remote_debug,
|
1433 | 1451 | swiftshader,
|
| 1452 | + ad_block_on, |
1434 | 1453 | block_images,
|
1435 | 1454 | chromium_arg,
|
1436 | 1455 | user_data_dir,
|
@@ -1475,6 +1494,7 @@ def get_local_driver(
|
1475 | 1494 | devtools,
|
1476 | 1495 | remote_debug,
|
1477 | 1496 | swiftshader,
|
| 1497 | + ad_block_on, |
1478 | 1498 | block_images,
|
1479 | 1499 | chromium_arg,
|
1480 | 1500 | user_data_dir,
|
@@ -1556,6 +1576,7 @@ def get_local_driver(
|
1556 | 1576 | devtools,
|
1557 | 1577 | remote_debug,
|
1558 | 1578 | swiftshader,
|
| 1579 | + ad_block_on, |
1559 | 1580 | block_images,
|
1560 | 1581 | chromium_arg,
|
1561 | 1582 | user_data_dir,
|
|
0 commit comments