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

WiP: Fix looping Cloudflare challenge, Resolves #1036 #1163

Draft
wants to merge 2 commits into
base: master
Choose a base branch
from

Conversation

ilike2burnthing
Copy link
Contributor

Thanks to @juanfrilla for #1036 (comment).

Unfortunately, currently this only works on Windows, and the looping challenges return if using proxies or VPNs.

@garfield69
Copy link
Contributor

garfield69 commented Apr 21, 2024

FWIW
My win10 is on chrome 124, and i don't use VPN or proxy.
I've tested this PR (as a source based python run), and it solves for trupornolabs, riperam, marinetracker, devil-torrents, 52BT, which were indexers that were giving me issues previoulsy.
Also tested against most of the other cloudflare protected indexers that were previously working for me, and they continue to work with this PR.
Some indexers however continue to fail, leporno still returns the invalid cookies error, and ext-torrents which now fails on ext.to but works for the other 2 alternate domains.

But after each solve there remains a chrome subtask that starts to spin up to 15% CPU and I have to manually kill them off.
Should I test using this PR win10 exe?
[edit] Oh wait, there isn't one.

@juanfrilla
Copy link

juanfrilla commented Apr 21, 2024

Another thing that I've noticed is that in the user-agent headless replacement:

                self.execute_cdp_cmd(
                    "Network.setUserAgentOverride",
                    {
                        "userAgent": self.execute_script(
                            "return navigator.userAgent"
                        ).replace("Headless", "")
                    },
                )

I don't know why but If I hardcode the user-agent using the exact that my computer has like this:

user_agent = "Mozilla/5.0 (Macintosh; Intel Mac OS X 10_15_7) AppleWebKit/537.36 (KHTML, like Gecko) Chrome/123.0.0.0 Safari/537.36"
options.add_argument(f"--user-agent={user_agent}")

it bypasses cloudflare, but if i put this to make it automatically like you have it on line 533 from src/undetected_chromedriver/__init__.py it does not work.

So an alternative could be to setup a driver only to get the user agent:

def get_user_agent(driver):
   return driver.execute_script("return navigator.userAgent;").replace("Headless", "")

And then pass the user-agent to the definitive driver

PD: I only can tell you what I've discovered to see if we can go through the solution cuz I'm having troubles to get the project installed/set up 😅

@m33ts4k0z
Copy link

m33ts4k0z commented Apr 21, 2024

Hello. I just wanted to let you know that this didnt bypass the challenge on arab-torrents.net, showing the same internal server error. I am not using VPN, proxies and I dont have a datacenter IP. Let me know if you need any info to troubleshoot this further.

I didnt actually use this branch, it worked fine after I switched to it. Thanks

@ilike2burnthing
Copy link
Contributor Author

ilike2burnthing commented Apr 21, 2024

@garfield69 yea this seems to be an issue with Chrome v124. You can revert to v123 in the mean time if it's easier - #1161

Alternatively, build your own binaries, which will use Chromium v123:

python src/build_package.py

@ilike2burnthing
Copy link
Contributor Author

@m33ts4k0z were you doing this on Windows?

@m33ts4k0z
Copy link

@m33ts4k0z were you doing this on Windows?

Yes on a Windows 11 VM on Unraid but it did work in the end. I updated my first post here with the cause.

@garfield69
Copy link
Contributor

Alternatively, build your own binaries, which will use Chromium v123:

python src/build_package.py

Oh cool, did not know I could build on windows.
Built successfully and tested. Much better, no left over chrome tasks chewing CPU anymore :-)

@ilike2burnthing
Copy link
Contributor Author

ilike2burnthing commented Apr 22, 2024

@juanfrilla sorry for the delay in replying, been busy and only got to a few quick ones on my phone.

I'll have a look at the UA idea when I next get a chance, thanks.

Assuming you're following the run from source instructions, what issue are you having? https://github.com/FlareSolverr/FlareSolverr#from-source-code

@juanfrilla
Copy link

@ilike2burnthing my main problem is that i cannot install Xvfb on MacOS

@ilike2burnthing
Copy link
Contributor Author

Tried XQuartz?

@juanfrilla
Copy link

