undetected-chromedriver icon indicating copy to clipboard operation
undetected-chromedriver copied to clipboard

Getting detected by cloudflare

Open vndhote opened this issue 1 year ago • 55 comments

undetected chromedriver worked well till yesterday but now, cloudflare improved and the chromedriver is not bypassing cloudflare. I have attached the screenshot of it. cloudflare is just looping the captcha when selenium is running. When I close it, the website loads. image This is my code snippet image It works fine when the script isn't running. I also tried changing the binary to chrome rather than brave, but the issue still persists

vndhote avatar Jul 11 '23 17:07 vndhote

I'm on the same spot, was working fine all this month and suddenly today it doesn't work

zakio0403 avatar Jul 11 '23 18:07 zakio0403

I have the same problem as you

MrKhosrojerdi avatar Jul 11 '23 18:07 MrKhosrojerdi

I'm on the same spot, was working fine all this month and suddenly today it doesn't work

I guess it gonna take some time to improve the logics in undetected chrome driver to be undetectable. Anyone having solution to this kindly send me friend request and dm me on discord My discord Id : vivek9646

vndhote avatar Jul 11 '23 19:07 vndhote

Same issue for me. Crawling 24 hours a day during last month, I got stuck a few hours ago. IMPORTANT: When I close my bot and browser is still open, bypass is successful. This is strange for me.

sh-erfan avatar Jul 11 '23 20:07 sh-erfan

Apparently that's an issue with the cloudflare captchas. I found that it works when dev tools are open. Adding the following line resolved the issue for me. chrome_options.add_argument("--auto-open-devtools-for-tabs") # automatically open dev tools on every new tab (This is a not a pretty solution ofc, I had no time to dive deeper yet)

benkrej avatar Jul 11 '23 20:07 benkrej

I tried adding the dev-tools option @benkrej but I'm just getting the word "None":

options.add_argument( '--headless' ) options.add_argument( '--auto-open-devtools-for-tabs' ) chrome = uc.Chrome( options = options ) message = chrome.get( 'http://bscscan.com/contractsVerified' ) #chrome.save_screenshot( 'datadome_undetected_webddriver.png' )

print(message)

digitalnomad91 avatar Jul 11 '23 21:07 digitalnomad91

You will have to scrape and structure the data yourself, driver.get returns None. I suggest you to look into the coding examples.

benkrej avatar Jul 11 '23 21:07 benkrej

Apperently that's an issue with the cloudflare captchas. I found that it works when dev tools are open. Adding the following line resolved the issue for me. chrome_options.add_argument("--auto-open-devtools-for-tabs") # automatically open dev tools on every new tab (This is a not a pretty solution ofc, I had no time to dive deeper yet)

god bless you man!

salvecom333 avatar Jul 11 '23 21:07 salvecom333

It worked, thank you!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!

digitalnomad91 avatar Jul 11 '23 21:07 digitalnomad91

chrome_options.add_argument("--auto-open-devtools-for-tabs") # automatically open dev tools on every new tab

That worked mate, thanks!

Btw anyone knows how to close it afterwards? Site-specific protections detect me because it's opened.

I've tried action chains with Shift + Ctrl + i, but didn't succeed

punkerpunker avatar Jul 11 '23 23:07 punkerpunker

Same issue for me. Crawling 24 hours a day during last month, I got stuck a few hours ago. IMPORTANT: When I close my bot and browser is still open, bypass is successful. This is strange for me.

Does this not indicate that Cloudflare is perhaps tracking mouse movements now?

jacobprice808 avatar Jul 12 '23 06:07 jacobprice808

Same issue for me. Crawling 24 hours a day during last month, I got stuck a few hours ago. IMPORTANT: When I close my bot and browser is still open, bypass is successful. This is strange for me.

Does this not indicate that Cloudflare is perhaps tracking mouse movements now?

Um.. like I tried using action chains to make it look more natural. I don't think so it may be mouse movements. It is possible that it's detecting selenium.

vndhote avatar Jul 12 '23 06:07 vndhote

chrome_options.add_argument("--auto-open-devtools-for-tabs") # automatically open dev tools on every new tab

That worked mate, thanks!

Btw anyone knows how to close it afterwards? Site-specific protections detect me because it's opened.

I've tried action chains with Shift + Ctrl + i, but didn't succeed

try to use pyautogui to close dev panel pip install pyautogui import pyautogui pyautogui.hotkey("Ctrl", "Shift", "J") add this to your code

