seleniumbase / SeleniumBase

📊 Blazing fast Python framework for web crawling, scraping, testing, and reporting. Supports pytest. Stealth abilities: UC Mode and CDP Mode.
https://seleniumbase.io
MIT License
5.44k stars 983 forks source link

uc_open_with_reconnect() shutting down the window #3242

Closed Yougz-Teapot closed 3 weeks ago

Yougz-Teapot commented 3 weeks ago

While I'm still fairly new to SeleniumBase I have managed to use it successfully to scrape content using uc_mode until recently. However, now the very same script I have been using shuts down the chrome window when hitting the second "uc_open_with_reconnect()" (within the try block).

I have tried "uc_open_with_tab()" which also shuts down the window. Plain "uc_open()" works fine though.

Since I have not modified the script I'm guessing it's a SB version (I am using SeleniumBase 4.32.6 ; on Windows) or driver version-related issue. I have tried specifying driver_version = "129" as suggested by another user but it did not change the behaviour. I'm having the same issue on another simple test script.

Did someone encounter the same issue recently and was able to solve it please ?

Code sample :

with SB(uc=True) as sb:

    # sb.get_new_driver(browser="chrome", driver_version="129")

    sb.driver.uc_open_with_reconnect(home_url, reconnect_time=3)

...

    for X in tqdm(Xs):

...

            try:              
                # sb.driver.uc_open_with_reconnect(url, reconnect_time="breakpoint")
                # sb.driver.uc_open_with_tab(url)
                sb.driver.uc_open(url)

...

mdmintz commented 3 weeks ago

If by "shuts down the chrome window" you mean that the current tab is closed and a new one opened for uc_open_with_reconnect(url) and uc_open_with_tab(url), then that is expected behavior. The existing tab may contain session_storage / local_storage / cookies / etc. that can reveal the presence of Selenium during bot-detection, so the current tab is closed and a new one opened with the URL that you want. For your situation, you may want to use a regular uc_open(), if you can. Or just driver.disconnect() if you only need to disconnect the driver from the browser.

mdmintz commented 3 weeks ago

Actually, looks like a bug on Windows in 4.32.6. (Was testing on a Mac earlier.) Caused by the removal of --disable-popup-blocking... As it turns out: That's necessary!

Temporary workaround until the next version is released: chromium_arg="--disable-popup-blocking".

mdmintz commented 3 weeks ago

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