Description
Improve multithreading with UC Mode 4.28.x
In case you missed #2865, 4.28.0
added a new UC Mode method: uc_gui_handle_cf()
, which uses pyautogui
to click Cloudflare checkboxes with the keyboard while the driver is disconnected from Chrome. For those of you who might not be familiar with the basics of that, pyautogui
keyboard actions only reach the active window on top (in the case of multiple windows). In order for the pyautogui
action to be successful, the window with the CAPTCHA must remain on top for the duration of the pyautogui
actions. In the case of uc_gui_handle_cf()
, that duration is generally less than 2 seconds per call, even if you have a lot of windows open and being controlled at the same time. The "call" includes: Making the current window the active window on top, finding the iframe, switching into the iframe, making the checkbox the active element, and then clicking the checkbox by pressing the spacebar with pyautogui
. To prevent that "call" from being disrupted, we need to use thread-locking to prevent other actions from making another window become the active one (for the entire duration of the "call").
Here are some actions that would make another window the active one:
- Launching a new browser.
- Calling
driver.switch_to.window()
. - Human actions while scripts are running.
Thread-locking can be placed around browser launches that occur via SeleniumBase. It can also be placed around SeleniumBase methods that call driver.switch_to.window()
indirectly. There isn't much that can be done about human actions while the scripts are running, or if people are calling driver.switch_to.window()
directly from their scripts.
With the extra thread-locking added, we should be able to see a noticeable improvement in the success rate of uc_gui_handle_cf()
calls when multiple threads are being used to spin up multiple browsers at the same time. As a side-effect, there may be some slowdowns when multiple threads are trying to change the active window at the same time, because only one thread will be able to perform such an action at one time. This special thread-locking will only take place during UC Mode. For regular mode, there won't be any blockers from scripts performing actions.