vndhote avatar Jul 12 '23 06:07 vndhote

Same issue for me. Crawling 24 hours a day during last month, I got stuck a few hours ago. IMPORTANT: When I close my bot and browser is still open, bypass is successful. This is strange for me.

Yeah, it's somehow able to detect the underlying control of Python. When I open a browser with this code and navigate to a Cloudflare site it is looping. When I open a new window manually, I don't experience this issue. Everything else is controlled manually in both cases: navigating to the website, clicking the checkbox, etc. The only difference is how the window was opened.

This is literally all I am doing to open the window:

options = uc.ChromeOptions()
driver = uc.Chrome(options=options)
time.sleep(60)

jacobprice808 avatar Jul 12 '23 07:07 jacobprice808

anyone know how can i make its dock at bottom?(automated)(default setting is right)

ParhamSobhan avatar Jul 12 '23 07:07 ParhamSobhan

I found out that if you open a new tab with js it passes cloudflare captchas. You can close the old tab and use the new one.

driver.execute_script('''window.open("http://nowsecure.nl","_blank");''') # open page in new tab
time.sleep(5) # wait until page has loaded
driver.switch_to.window(window_name=driver.window_handles[0])   # switch to first tab
driver.close() # close first tab
driver.switch_to.window(window_name=driver.window_handles[0] )  # switch back to new tab
time.sleep(2)
driver.get("https://google.com")
time.sleep(2)
driver.get("https://nowsecure.nl") # this should pass cloudflare captchas now

benkrej avatar Jul 12 '23 07:07 benkrej

I found out that if you open a new tab with js it passes cloudflare captchas. You can close the old tab and use the new one.

driver.execute_script('''window.open("http://nowsecure.nl","_blank");''') # open page in new tab
time.sleep(5) # wait until page has loaded
driver.switch_to.window(window_name=driver.window_handles[0])   # switch to first tab
driver.close() # close first tab
driver.switch_to.window(window_name=driver.window_handles[0] )  # switch back to new tab
time.sleep(2)
driver.get("https://google.com")
time.sleep(2)
driver.get("https://nowsecure.nl") # this should pass cloudflare captchas now

God damnnn that worked ! thanks a lot mate

vndhote avatar Jul 12 '23 08:07 vndhote

Apperently that's an issue with the cloudflare captchas. I found that it works when dev tools are open. Adding the following line resolved the issue for me. chrome_options.add_argument("--auto-open-devtools-for-tabs") # automatically open dev tools on every new tab (This is a not a pretty solution ofc, I had no time to dive deeper yet)

I tried your solutions, this and the new one and it works on my local machine. However it cannot seem to work on AWS ec2 or Digitalocean droplet. Do you have any pointers where to look to solve this?

mutiinsani avatar Jul 12 '23 09:07 mutiinsani

Apperently that's an issue with the cloudflare captchas. I found that it works when dev tools are open. Adding the following line resolved the issue for me. chrome_options.add_argument("--auto-open-devtools-for-tabs") # automatically open dev tools on every new tab (This is a not a pretty solution ofc, I had no time to dive deeper yet)

I tried your solutions, this and the new one and it works on my local machine. However it cannot seem to work on AWS ec2 or Digitalocean droplet. Do you have any pointers where to look to solve this?

Are you sure you are using the exact same code on your local machine and cloud? Try to match the python version as well as uc and chrome versions!

benkrej avatar Jul 12 '23 09:07 benkrej

Apperently that's an issue with the cloudflare captchas. I found that it works when dev tools are open. Adding the following line resolved the issue for me. chrome_options.add_argument("--auto-open-devtools-for-tabs") # automatically open dev tools on every new tab (This is a not a pretty solution ofc, I had no time to dive deeper yet)

I tried your solutions, this and the new one and it works on my local machine. However it cannot seem to work on AWS ec2 or Digitalocean droplet. Do you have any pointers where to look to solve this?

Are you sure you are using the exact same code on your local machine and cloud? Try to match the python version as well as uc and chrome versions!

Yes, I use your code to test! Chrome and UC version are exactly the same the only difference is my local Python is version 3.10.10 while my DO server version is 3.10.6 .

I print driver.title for testing and in my local it returns nowSecure while in DO it returns Just a moment... (which is from cloudflare)

mutiinsani avatar Jul 12 '23 11:07 mutiinsani

You might need to modify the first sleep, the cf protected site needs to fully load in the new tab in order for it to work.