juanfrilla commented Apr 22, 2024

Tried XQuartz?

yessir now the project is set up, let's see what I can fix

@21hsmw
Copy link
Contributor

21hsmw commented May 1, 2024

What exactly is left to do on this to get it merge? I tried to guess with the comments here and some different issues but I can't get the current status of this. It seems to be stale for quite some time, so what's needed?

@ilike2burnthing
Copy link
Contributor Author

Unfortunately, currently this only works on Windows, and the looping challenges return if using proxies or VPNs.

I'll have a look at the UA idea when I next get a chance, thanks.

@21hsmw
Copy link
Contributor

21hsmw commented May 1, 2024

Unfortunately, currently this only works on Windows, and the looping challenges return if using proxies or VPNs.

I'll have a look at the UA idea when I next get a chance, thanks.

Well, I made my own implementation of this "new tab" idea and I was able to make it work with every website I could (ext.to, www3.yggtorrent.cool, dodi-repacks.site, hd-torrents.me/login.php, nhentai.net) on my Linux system using a VPN / socks5 proxy and also with my container image on my own remote Linux server, which was blocked by cloudflare too.
Unfortunately I can't test on Windows, so if someone can test that and report back please do.

Public image with my edits: 21hsmw/flaresolverr:fixlooping
Code here: 21hsmw@da6cc9d

@ilike2burnthing
Copy link
Contributor Author

That's working 95% of the time on Windows for me, even with a proxy, but failing 95% of the time on Docker. Usual error:

Error: Error solving the challenge. 'NoneType' object has no attribute 'startswith'

Seems it's related to get_correct_window and trying to get driver.current_url. Adding some extra logging shows that the URL is returned as None. Adding some additional sleeps then shows the correct URL, but I'm still getting challenge loops or crashed.

@21hsmw
Copy link
Contributor

21hsmw commented May 2, 2024

That's working 95% of the time on Windows for me, even with a proxy, but failing 95% of the time on Docker.

When you say it fails on Docker, is it still on Windows or Linux?

I got this error on Linux while doing my implementation, but have not been able to replicate it since. For the looping challenges, it seems to be a timing issue. Playing with the timer values can make it work in some cases, but it's not easy to know what works for everyone since it seems to take network latency into account. For example, if I use a proxy close to my location, it works 100% of the time with the sites I listed earlier, but if I use a proxy very far from me, it works 50% of the time.
Can you try to increase the timers to something like 6, 8 or more?

@ilike2burnthing
Copy link
Contributor Author

Linux.

I'll play around with timings again (I did a bunch yesterday), see if I can get something that works both on my Docker and Windows.

@21hsmw
Copy link
Contributor

21hsmw commented May 2, 2024

Linux.

Strange then. I'm able to solve the challenges of all sites I try on my Debian and Fedora systems with different VPNs/Proxies with and without Docker involved.
Can you share an example of one of your tests with debug enabled?

Here's an example with dodi-repacks.site using the docker image I shared previously:
https://pastebin.com/nBramRXq

@aevrard

This comment was marked as off-topic.

@zenderzender
Copy link

Unfortunately, currently this only works on Windows, and the looping challenges return if using proxies or VPNs.

I'll have a look at the UA idea when I next get a chance, thanks.

Well, I made my own implementation of this "new tab" idea and I was able to make it work with every website I could (ext.to, www3.yggtorrent.cool, dodi-repacks.site, hd-torrents.me/login.php, nhentai.net) on my Linux system using a VPN / socks5 proxy and also with my container image on my own remote Linux server, which was blocked by cloudflare too. Unfortunately I can't test on Windows, so if someone can test that and report back please do.

Public image with my edits: 21hsmw/flaresolverr:fixlooping Code here: 21hsmw@da6cc9d

Thanks for your workaround @21hsmw
Here is a temporary image for anybody needing arm build :)
zender/flaresolverr-fixed:arm

Working with LANG=fr-FR

@aevrard the solution you provide will kill the killswitch if you're using something like gluetun...

@LoicBrison
Copy link

Thanks @21hsmw !
Works for YGG with YGGCookie and YGGtorrent; LANG=en_US

@Vrozaksen
Copy link

