Update CDP Mode
This commit is contained in:
parent
44ba6a00a4
commit
a2e8bb7733
|
@ -368,6 +368,9 @@ sb.cdp.get_element_attribute(selector, attribute)
|
||||||
sb.cdp.get_element_html(selector)
|
sb.cdp.get_element_html(selector)
|
||||||
sb.cdp.set_locale(locale)
|
sb.cdp.set_locale(locale)
|
||||||
sb.cdp.set_attributes(selector, attribute, value)
|
sb.cdp.set_attributes(selector, attribute, value)
|
||||||
|
sb.cdp.gui_press_key(key)
|
||||||
|
sb.cdp.gui_press_keys(keys)
|
||||||
|
sb.cdp.gui_write(text)
|
||||||
sb.cdp.gui_click_x_y(x, y)
|
sb.cdp.gui_click_x_y(x, y)
|
||||||
sb.cdp.gui_click_element(selector)
|
sb.cdp.gui_click_element(selector)
|
||||||
sb.cdp.internalize_links()
|
sb.cdp.internalize_links()
|
||||||
|
|
|
@ -620,6 +620,9 @@ def uc_open_with_cdp_mode(driver, url=None):
|
||||||
cdp.reset_window_size = CDPM.reset_window_size
|
cdp.reset_window_size = CDPM.reset_window_size
|
||||||
cdp.set_locale = CDPM.set_locale
|
cdp.set_locale = CDPM.set_locale
|
||||||
cdp.set_attributes = CDPM.set_attributes
|
cdp.set_attributes = CDPM.set_attributes
|
||||||
|
cdp.gui_press_key = CDPM.gui_press_key
|
||||||
|
cdp.gui_press_keys = CDPM.gui_press_keys
|
||||||
|
cdp.gui_write = CDPM.gui_write
|
||||||
cdp.gui_click_x_y = CDPM.gui_click_x_y
|
cdp.gui_click_x_y = CDPM.gui_click_x_y
|
||||||
cdp.gui_click_element = CDPM.gui_click_element
|
cdp.gui_click_element = CDPM.gui_click_element
|
||||||
cdp.internalize_links = CDPM.internalize_links
|
cdp.internalize_links = CDPM.internalize_links
|
||||||
|
@ -721,6 +724,9 @@ def uc_click(
|
||||||
timeout=settings.SMALL_TIMEOUT,
|
timeout=settings.SMALL_TIMEOUT,
|
||||||
reconnect_time=None,
|
reconnect_time=None,
|
||||||
):
|
):
|
||||||
|
if __is_cdp_swap_needed(driver):
|
||||||
|
driver.cdp.click(selector)
|
||||||
|
return
|
||||||
with suppress(Exception):
|
with suppress(Exception):
|
||||||
rct = float(by) # Add shortcut: driver.uc_click(selector, RCT)
|
rct = float(by) # Add shortcut: driver.uc_click(selector, RCT)
|
||||||
if not reconnect_time:
|
if not reconnect_time:
|
||||||
|
|
|
@ -942,6 +942,45 @@ class CDPMethods():
|
||||||
)
|
)
|
||||||
return pyautogui_copy
|
return pyautogui_copy
|
||||||
|
|
||||||
|
def gui_press_key(self, key):
|
||||||
|
self.__install_pyautogui_if_missing()
|
||||||
|
import pyautogui
|
||||||
|
pyautogui = self.__get_configured_pyautogui(pyautogui)
|
||||||
|
gui_lock = fasteners.InterProcessLock(
|
||||||
|
constants.MultiBrowser.PYAUTOGUILOCK
|
||||||
|
)
|
||||||
|
with gui_lock:
|
||||||
|
pyautogui.press(key)
|
||||||
|
time.sleep(0.0375)
|
||||||
|
self.__slow_mode_pause_if_set()
|
||||||
|
self.loop.run_until_complete(self.page.wait())
|
||||||
|
|
||||||
|
def gui_press_keys(self, keys):
|
||||||
|
self.__install_pyautogui_if_missing()
|
||||||
|
import pyautogui
|
||||||
|
pyautogui = self.__get_configured_pyautogui(pyautogui)
|
||||||
|
gui_lock = fasteners.InterProcessLock(
|
||||||
|
constants.MultiBrowser.PYAUTOGUILOCK
|
||||||
|
)
|
||||||
|
with gui_lock:
|
||||||
|
for key in keys:
|
||||||
|
pyautogui.press(key)
|
||||||
|
time.sleep(0.0375)
|
||||||
|
self.__slow_mode_pause_if_set()
|
||||||
|
self.loop.run_until_complete(self.page.wait())
|
||||||
|
|
||||||
|
def gui_write(self, text):
|
||||||
|
self.__install_pyautogui_if_missing()
|
||||||
|
import pyautogui
|
||||||
|
pyautogui = self.__get_configured_pyautogui(pyautogui)
|
||||||
|
gui_lock = fasteners.InterProcessLock(
|
||||||
|
constants.MultiBrowser.PYAUTOGUILOCK
|
||||||
|
)
|
||||||
|
with gui_lock:
|
||||||
|
pyautogui.write(text)
|
||||||
|
self.__slow_mode_pause_if_set()
|
||||||
|
self.loop.run_until_complete(self.page.wait())
|
||||||
|
|
||||||
def __gui_click_x_y(self, x, y, timeframe=0.25, uc_lock=False):
|
def __gui_click_x_y(self, x, y, timeframe=0.25, uc_lock=False):
|
||||||
self.__install_pyautogui_if_missing()
|
self.__install_pyautogui_if_missing()
|
||||||
import pyautogui
|
import pyautogui
|
||||||
|
|
|
@ -550,11 +550,7 @@ def Driver(
|
||||||
or uc_sub
|
or uc_sub
|
||||||
):
|
):
|
||||||
undetectable = True
|
undetectable = True
|
||||||
if (
|
if undetectable or undetected or uc:
|
||||||
(undetectable or undetected or uc)
|
|
||||||
and (uc_subprocess is None)
|
|
||||||
and (uc_sub is None)
|
|
||||||
):
|
|
||||||
uc_subprocess = True # Use UC as a subprocess by default.
|
uc_subprocess = True # Use UC as a subprocess by default.
|
||||||
elif (
|
elif (
|
||||||
"--undetectable" in sys_argv
|
"--undetectable" in sys_argv
|
||||||
|
|
|
@ -608,11 +608,7 @@ def SB(
|
||||||
or uc_sub
|
or uc_sub
|
||||||
):
|
):
|
||||||
undetectable = True
|
undetectable = True
|
||||||
if (
|
if undetectable or undetected or uc:
|
||||||
(undetectable or undetected or uc)
|
|
||||||
and (uc_subprocess is None)
|
|
||||||
and (uc_sub is None)
|
|
||||||
):
|
|
||||||
uc_subprocess = True # Use UC as a subprocess by default.
|
uc_subprocess = True # Use UC as a subprocess by default.
|
||||||
elif (
|
elif (
|
||||||
"--undetectable" in sys_argv
|
"--undetectable" in sys_argv
|
||||||
|
|
|
@ -18,6 +18,7 @@ from typing import (
|
||||||
TypeVar,
|
TypeVar,
|
||||||
)
|
)
|
||||||
import websockets
|
import websockets
|
||||||
|
from websockets.protocol import State
|
||||||
from . import cdp_util as util
|
from . import cdp_util as util
|
||||||
import mycdp as cdp
|
import mycdp as cdp
|
||||||
import mycdp.network
|
import mycdp.network
|
||||||
|
@ -261,7 +262,7 @@ class Connection(metaclass=CantTouchThis):
|
||||||
"""
|
"""
|
||||||
Opens the websocket connection. Shouldn't be called manually by users.
|
Opens the websocket connection. Shouldn't be called manually by users.
|
||||||
"""
|
"""
|
||||||
if not self.websocket or self.websocket.closed:
|
if not self.websocket or self.websocket.state is State.CLOSED:
|
||||||
try:
|
try:
|
||||||
self.websocket = await websockets.connect(
|
self.websocket = await websockets.connect(
|
||||||
self.websocket_url,
|
self.websocket_url,
|
||||||
|
@ -288,7 +289,7 @@ class Connection(metaclass=CantTouchThis):
|
||||||
"""
|
"""
|
||||||
Closes the websocket connection. Shouldn't be called manually by users.
|
Closes the websocket connection. Shouldn't be called manually by users.
|
||||||
"""
|
"""
|
||||||
if self.websocket and not self.websocket.closed:
|
if self.websocket and self.websocket.state is not State.CLOSED:
|
||||||
if self.listener and self.listener.running:
|
if self.listener and self.listener.running:
|
||||||
self.listener.cancel()
|
self.listener.cancel()
|
||||||
self.enabled_domains.clear()
|
self.enabled_domains.clear()
|
||||||
|
@ -393,7 +394,7 @@ class Connection(metaclass=CantTouchThis):
|
||||||
when multiple calls to connection.send() are made.
|
when multiple calls to connection.send() are made.
|
||||||
"""
|
"""
|
||||||
await self.aopen()
|
await self.aopen()
|
||||||
if not self.websocket or self.closed:
|
if not self.websocket or self.websocket.state is State.CLOSED:
|
||||||
return
|
return
|
||||||
if self._owner:
|
if self._owner:
|
||||||
browser = self._owner
|
browser = self._owner
|
||||||
|
|
Loading…
Reference in New Issue