benkrej avatar Jul 12 '23 11:07 benkrej

Been trying changing that, still no luck

mutiinsani avatar Jul 12 '23 11:07 mutiinsani

Apparently that's an issue with the cloudflare captchas. I found that it works when dev tools are open. Adding the following line resolved the issue for me. chrome_options.add_argument("--auto-open-devtools-for-tabs") # automatically open dev tools on every new tab (This is a not a pretty solution ofc, I had no time to dive deeper yet)

thank u man!!! it works fine for me!!!

Sunda001 avatar Jul 12 '23 12:07 Sunda001

Same issue for me. Crawling 24 hours a day during last month, I got stuck a few hours ago. IMPORTANT: When I close my bot and browser is still open, bypass is successful. This is strange for me.

Does this not indicate that Cloudflare is perhaps tracking mouse movements now?

I click the checkbox with mouse, also applied random waits to simulate real human, but still stuck. I guess it is detecting selenium somehow

sh-erfan avatar Jul 12 '23 12:07 sh-erfan

Same issue for me. Crawling 24 hours a day during last month, I got stuck a few hours ago. IMPORTANT: When I close my bot and browser is still open, bypass is successful. This is strange for me.

Yeah, it's somehow able to detect the underlying control of Python. When I open a browser with this code and navigate to a Cloudflare site it is looping. When I open a new window manually, I don't experience this issue. Everything else is controlled manually in both cases: navigating to the website, clicking the checkbox, etc. The only difference is how the window was opened.

This is literally all I am doing to open the window:

options = uc.ChromeOptions()
driver = uc.Chrome(options=options)
time.sleep(60)

I guess that is strictly related to detecting type of the handler that controls the browser, may be via JS. When I close bot, then the handler is kind of disposed, and so, CF realizes no automatic handler is back there and let me bypass. Can you test this scenario: Open the main window via code, then open a new tab and head to the same website manually.

sh-erfan avatar Jul 12 '23 12:07 sh-erfan

Same issue for me. Crawling 24 hours a day during last month, I got stuck a few hours ago. IMPORTANT: When I close my bot and browser is still open, bypass is successful. This is strange for me.

Yeah, it's somehow able to detect the underlying control of Python. When I open a browser with this code and navigate to a Cloudflare site it is looping. When I open a new window manually, I don't experience this issue. Everything else is controlled manually in both cases: navigating to the website, clicking the checkbox, etc. The only difference is how the window was opened.

This is literally all I am doing to open the window:

options = uc.ChromeOptions()

driver = uc.Chrome(options=options)

time.sleep(60)

I guess that is strictly related to detecting type of the handler that controls the browser, may be via JS. When I close bot, then the handler is kind of disposed, and so, CF realizes no automatic handler is back there and let me bypass. Can you test this scenario: Open the main window via code, then open a new tab and head to the same website manually.

My second workaround does exactly what you described.

benkrej avatar Jul 12 '23 13:07 benkrej

Apparently that's an issue with the cloudflare captchas. I found that it works when dev tools are open. Adding the following line resolved the issue for me. chrome_options.add_argument("--auto-open-devtools-for-tabs") # automatically open dev tools on every new tab (This is a not a pretty solution ofc, I had no time to dive deeper yet)

For those who are less gifted like me and couldn't figure out where to insert this work around :

In utils.py at line 45 if you're running the default installation, you'll find a bunch of lines with adding arguments to the "options" variable .

replace "chrome_options" with options

et Voila everything should work now.

kenanAlhindi97 avatar Jul 12 '23 21:07 kenanAlhindi97

Apparently that's an issue with the cloudflare captchas. I found that it works when dev tools are open. Adding the following line resolved the issue for me. chrome_options.add_argument("--auto-open-devtools-for-tabs") # automatically open dev tools on every new tab (This is a not a pretty solution ofc, I had no time to dive deeper yet)

It seems that adding this line will consume more memory, does anyone encounter this?

greathope avatar Jul 13 '23 03:07 greathope

Hello everyone, If you just need to pass the cloudflare challenge, You can refer to cf-clearance

vvanglro avatar Jul 13 '23 04:07 vvanglro

@vvanglro your answer has nothing to do with the current issue. You might have not seen it but this is the cf turnstile captcha, not cf_clearance bot protection which is easily bypassed by using correct headers in your requests.

benkrej avatar Jul 13 '23 08:07 benkrej