Vrozaksen commented May 3, 2024

21hsmw/flaresolverr:fixlooping

Worked for me on whatbox.ca

services:
     flaresolverr:
         image: 21hsmw/flaresolverr:fixlooping
         environment:
           - LOG_LEVEL=${LOG_LEVEL:-info}
           - LOG_HTML=${LOG_HTML:-false}
           - CAPTCHA_SOLVER=${CAPTCHA_SOLVER:-none}
           - TZ=UTC
           - PORT=25000
           - HOST=127.0.0.1
         network_mode: host
         pull_policy: always
         restart: unless-stopped

@juanfrilla
Copy link

juanfrilla commented May 3, 2024

Unfortunately, currently this only works on Windows, and the looping challenges return if using proxies or VPNs.

I'll have a look at the UA idea when I next get a chance, thanks.

Well, I made my own implementation of this "new tab" idea and I was able to make it work with every website I could (ext.to, www3.yggtorrent.cool, dodi-repacks.site, hd-torrents.me/login.php, nhentai.net) on my Linux system using a VPN / socks5 proxy and also with my container image on my own remote Linux server, which was blocked by cloudflare too. Unfortunately I can't test on Windows, so if someone can test that and report back please do.

Public image with my edits: 21hsmw/flaresolverr:fixlooping Code here: 21hsmw@da6cc9d

