Activate CDP Mode with the URL and kwargs.
(driver, url=None, **kwargs)
| 637 | |
| 638 | |
| 639 | def uc_open_with_cdp_mode(driver, url=None, **kwargs): |
| 640 | """Activate CDP Mode with the URL and kwargs.""" |
| 641 | import asyncio |
| 642 | from seleniumbase.undetected.cdp_driver import cdp_util |
| 643 | |
| 644 | time.sleep(0.012) |
| 645 | try: |
| 646 | driver.disconnect() |
| 647 | except Exception: |
| 648 | time.sleep(0.012) |
| 649 | driver.disconnect() |
| 650 | |
| 651 | cdp_details = driver._get_cdp_details() |
| 652 | cdp_host = cdp_details[1].split("://")[1].split(":")[0] |
| 653 | cdp_port = int(cdp_details[1].split("://")[1].split(":")[1].split("/")[0]) |
| 654 | |
| 655 | url = shared_utils.fix_url_as_needed(url) |
| 656 | url_protocol = url.split(":")[0] |
| 657 | safe_url = True |
| 658 | if url_protocol not in ["about", "data", "chrome"]: |
| 659 | safe_url = False |
| 660 | |
| 661 | if ( |
| 662 | getattr(driver, "_is_using_cdp", None) |
| 663 | and getattr(driver, "cdp", None) |
| 664 | and hasattr(driver.cdp, "loop") |
| 665 | ): |
| 666 | # CDP Mode was already initialized |
| 667 | driver.cdp.open(url, **kwargs) |
| 668 | if not safe_url: |
| 669 | time.sleep(constants.UC.CDP_MODE_OPEN_WAIT) |
| 670 | if IS_WINDOWS: |
| 671 | time.sleep(constants.UC.EXTRA_WINDOWS_WAIT) |
| 672 | else: |
| 673 | time.sleep(0.012) |
| 674 | return |
| 675 | |
| 676 | headless = False |
| 677 | headed = None |
| 678 | xvfb = None |
| 679 | xvfb_metrics = None |
| 680 | binary_location = None |
| 681 | if hasattr(sb_config, "headless"): |
| 682 | headless = sb_config.headless |
| 683 | if hasattr(sb_config, "headed"): |
| 684 | headed = sb_config.headed |
| 685 | if hasattr(sb_config, "xvfb"): |
| 686 | xvfb = sb_config.xvfb |
| 687 | if hasattr(sb_config, "xvfb_metrics"): |
| 688 | xvfb_metrics = sb_config.xvfb_metrics |
| 689 | if hasattr(sb_config, "binary_location"): |
| 690 | binary_location = sb_config.binary_location |
| 691 | |
| 692 | loop = asyncio.new_event_loop() |
| 693 | asyncio.set_event_loop(loop) |
| 694 | driver.cdp_base = loop.run_until_complete( |
| 695 | cdp_util.start( |
| 696 | host=cdp_host, |
no test coverage detected
searching dependent graphs…