ultrafunkamsterdam / undetected-chromedriver

Custom Selenium Chromedriver | Zero-Config | Passes ALL bot mitigation systems (like Distil / Imperva/ Datadadome / CloudFlare IUAM)
https://github.com/UltrafunkAmsterdam/undetected-chromedriver
GNU General Public License v3.0
9.62k stars 1.15k forks source link

Chrome hangs on several websites until you bring chrome windows to front. #697

Open MacMarde opened 2 years ago

MacMarde commented 2 years ago

Hi I am using undetected-chromedriver and its working fine except one issue:

Chrome is sometimes "hanging" on some websites. For example on www.ip2location.com. It does not hang every time, but sometimes. Also other sites and sub-sites are affected. I am using mult-threading with sevral chrome instances.

If it hangs my python program is hanging forever. There is no more interaction possible with chrome, also not in debugging mode.

What I have to do is manually bringing the affected chrome window to front, either with clicking on the chrome window with the mouse or clicking on the window preview in the Windows 10 task bar. This is working for 100% and the python script just continous like nothing happened.

But of course this is a big issue because my bot needs baby-sitting. Clicking on the window with selenium is also not working reliable, because as I wrote, no interaction possible with this stucked chrome window. I created an Autoit script which just brings all chrome windows to the front, but it is also only working sometimes not every time.

So until now I have no solution that is reliable.

I am using chrome 98.0.4758.102 with latest version from UC. I do know there are newer versions of chrome available, but I can not use them becuase there are other bugs in the newer vesions which have not been solved for now.

sebdelsol commented 2 years ago

Which bugs prevent you from upgrading ?

MacMarde commented 2 years ago

Something similat to this: https://groups.google.com/g/chromedriver-users/c/Z_CaHJTJnLw

I am getting "target frame detached" errors. It only occurs when I am using my own proxy extension with python, which I do need to be able to use proxies with username/pw. If I am not using a proxy with my extension or going back to chrome v98 the problem does not appear anymore.

sebdelsol commented 2 years ago

You could try to use 102 (103 has a nagging issue #694) with seleniumwire for proxies with authentication. Maybe there's something wrong in your multi-thread code, do you have minimal code to reproduce it ?

sebdelsol commented 2 years ago

Please check #708

MacMarde commented 2 years ago

@sebdelsol Sorry I did forget to answer you. What exactly should seleniumwire be good for in my case?

I do not think my code is wrong, because it did work earlier without UC. Also my code is to complex to post here. I am gonna try #708 but it is not the same problem as I do have, because for me it is working most of the time, even when Chrome windows are in background, so the problem only occurs ocacassionaly and can not be reproduced for sure.

MacMarde commented 2 years ago

@sebdelsol But I have a suspicion. It seems like the issue only occurs when I let my bot run with active Remote Desktop. It seems like no errors occur, when using this batch file to close RDP:

for /f "skip=1 tokens=3" %%s in ('query user %USERNAME%') do ( %windir%\System32\tscon.exe %%s /dest:console )

It closes active RDP connection and does not lock windows. It seems like this is a partial solution, but as I do need to use RDP often, it is still a problem.

MacMarde commented 2 years ago

@sebdelsol I have tried #708 and it seems like it really fixed my issue. Thanks a lot.

MacMarde commented 2 years ago

@sebdelsol Unfortunately it turned out it is still not working. It is running fine on a system where I do not use proxies and still a problem on a system with proxies. But I am not sure, I can not test it because both systems should be running unchanged. I use proxies with an chrome extension like suggested here.

Anyway I am thinking about using selenium wire, which also supports proxies with username/pw.

You also mentioned Seleniumwire. So how can I use it with UC? And is it safe to use it in terms of being undetectable?

sebdelsol commented 2 years ago

Please check this answer for how to use seleniumwire.

There are indeed some caveats for using seleniumwire.

MacMarde commented 2 years ago

@sebdelsol Thank you. Ok I am gonna test seleniumwire in the future with a separated setup to be sure it is working before applying it.

Regarding the proxy extension for chrome I can find 2 version: Version 1 Version 2

For me both versions look good or what do you think? I am using version 1