replacing the image of the dockerfile for this:
python:3.11-slim-bullseye works perfectly locally on MacOS M2 with and without proxies (tested for my website "https://www.icj-cij.org/sites/default/files/case-related/187/187-20231215-ord-01-00-en.pdf", I can get the cf_clearance cookie

I tested as well on a centOS server with the previous image (python:3.11-slim-bookworm) and it doesnt work

@Gauvino Gauvino mentioned this pull request May 6, 2024
@0rsa

This comment was marked as off-topic.

@tenettow
Copy link

tenettow commented May 9, 2024

I can access all trackers in Jackett with the latest Flaresolverr, but not with these changes.

@ilike2burnthing
Copy link
Contributor Author

'latest' being v3.3.17?

What OS?

@tenettow
Copy link

tenettow commented May 9, 2024

Flaresolverr v3.3.17, Linux x86_64 running on DigitalOcean. Tested on my macOS and that version also works fine with my normal IP. Any tracker I should try that you have issues with?

@ilike2burnthing
Copy link
Contributor Author

ilike2burnthing commented May 9, 2024

https://github.com/search?q=repo%3AJackett%2FJackett+configuring-flaresolverr&type=code

Some may not be currently using CF, there may be some missed, some only use it for login or keyword searches, but that should give you an idea.

See also those sites mentioned in #1036.

@researchersec
Copy link

juanfrillaaa/flaresolverr:latest solves the challenges greatly on my ubuntu with docker! Thanks @juanfrilla!

@21hsmw
Copy link
Contributor

21hsmw commented May 24, 2024

The only thing I don't know is if it will run correctly inside a container.

Update: Just tested, it works with an xvfb display inside a container. I'll see if I can find some time to implement part of nodriver for flaresolverr, but I'm not sure if I should put both undetected-chromedriver and nodriver in the same files, or if it would be better to create separate files like flaresolverr_service_nd.py to make the code cleaner. Any thoughts? @ilike2burnthing

@ilike2burnthing
Copy link
Contributor Author

Separate sounds good.

@21hsmw
Copy link
Contributor

21hsmw commented May 28, 2024

@ilike2burnthing I spent some time the last few days implementing the request.get part of flaresolverr with nodriver. It works on Linux and Windows based on my own testing, including headless for Windows.
If you have some time, can you build and test my nodriver-support branch? There's still some work to be done, but it should work as is and I'm curious to see if you can pass cf challenges with it.

@ilike2burnthing
Copy link
Contributor Author

Looks good, I'll test this when I get some free time. Can you also push a Docker build of this so I can test it more easily as well? Thanks!

@21hsmw
Copy link
Contributor

21hsmw commented May 29, 2024

Can you also push a Docker build of this so I can test it more easily as well? Thanks!

Sure, it's available here on docker hub: 21hsmw/flaresolverr:nodriver
Use DRIVER=nodriver to enable it.
Let me know about your results.

@Larryadd
Copy link

Larryadd commented Jun 3, 2024

I don't know if this can help but YGG is cloudflared since yesterday (june 2 2024).
Last version of FlareSolverr wasn't working I tried differents configs with no luck. (I actually read all comments)
I tried 21hsmw build and it worked 1st time without changing anything in the config.
Cannot explain why but just wanted to share the info.
I use this message to thank you all for your investment on this project.
Have a good day.
Edit : Docker/debian12.

@juanfrilla
Copy link

juanfrilla commented Jun 3, 2024

i'm not able to get it working with this url (i dont know what happened):
"https://www.icj-cij.org/sites/default/files/case-related/187/187-20231215-ord-01-00-en.pdf"

@21hsmw
Copy link
Contributor

21hsmw commented Jun 3, 2024

i'm not able to get it working with this url (i dont know what happened): "https://www.icj-cij.org/sites/default/files/case-related/187/187-20231215-ord-01-00-en.pdf"

Can you tell which image you used to get this result?

I tried the current latest tag which got stuck in a loop, then I tried 21hsmw/flaresolverr:fixlooping and 21hsmw/flaresolverr:nodriver (with uc and nodriver) and they both pass the challenge.

@juanfrilla
Copy link

juanfrilla commented Jun 4, 2024

I'm doing it with 21hsmw/flaresolverr:nodriver cuz I cannot execute this 21hsmw/flaresolverr:fixloopingwith macos.
Sometimes it works and sometimes dont, I notice when I combine with scrapy it doesnt work and when I execute in a separate script it works.
For working I mean to be able to get the cookies from the flaresolverr and send them to requests library in order to get the response.content

i'm not able to get it working with this url (i dont know what happened): "https://www.icj-cij.org/sites/default/files/case-related/187/187-20231215-ord-01-00-en.pdf"

Can you tell which image you used to get this result?

I tried the current latest tag which got stuck in a loop, then I tried 21hsmw/flaresolverr:fixlooping and 21hsmw/flaresolverr:nodriver (with uc and nodriver) and they both pass the challenge.

@21hsmw
Copy link
Contributor

21hsmw commented Jun 5, 2024

For working I mean to be able to get the cookies from the flaresolverr and send them to requests library in order to get the response.content

When flaresolverr fails to return cookies, what error exactly is being reported?
Since you said it works with an external script and not scrapy, I'm not sure if it works all the time and the external tool fails, or if it's flaresolverr itself that fails to solve the challenge.

@Hyperz
Copy link

Hyperz commented Jun 5, 2024

@21hsmw I've been testing your nodriver version on Windows 10. It works, but there are two issues I've found with it. First, for some reason it seems to leave behind zombie Chrome processes that peg one core at 100% each. Not sure if this is a nodriver bug or something related to how FlareSolverr handles the lifespan of driver/tab instances. Second issue is that whenever it creates a driver instance to solve a challenge it steals focus from other windows which is incredibly annoying when trying to use it locally while doing other work. TBF this was an issue with chromedirver too, but there it could be solved by passing a --headless argument in the options instead of relying on startupinfo.dwFlags |= subprocess.STARTF_USESHOWWINDOW to fake headless mode. This no longer works b/c using the headless flag gets it detected. But I was thinking do we really need to completely destroy the driver instance after every use? If there was an option to force it to reuse an existing driver instance it would resolve the focus stealing problem on Windows I think, and it would also be a good option to have for running FlareSolver on systems that have more RAM than CPU resources available since (re)starting Chrome for every single challenge is a really expensive operation 🤷‍♂️.

@21hsmw
Copy link
Contributor

21hsmw commented Jun 5, 2024

First, for some reason it seems to leave behind zombie Chrome processes that peg one core at 100% each. Not sure if this is a nodriver bug or something related to how FlareSolverr handles the lifespan of driver/tab instances.

Yes, I am aware of this problem. I experienced it when I tested it with Windows, and I found out in the nodriver documentation that the parent process could stay running in the background. I did some testing, including testing an internal nodriver function that is not part of the official documentation, and it did not kill it. It's actually on my list of things to fix before doing a PR. I'll see what I can do.

Second issue is that whenever it creates a driver instance to solve a challenge it steals focus from other windows which is incredibly annoying when trying to use it locally while doing other work. TBF this was an issue with chromedirver too, but there it could be solved by passing a --headless argument in the options instead of relying on startupinfo.dwFlags |= subprocess.STARTF_USESHOWWINDOW to fake headless mode. This no longer works b/c using the headless flag gets it detected.

For the nodriver addition, I decided to keep the original headless implementation for Windows. Since it doesn't use a driver here, maybe the headless option built into nodriver could work, to be honest I haven't tested it, so I'll try that later.

But I was thinking do we really need to completely destroy the driver instance after every use? If there was an option to force it to reuse an existing driver instance it would resolve the focus stealing problem on Windows I think, and it would also be a good option to have for running FlareSolver on systems that have more RAM than CPU resources available since (re)starting Chrome for every single challenge is a really expensive operation 🤷‍♂️.

That's what sessions are for, but it's not available in nodriver yet. This is something I need to add, and it will probably be added before the end of the week.

@ilike2burnthing
Copy link
Contributor Author

Apologies, still yet to get the time to look at this. There are a few open issues about memory leaks with nodriver, might be worth looking at:

We've also dealt with zombie processes in the past, most recently in #1193, but might be worth looking at 7d84f1b and 9b2c602 in case there's anything useful and equivalent that could be done.

@Hyperz
Copy link

Hyperz commented Jun 5, 2024

Yes, I am aware of this problem. I experienced it when I tested it with Windows, and I found out in the nodriver documentation that the parent process could stay running in the background. I did some testing, including testing an internal nodriver function that is not part of the official documentation, and it did not kill it. It's actually on my list of things to fix before doing a PR. I'll see what I can do.

I'm using this rather ugly workaround for it at the moment using psutil. I call the function after every driver.stop() call. It only kills nodriver Chrome instances and I'm not seeing any negative side effects in doing so:

def kill_chrome_processes(delay: float = 5.0) -> None:
    if delay > 0:
        time.sleep(delay)

    for proc in psutil.process_iter(['pid', 'name', 'cmdline']):
        if proc.info['name'] in ('chrome', 'chrome.exe'):
            if (
                any(c.startswith('--no-zygote') for c in proc.info['cmdline'])
                and any(c.startswith('--user-agent') for c in proc.info['cmdline'])
            ):
                psutil.Process(proc.info['pid']).kill()

For the nodriver addition, I decided to keep the original headless implementation for Windows. Since it doesn't use a driver here, maybe the headless option built into nodriver could work, to be honest I haven't tested it, so I'll try that later.

But it is using the headless option built into nodriver (options.windows_headless = True) no? This is "fake headless" though and works by spawning a chrome process with an invisible window. But since it still creates a window it steals focus, unlike real headless mode by using options.add_argument('--headless'). But nodriver throws an exception when you try to do that. And commenting out the code that checks for the --headless argument just causes timeouts again when trying to solve challenges. Though I didn't investigate further.

That's what sessions are for, but it's not available in nodriver yet. This is something I need to add, and it will probably be added before the end of the week.

Oh, right. For some reason I thought that was something related to cookies. Still, wouldn't it make sense for the default behavior to be reusing driver instances unless explicitly choosing to manage sessions?

@21hsmw
Copy link
Contributor

21hsmw commented Jun 5, 2024

But it is using the headless option built into nodriver (options.windows_headless = True) no? This is "fake headless" though and works by spawning a chrome process with an invisible window. But since it still creates a window it steals focus, unlike real headless mode by using options.add_argument('--headless'). But nodriver throws an exception when you try to do that. And commenting out the code that checks for the --headless argument just causes timeouts again when trying to solve challenges. Though I didn't investigate further.

options.windows_headless is not included in nodriver by default, I added it manually to the source. Only options.headless is included natively. If you want to try it instead of the fake headless mode, replace options.windows_headless = True with options.headless = True in utils.py. Let me know if this changes anything for you.

Still, wouldn't it make sense for the default behavior to be reusing driver instances unless explicitly choosing to manage sessions?

If by that you mean running the browser by default all the time, I don't think that's a good idea. Flaresolverr is mostly used via container images, and some people run it on very small setups with low ram. A lot of people who do not know how containers and environment variables work would be stuck with a slow system, and I can already see a lot of problems coming up here because of that. The session option was made for people who want to keep their browser running when they know they can handle the resources it's using, and I think that's the best way to do it.

Apologies, still yet to get the time to look at this. There are a few open issues about memory leaks with nodriver, might be worth looking at

It's fine, take your time, there's more to do anyway so it's not urgent. I've seen those issues when I started implementing nodriver, I'll try to implement something like @Hyperz shared or I'll try to fix how nodriver detects the processes and deletes them.

@Hyperz
Copy link

Hyperz commented Jun 5, 2024

If you want to try it instead of the fake headless mode, replace options.windows_headless = True with options.headless = True in utils.py. Let me know if this changes anything for you.

Ah. Yes that seems to work without stealing focus, thanks.

@juanfrilla
Copy link

juanfrilla commented Jun 6, 2024

I keep having
2024-06-06 12:07:21 2024-06-06 13:07:21 INFO Incoming request => POST /v1 body: {'cmd': 'request.get', 'url': 'https://www.icj-cij.org//sites/default/files/case-related/187/187-20240531-ord-01-00-en.pdf', 'maxTimeout': 5000, 'proxy': '196.51.141.167:8800'}
2024-06-06 12:07:21 version_main cannot be converted to an integer
2024-06-06 12:07:22 2024-06-06 13:07:22 INFO Challenge detected. Title found: Just a moment...
2024-06-06 12:07:27 2024-06-06 13:07:27 ERROR Error: Error solving the challenge. Timeout after 5.0 seconds.
2024-06-06 12:07:27 2024-06-06 13:07:27 INFO Response in 5.776 s

If I increase the timeout it doesnt work either.
And after a while my proxy ip of my external script gets banned as well.

I'm testing with 21hsmw/flaresolverr:nodriver

For working I mean to be able to get the cookies from the flaresolverr and send them to requests library in order to get the response.content

When flaresolverr fails to return cookies, what error exactly is being reported? Since you said it works with an external script and not scrapy, I'm not sure if it works all the time and the external tool fails, or if it's flaresolverr itself that fails to solve the challenge.

@21hsmw
Copy link
Contributor

21hsmw commented Jun 6, 2024

I keep having 2024-06-06 12:07:21 2024-06-06 13:07:21 INFO Incoming request => POST /v1 body: {'cmd': 'request.get', 'url': 'https://www.icj-cij.org//sites/default/files/case-related/187/187-20240531-ord-01-00-en.pdf', 'maxTimeout': 5000, 'proxy': '196.51.141.167:8800'} 2024-06-06 12:07:21 version_main cannot be converted to an integer 2024-06-06 12:07:22 2024-06-06 13:07:22 INFO Challenge detected. Title found: Just a moment... 2024-06-06 12:07:27 2024-06-06 13:07:27 ERROR Error: Error solving the challenge. Timeout after 5.0 seconds. 2024-06-06 12:07:27 2024-06-06 13:07:27 INFO Response in 5.776 s

If I increase the timeout it doesnt work either. And after a while my proxy ip of my external script gets banned as well.

I'm testing with 21hsmw/flaresolverr:nodriver

For working I mean to be able to get the cookies from the flaresolverr and send them to requests library in order to get the response.content

When flaresolverr fails to return cookies, what error exactly is being reported? Since you said it works with an external script and not scrapy, I'm not sure if it works all the time and the external tool fails, or if it's flaresolverr itself that fails to solve the challenge.

Can you switch LOG_LEVEL to debug and reshare the logs? It will be better to find out what's causing this.
Are you running flaresolverr with DRIVER=nodriver or is it still running with undetected-chromedriver?

Edit:
The proxy parameter should look like this in the logs 'proxy': {'url': 'http://IP:PORT'}, the one in your logs looks different.
Your proxy is actually ignored because the format is not the expected one, but I'm not sure if this is related to the timeout.

@juanfrilla
Copy link

DRIVER=nodriver

Okay, now its working, even in the server. I needed to fix the proxy and the DRIVER=nodriver
Sorry for the confusion
Thanks

@juanfrilla
Copy link

juanfrilla commented Jun 6, 2024

@21hsmw I have two questions

  1. can I limit the number of attempts?
    this are now the logs:
2024-06-06 15:35:25 DEBUG    ReqId 139728002909888 Waiting for title (attempt 11): Just a moment...
2024-06-06 15:35:27 DEBUG    ReqId 139728002909888 Timeout waiting for selector
2024-06-06 15:35:27 DEBUG    ReqId 139728002909888 Trying to find the closest Cloudflare clickable element...
2024-06-06 15:35:57 DEBUG    ReqId 139728002909888 Cloudflare element not found on the page.
2024-06-06 15:35:59 DEBUG    ReqId 139728002909888 Waiting for title (attempt 12): Just a moment...
2024-06-06 15:36:01 DEBUG    ReqId 139728002909888 Timeout waiting for selector
2024-06-06 15:36:01 DEBUG    ReqId 139728002909888 Trying to find the closest Cloudflare clickable element...
2024-06-06 15:36:08 DEBUG    ReqId 139728002909888 Cloudflare element not found on the page.
2024-06-06 15:36:10 DEBUG    ReqId 139728002909888 Waiting for title (attempt 13): Just a moment...
2024-06-06 15:36:12 DEBUG    ReqId 139728002909888 Timeout waiting for selector
2024-06-06 15:36:12 DEBUG    ReqId 139728002909888 Trying to find the closest Cloudflare clickable element...
2024-06-06 15:36:33 DEBUG    ReqId 139728002909888 Cloudflare element not found on the page.
2024-06-06 15:36:35 DEBUG    ReqId 139728002909888 Waiting for title (attempt 14): Just a moment...
2024-06-06 15:36:37 DEBUG    ReqId 139728002909888 Timeout waiting for selector
2024-06-06 15:36:37 DEBUG    ReqId 139728002909888 Trying to find the closest Cloudflare clickable element...

to change of proxies when the limit of attempt happen

  1. Does it consume a lot of resources launching the browsers?

@21hsmw
Copy link
Contributor

21hsmw commented Jun 6, 2024

  1. can I limit the number of attempts?

Attempts are just an indication of how many times flaresolverr tries to pass the challenge on the page, so there's no way to control anything based on this value right now. It will keep trying to pass the challenge until it hits the timeout, and then it will fail.

2. Does it consume a lot of resources launching the browsers?

It depends on what the page looks like and all the elements that need to be loaded, but generally it turns around 1GB of memory when it's trying to pass the challenge on my side (Linux).

@xinghui233
Copy link

在过去的几天里,我花了一些时间用 nodriver 实现了 flaresolverr 的部分。根据我自己的测试,它适用于 Linux 和 Windows,包括 Windows 的无头。如果你有时间,你能建立和测试我的nodriver-support分支吗?还有一些工作要做,但它应该按原样工作,我很好奇你是否能通过它的挑战。request.get

Thanks for your work, he got me through the challenge
But I noticed a few issues with cookies
There are some errors in nodrive's driver.cookies.set_all function. Comment out cookies = await connection.send(cdp.storage.get_cookies())
And set_all accepts List[cdp.network.CookieParam]
So you actually have to build the CookieParam list by hand, and on my machine I can't set a cookie for the current page correctly without specifying the domain for the cookie.
Below is the code I modified, it may still have some errors, and root_domain is extracted from the domain name using regular.

        await driver.cookies.clear()
        root_domain = plugin.extract_root_domain(req.url)
        cookies = []
        for cookie in req.cookies:
            if cookie['name'] == 'cf_clearance':
                domain = f".{root_domain}"
            else:
                domain = root_domain
            cookies.append(cdp.network.CookieParam(
                name=cookie['name'],  value=cookie['value'],
                path='/', domain = domain))

        await driver.cookies.set_all(cookies)

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
help wanted Extra attention is needed needs investigation
Projects
None yet
Development

Successfully merging this pull request may close these issues.

None yet