Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Improve multithreading with UC Mode 4.28.x #2883

Closed
mdmintz opened this issue Jun 28, 2024 · 4 comments · Fixed by #2884
Closed

Improve multithreading with UC Mode 4.28.x #2883

mdmintz opened this issue Jun 28, 2024 · 4 comments · Fixed by #2884
Assignees
Labels
enhancement Making things better UC Mode / CDP Mode Undetected Chromedriver Mode / CDP Mode

Comments

@mdmintz
Copy link
Member

mdmintz commented Jun 28, 2024

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.

@mdmintz mdmintz added enhancement Making things better UC Mode / CDP Mode Undetected Chromedriver Mode / CDP Mode labels Jun 28, 2024
@mdmintz mdmintz self-assigned this Jun 28, 2024
@mdmintz
Copy link
Member Author

mdmintz commented Jun 29, 2024

This was resolved in 4.28.2 - https://github.com/seleniumbase/SeleniumBase/releases/tag/v4.28.2

@OpsecGuy
Copy link

OpsecGuy commented Jun 30, 2024

This was resolved in 4.28.2 - https://github.com/seleniumbase/SeleniumBase/releases/tag/v4.28.2

Hey, in my case the latest update doesn't really click on the captcha checkbox on Windows.
Im using SB format. Updates 4.28.0 and 4.28.1 are working properly, however using latest update makes my code stuck on uc_gui_handle_cf method. Even after waiting for 5 and more minutes nothing really happens.

@mdmintz
Copy link
Member Author

mdmintz commented Jul 1, 2024

I see the issue on Windows. I'll ship a new release soon...

@mdmintz
Copy link
Member Author

mdmintz commented Jul 1, 2024

Upgrade to 4.28.3 (Fixes #2889)

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
enhancement Making things better UC Mode / CDP Mode Undetected Chromedriver Mode / CDP Mode
Projects
None yet
Development

Successfully merging a pull request may close this issue.

2 participants