|
12 | 12 | import zipfile |
13 | 13 | from selenium import webdriver |
14 | 14 | from selenium.webdriver.chrome.service import Service as ChromeService |
| 15 | +from selenium.webdriver.common.service import utils as service_utils |
15 | 16 | from selenium.webdriver.edge.service import Service as EdgeService |
16 | 17 | from selenium.webdriver.firefox.service import Service as FirefoxService |
17 | 18 | from selenium.webdriver.safari.service import Service as SafariService |
@@ -731,7 +732,12 @@ def _set_chrome_options( |
731 | 732 | # To access the Debugger, go to: chrome://inspect/#devices |
732 | 733 | # while a Chromium driver is running. |
733 | 734 | # Info: https://chromedevtools.github.io/devtools-protocol/ |
734 | | - chrome_options.add_argument("--remote-debugging-port=9222") |
| 735 | + sys_argv = sys.argv |
| 736 | + arg_join = " ".join(sys_argv) |
| 737 | + debug_port = 9222 |
| 738 | + if ("-n" in sys.argv) or (" -n=" in arg_join) or ("-c" in sys.argv): |
| 739 | + debug_port = service_utils.free_port() |
| 740 | + chrome_options.add_argument("--remote-debugging-port=%s" % debug_port) |
735 | 741 | if swiftshader: |
736 | 742 | chrome_options.add_argument("--use-gl=swiftshader") |
737 | 743 | elif not is_using_uc(undetectable, browser_name): |
@@ -2477,7 +2483,12 @@ def get_local_driver( |
2477 | 2483 | # To access the Debugger, go to: edge://inspect/#devices |
2478 | 2484 | # while a Chromium driver is running. |
2479 | 2485 | # Info: https://chromedevtools.github.io/devtools-protocol/ |
2480 | | - edge_options.add_argument("--remote-debugging-port=9222") |
| 2486 | + sys_argv = sys.argv |
| 2487 | + arg_join = " ".join(sys_argv) |
| 2488 | + free_port = 9222 |
| 2489 | + if ("-n" in sys.argv or " -n=" in args or args == "-c"): |
| 2490 | + free_port = service_utils.free_port() |
| 2491 | + edge_options.add_argument("--remote-debugging-port=%s" % free_port) |
2481 | 2492 | if swiftshader: |
2482 | 2493 | edge_options.add_argument("--use-gl=swiftshader") |
2483 | 2494 | else: |
@@ -2527,7 +2538,14 @@ def get_local_driver( |
2527 | 2538 | log_path=os.devnull, |
2528 | 2539 | ) |
2529 | 2540 | # https://stackoverflow.com/a/56638103/7058266 |
2530 | | - edge_options.add_argument("--remote-debugging-port=9222") |
| 2541 | + sys_argv = sys.argv |
| 2542 | + arg_join = " ".join(sys_argv) |
| 2543 | + free_port = 9222 |
| 2544 | + if ("-n" in sys.argv or " -n=" in args or args == "-c"): |
| 2545 | + free_port = service_utils.free_port() |
| 2546 | + edge_options.add_argument( |
| 2547 | + "--remote-debugging-port=%s" % free_port |
| 2548 | + ) |
2531 | 2549 | return Edge(service=service, options=edge_options) |
2532 | 2550 | if not auto_upgrade_edgedriver: |
2533 | 2551 | raise # Not an obvious fix. |
@@ -2593,7 +2611,14 @@ def get_local_driver( |
2593 | 2611 | log_path=os.devnull, |
2594 | 2612 | ) |
2595 | 2613 | # https://stackoverflow.com/a/56638103/7058266 |
2596 | | - edge_options.add_argument("--remote-debugging-port=9222") |
| 2614 | + sys_argv = sys.argv |
| 2615 | + arg_join = " ".join(sys_argv) |
| 2616 | + free_port = 9222 |
| 2617 | + if ("-n" in sys.argv or " -n=" in args or args == "-c"): |
| 2618 | + free_port = service_utils.free_port() |
| 2619 | + edge_options.add_argument( |
| 2620 | + "--remote-debugging-port=%s" % free_port |
| 2621 | + ) |
2597 | 2622 | return Edge(service=service, options=edge_options) |
2598 | 2623 | if not auto_upgrade_edgedriver: |
2599 | 2624 | raise # Not an obvious fix. |
|
0 commit comments