Giter Site home page Giter Site logo

Comments (29)

EgglezosK avatar EgglezosK commented on July 16, 2024 3

Okay, so you can use this code:

For windows get this code for AutoHotKey v2

File name: cloudflare-bypass-script.ahk

  CoordMode("Mouse", "Window");
  
  x := A_Args[1];
  y := A_Args[2];
  
  MouseMove x, y, 10;
  Click ;
  ExitApp ;

For Ubuntu xdotool:
File name: cloudflare-bypass-script.sh

** Do not forget to set: sudo chmod +x on cloudflare-bypass-script.sh**


#!/bin/bash

x=$1
y=$2
speed=50

# Move the mouse to the specified coordinates
xdotool mousemove --sync $x $y

# Click the mouse
xdotool click 1

And for the NodeJS


import { connect } from './index.js'
import path from 'path';
import { fileURLToPath } from 'url';
import { exec } from 'child_process';
import xvfb from 'xvfb';

// Function to wait for a specified amount of time
function wait(ms) {
  //console.log('waiting');
  return new Promise(resolve => setTimeout(resolve, ms));
}

const __dirname = path.dirname(fileURLToPath(import.meta.url));
const cloudflareBypassScriptPath = path.join(__dirname, 'cloudflare-bypass-script.sh');

async function clickInCloudflareCheckbox(page) {
  
  try {
    const elements = await page.$$('iframe');
  
    for (const element of elements) {
      const iframeSrcURL = await element.evaluate(node => node.src);
      
      if (!iframeSrcURL.includes('turnstile')) {
        console.log('there is no turnstile');
        continue;
      }

      const box = await element.boundingBox();
      if (!box) {
        console.log('There is no BOX');
        continue;
      }

      const x = box.x * 1.3; // Manually curated adjustment coefficient
      const y = box.y * 1.7; // Manually curated adjustment coefficient
      
      exec(`"${cloudflareBypassScriptPath}" ${x} ${y}`);
      await wait(2000);
      exec(`"${cloudflareBypassScriptPath}" ${x} ${y}`);
      
      return;
    }
  } catch (error) {
    console.log(`Error in clickInCloudflareCheckbox. Error: ${error}`);
  }
}

async function ByPassCloudFlare(number, proxy) {
  return new Promise((resolve, reject) => {
    const xvfbInstance = new xvfb({
      displayNum: number,
      reuse: true,
      silent: true,
    });

    xvfbInstance.start(async (error) => {
      if (error) {
        reject(error);
        return;
      }

      try {
        console.log(proxy);
        const proxynew = proxy.split(":");
        console.log(`Start of test.js ${number}`);

        const { page, browser } = await connect({
          headless: 'auto',
          args: ['--no-sandbox', '--disable-setuid-sandbox'],
          customConfig: {},
          skipTarget: [],
          fingerprint: false,
          turnstile: false,
          connectOption: {},
          proxy: {
            host: proxynew[0], 
            port: proxynew[1], 
            username: "-",
            password: "-"
          },
          englezos_custom: 5
        });

        //console.log('Cookies loaded');
        console.log('Connected to browser');

        await page.goto('https://nopecha.com/demo/cloudflare', {
          waitUntil: 'domcontentloaded'
        });

        const page_title = await page.title();

        if (page_title.includes('Just a') || page_title.includes('Cloudflare')) {
          await wait(6000);
          //await page.screenshot({ path: `example_cloudflare_${number}.png` });
          await clickInCloudflareCheckbox(page);
          //await page.screenshot({ path: `example_cloudflare_after_click_${number}.png` });
        }

        console.log('Navigated to page');

        try {
          await page.waitForSelector('.link_row', {
            timeout: 60000
        })
        } catch {
          await browser.close();
          xvfbInstance.stop(() => {
            console.log('XVFB stopped');
          });
          resolve(null);
          return;
        }

        //await page.screenshot({ path: `example_${number}.png` });

        const cookies = await page.cookies();
        const userAgent = await page.evaluate(() => navigator.userAgent);

        await browser.close();
        xvfbInstance.stop(() => {
          console.log('XVFB stopped');
        });


        const result = {
          "proxy":proxy,
          "cookies":cookies,
          "agent": userAgent
        }
        resolve(result);
      } catch (err) {
        xvfbInstance.stop(() => {
          console.log('XVFB stopped');
        });
        reject(err);
      }
    });
  });
}

await ByPassCloudFlare(99,'127.0.0.1');

Hope in the future to find something more robust and quick!

from puppeteer-real-browser.

EgglezosK avatar EgglezosK commented on July 16, 2024 2

@zfcsoftware I don't think its my computer problem, i test it out on two laptops , one desktop and two VPS with Ubuntu 18.04 and 22.04.4 with same results. Maybe something wrong with my installation? Who knows....

### Good News!

After 3 days with a lot of research and tries, using your library @zfcsoftware and the main idea of @ziaq i think that i figure out how to make it work with VPS on Ubuntu and Windows while using proxies.

I am going to make a try of my installation on a clean VPS to make sure that my solutions is working and its robust and i will post here step by step guide how to do the same.

Screencast.from.05-07-2024.01-11-18.mp4

from puppeteer-real-browser.

EgglezosK avatar EgglezosK commented on July 16, 2024 1

@ziaq It seems AutoHotKey works on windows, then your script doesn't work on linux?

Yes, this solution is specifically for Windows, but I believe there are similar tools available for Linux with GUI too.

In an open source project you cannot stipulate conditions for sharing information.

I have examined the problem. I have tried many ways like windows, ubuntu, docker etc. and I have no problem. I think the problem is caused by the proxy country and the browser language not matching.

corporate plan works fine on Cloudflare as in the video. Proxy used.

2024-07-04.11-31-41.mp4

Hello @zfcsoftware , i am not sure about the language because i test it out with same country as my browser language and same origin website. Without proxy can bypass the cloudflare, with proxies from my country origin ( same as browser language ) still facing issue.

Any idea?

from puppeteer-real-browser.

EgglezosK avatar EgglezosK commented on July 16, 2024

Facing the same issue, will investigate also the solution

from puppeteer-real-browser.

Snadjim avatar Snadjim commented on July 16, 2024

Ok thank you. In the past I had this problem with selenium and to solve the problem I opened a second tab with the page where there is cloudflare and it worked. But here I can't open a second tab....

from puppeteer-real-browser.

chlwodud77 avatar chlwodud77 commented on July 16, 2024

I also faced with the same issue and tested with several times but same result.
Selecting checking cloudflare checkbox by selector is no more available to bypass..
Also same with sending press key tab + spacebar to avoid block.

I think should change bypass solution by moving mouse pointer to checkbox and click.

from puppeteer-real-browser.

zfcsoftware avatar zfcsoftware commented on July 16, 2024

I just tested with free and corporate plan Captcha with proxies from Webshare and had no problems. You can try sending the fingerprint variable false and changing the proxy.

from puppeteer-real-browser.

Snadjim avatar Snadjim commented on July 16, 2024

Hi @zfcsoftware,

I also try with my webshare proxy and still doesn't work. And howI can find the fake variable fingerprint and change the proxy?

from puppeteer-real-browser.

EgglezosK avatar EgglezosK commented on July 16, 2024

I just tested with free and corporate plan Captcha with proxies from Webshare and had no problems. You can try sending the fingerprint variable false and changing the proxy.

I just test it with proxies (Webshare) the result is this:

https://gyazo.com/14046e9a2b82506524a56131cef3ee93

this is the testing code:

`import { connect } from 'puppeteer-real-browser'
const proxy_uname = '-';
const proxy_pass = '-';
const proxy_ip = "-";

connect({
headless: 'auto',
args: [],
customConfig: {},
skipTarget: [],
fingerprint: false,
turnstile: true,
connectOption: {},
fpconfig: {},
proxy: {
host: "-",
port: "-",
username: '-',
password: '-'
}

})
.then(async response => {
const { browser, page } = response
await page.goto('https://nopecha.com/demo/cloudflare')
})
.catch(error => {
console.log(error.message)
})`

UPDATE

I give a try with turnstile:false and proxies and manually hit the tick button and access it normally. turbstile somehow being detected?

from puppeteer-real-browser.

zfcsoftware avatar zfcsoftware commented on July 16, 2024

I just tested with free and corporate plan Captcha with proxies from Webshare and had no problems. You can try sending the fingerprint variable false and changing the proxy.

I just test it with proxies (Webshare) the result is this:

https://gyazo.com/14046e9a2b82506524a56131cef3ee93

this is the testing code:

`import { connect } from 'puppeteer-real-browser' const proxy_uname = '-'; const proxy_pass = '-'; const proxy_ip = "-";

connect({ headless: 'auto', args: [], customConfig: {}, skipTarget: [], fingerprint: false, turnstile: true, connectOption: {}, fpconfig: {}, proxy: { host: "-", port: "-", username: '-', password: '-' }

}) .then(async response => { const { browser, page } = response await page.goto('https://nopecha.com/demo/cloudflare') }) .catch(error => { console.log(error.message) })`

UPDATE

I give a try with turnstile:false and proxies and manually hit the tick button and access it normally. turbstile somehow being detected?

I've just tested it on windows and linux and it's impossible for it not to work.

git clone https://github.com/zfcsoftware/puppeteer-real-browser
cd puppeteer-real-browser
npm install
node src/test.js

This way you can run the test.

from puppeteer-real-browser.

EgglezosK avatar EgglezosK commented on July 16, 2024

I just tested with free and corporate plan Captcha with proxies from Webshare and had no problems. You can try sending the fingerprint variable false and changing the proxy.

I just test it with proxies (Webshare) the result is this:
https://gyazo.com/14046e9a2b82506524a56131cef3ee93
this is the testing code:
import { connect } from 'puppeteer-real-browser' const proxy_uname = '-'; const proxy_pass = '-'; const proxy_ip = "-"; connect({ headless: 'auto', args: [], customConfig: {}, skipTarget: [], fingerprint: false, turnstile: true, connectOption: {}, fpconfig: {}, proxy: { host: "-", port: "-", username: '-', password: '-' } }) .then(async response => { const { browser, page } = response await page.goto('https://nopecha.com/demo/cloudflare') }) .catch(error => { console.log(error.message) })
UPDATE
I give a try with turnstile:false and proxies and manually hit the tick button and access it normally. turbstile somehow being detected?

I've just tested it on windows and linux and it's impossible for it not to work.

git clone https://github.com/zfcsoftware/puppeteer-real-browser
cd puppeteer-real-browser
npm install
node src/test.js

This way you can run the test.

I just run it, with out proxies working well, but while enable proxies ( Webshare ) it keeps reloading and the logs of the terminal is like this:

Start of test.js
Connected to browser
Navigated to page

until get timeout ( 60s )

Somehow trunstile detected

from puppeteer-real-browser.

zfcsoftware avatar zfcsoftware commented on July 16, 2024

I just tested with free and corporate plan Captcha with proxies from Webshare and had no problems. You can try sending the fingerprint variable false and changing the proxy.

I just test it with proxies (Webshare) the result is this:
https://gyazo.com/14046e9a2b82506524a56131cef3ee93
this is the testing code:
import { connect } from 'puppeteer-real-browser' const proxy_uname = '-'; const proxy_pass = '-'; const proxy_ip = "-"; connect({ headless: 'auto', args: [], customConfig: {}, skipTarget: [], fingerprint: false, turnstile: true, connectOption: {}, fpconfig: {}, proxy: { host: "-", port: "-", username: '-', password: '-' } }) .then(async response => { const { browser, page } = response await page.goto('https://nopecha.com/demo/cloudflare') }) .catch(error => { console.log(error.message) })
UPDATE
I give a try with turnstile:false and proxies and manually hit the tick button and access it normally. turbstile somehow being detected?

I've just tested it on windows and linux and it's impossible for it not to work.

git clone https://github.com/zfcsoftware/puppeteer-real-browser
cd puppeteer-real-browser
npm install
node src/test.js

This way you can run the test.

I just run it, with out proxies working well, but while enable proxies ( Webshare ) it keeps reloading and the logs of the terminal is like this:

Start of test.js Connected to browser Navigated to page

until get timeout ( 60s )

Somehow trunstile detected

[email protected]
Can you send your anydesk id to my mail?
https://anydesk.com/en

from puppeteer-real-browser.

ziaq avatar ziaq commented on July 16, 2024

Emulate real mouse movement and a click on the checkbox - it works without even trying to mimic human behavior. Just teleport the cursor to the checkbox and click immediately.

Here's a simple Autohotkey script:

#Requires AutoHotkey v2.0
CoordMode("Mouse", "Window")  ; Sets the mouse coordinates relative to the active window

x := A_Args[1]  ; Takes the first argument as the x-coordinate
y := A_Args[2]  ; Takes the second argument as the y-coordinate

MouseMove x, y, 50  ; 50 is speed
Click  ;

ExitApp  ;

Pass the coordinates of the checkbox to it and run it using exec:

const __dirname = path.dirname(fileURLToPath(import.meta.url));
const cloudflareBypassScriptPath = path.join(__dirname, 'cloudflare-bypass-script.ahk');

async function clickInCloudflareCheckbox(page: Page): Promise<void> {
  try {
    const elements = await page.$$('iframe');

    for (const element of elements) {
      const iframeSrcURL = await element.evaluate(node => node.src);
      if (!iframeSrcURL.includes('turnstile')) continue;

      const box = await element.boundingBox();
      if (!box) continue;

      const x = box.x * 2.4; // Manually curated adjustment coefficient
      const y = box.y * 3.8; // Manually curated adjustment coefficient
      
      exec(`"${cloudflareBypassScriptPath}" ${x} ${y}`);
      return;
    }
  } catch (error) {
    throw new Error(`Error in clickInCloudflareCheckbox. Error: ${error}`);
  }
}

from puppeteer-real-browser.

EgglezosK avatar EgglezosK commented on July 16, 2024

Emulate real mouse movement and a click on the checkbox - it works without even trying to mimic human behavior. Just teleport the cursor to the checkbox and click immediately.

Here's a simple Autohotkey script:

#Requires AutoHotkey v2.0
CoordMode("Mouse", "Window")  ; Sets the mouse coordinates relative to the active window

x := A_Args[1]  ; Takes the first argument as the x-coordinate
y := A_Args[2]  ; Takes the second argument as the y-coordinate

MouseMove x, y, 50  ; 50 is speed
Click  ;

ExitApp  ;

Pass the coordinates of the checkbox to it and run it using exec:

const __dirname = path.dirname(fileURLToPath(import.meta.url));
const cloudflareBypassScriptPath = path.join(__dirname, 'cloudflare-bypass-script.ahk');

async function clickInCloudflareCheckbox(page: Page): Promise<void> {
  try {
    const elements = await page.$$('iframe');

    for (const element of elements) {
      const iframeSrcURL = await element.evaluate(node => node.src);
      if (!iframeSrcURL.includes('turnstile')) continue;

      const box = await element.boundingBox();
      if (!box) continue;

      const x = box.x * 2.4; // Manually curated adjustment coefficient
      const y = box.y * 3.8; // Manually curated adjustment coefficient
      
      exec(`"${cloudflareBypassScriptPath}" ${x} ${y}`);
      return;
    }
  } catch (error) {
    throw new Error(`Error in clickInCloudflareCheckbox. Error: ${error}`);
  }
}

Can you give a full example please?

from puppeteer-real-browser.

ziaq avatar ziaq commented on July 16, 2024

Emulate real mouse movement and a click on the checkbox - it works without even trying to mimic human behavior. Just teleport the cursor to the checkbox and click immediately.
Here's a simple Autohotkey script:

#Requires AutoHotkey v2.0
CoordMode("Mouse", "Window")  ; Sets the mouse coordinates relative to the active window

x := A_Args[1]  ; Takes the first argument as the x-coordinate
y := A_Args[2]  ; Takes the second argument as the y-coordinate

MouseMove x, y, 50  ; 50 is speed
Click  ;

ExitApp  ;

Pass the coordinates of the checkbox to it and run it using exec:

const __dirname = path.dirname(fileURLToPath(import.meta.url));
const cloudflareBypassScriptPath = path.join(__dirname, 'cloudflare-bypass-script.ahk');

async function clickInCloudflareCheckbox(page: Page): Promise<void> {
  try {
    const elements = await page.$$('iframe');

    for (const element of elements) {
      const iframeSrcURL = await element.evaluate(node => node.src);
      if (!iframeSrcURL.includes('turnstile')) continue;

      const box = await element.boundingBox();
      if (!box) continue;

      const x = box.x * 2.4; // Manually curated adjustment coefficient
      const y = box.y * 3.8; // Manually curated adjustment coefficient
      
      exec(`"${cloudflareBypassScriptPath}" ${x} ${y}`);
      return;
    }
  } catch (error) {
    throw new Error(`Error in clickInCloudflareCheckbox. Error: ${error}`);
  }
}

Can you give a full example please?

This is a comprehensive example, with the rest of the code being specific to my project. Just use my fn after page.goto:

  await page.goto(
    'https://example.com', 
    { waitUntil: 'domcontentloaded' },
  );
  await wait(10000);

  await clickInCloudflareCheckbox(page);
  await wait(5000);

  return page;

from puppeteer-real-browser.

chlwodud77 avatar chlwodud77 commented on July 16, 2024

@ziaq It seems AutoHotKey works on windows, then your script doesn't work on linux?

from puppeteer-real-browser.

ziaq avatar ziaq commented on July 16, 2024

@ziaq It seems AutoHotKey works on windows, then your script doesn't work on linux?

Yes, this solution is specifically for Windows, but I believe there are similar tools available for Linux with GUI too.

from puppeteer-real-browser.

zfcsoftware avatar zfcsoftware commented on July 16, 2024

@ziaq It seems AutoHotKey works on windows, then your script doesn't work on linux?

Yes, this solution is specifically for Windows, but I believe there are similar tools available for Linux with GUI too.

In an open source project you cannot stipulate conditions for sharing information.

I have examined the problem. I have tried many ways like windows, ubuntu, docker etc. and I have no problem. I think the problem is caused by the proxy country and the browser language not matching.

corporate plan works fine on Cloudflare as in the video. Proxy used.

2024-07-04.11-31-41.mp4

from puppeteer-real-browser.

zfcsoftware avatar zfcsoftware commented on July 16, 2024

@ziaq It seems AutoHotKey works on windows, then your script doesn't work on linux?

Yes, this solution is specifically for Windows, but I believe there are similar tools available for Linux with GUI too.

In an open source project you cannot stipulate conditions for sharing information.
I have examined the problem. I have tried many ways like windows, ubuntu, docker etc. and I have no problem. I think the problem is caused by the proxy country and the browser language not matching.
corporate plan works fine on Cloudflare as in the video. Proxy used.
2024-07-04.11-31-41.mp4

Hello @zfcsoftware , i am not sure about the language because i test it out with same country as my browser language and same origin website. Without proxy can bypass the cloudflare, with proxies from my country origin ( same as browser language ) still facing issue.

Any idea?

Maybe it's webrtc, but in that case it shouldn't work for me either. Interesting problem. Could you please test with docker on wsl?
https://github.com/zfcsoftware/puppeteer-real-browser?tab=readme-ov-file#docker

from puppeteer-real-browser.

EgglezosK avatar EgglezosK commented on July 16, 2024

@ziaq It seems AutoHotKey works on windows, then your script doesn't work on linux?

Yes, this solution is specifically for Windows, but I believe there are similar tools available for Linux with GUI too.

In an open source project you cannot stipulate conditions for sharing information.
I have examined the problem. I have tried many ways like windows, ubuntu, docker etc. and I have no problem. I think the problem is caused by the proxy country and the browser language not matching.
corporate plan works fine on Cloudflare as in the video. Proxy used.
2024-07-04.11-31-41.mp4

Hello @zfcsoftware , i am not sure about the language because i test it out with same country as my browser language and same origin website. Without proxy can bypass the cloudflare, with proxies from my country origin ( same as browser language ) still facing issue.
Any idea?

Maybe it's webrtc, but in that case it shouldn't work for me either. Interesting problem. Could you please test with docker on wsl? https://github.com/zfcsoftware/puppeteer-real-browser?tab=readme-ov-file#docker

@zfcsoftware no luck at all,
image

facing the same issue.

maybe can i give you anydesk, and try with your proxy in my system to check the results?

from puppeteer-real-browser.

zfcsoftware avatar zfcsoftware commented on July 16, 2024

@ziaq It seems AutoHotKey works on windows, then your script doesn't work on linux?

Yes, this solution is specifically for Windows, but I believe there are similar tools available for Linux with GUI too.

In an open source project you cannot stipulate conditions for sharing information.
I have examined the problem. I have tried many ways like windows, ubuntu, docker etc. and I have no problem. I think the problem is caused by the proxy country and the browser language not matching.
corporate plan works fine on Cloudflare as in the video. Proxy used.
2024-07-04.11-31-41.mp4

Hello @zfcsoftware , i am not sure about the language because i test it out with same country as my browser language and same origin website. Without proxy can bypass the cloudflare, with proxies from my country origin ( same as browser language ) still facing issue.
Any idea?

Maybe it's webrtc, but in that case it shouldn't work for me either. Interesting problem. Could you please test with docker on wsl? https://github.com/zfcsoftware/puppeteer-real-browser?tab=readme-ov-file#docker

@zfcsoftware no luck at all, image

facing the same issue.

maybe can i give you anydesk, and try with your proxy in my system to check the results?

Sounds like a problem with your computer. Can you rent a vps from a server provider like Vultr and test it?

from puppeteer-real-browser.

CValeron avatar CValeron commented on July 16, 2024

@EgglezosK hi,

I do receive " Error: net::ERR_NO_SUPPORTED_PROXIES " error with sample code you provided. How I can resolve this ?

Thank you

from puppeteer-real-browser.

EgglezosK avatar EgglezosK commented on July 16, 2024

@EgglezosK hi,

I do receive " Error: net::ERR_NO_SUPPORTED_PROXIES " error with sample code you provided. How I can resolve this ?

Thank you

Make sure you have change the proxy from example with your own. ( Webshare for example )

await ByPassCloudFlare(ANY_INT_NUMBER,'127.0.0.1:5555');

in case you don't want to use proxies, you have to comment this part of the code:


proxy: {
            host: proxynew[0], 
            port: proxynew[1], 
            username: "-",
            password: "-"
          },


from puppeteer-real-browser.

CValeron avatar CValeron commented on July 16, 2024

Thank you solved it, but not I cannot use xdotool in my amazon linux instance. Is it event possible to click mouse with aws instance ?

Will below mouse click can also work ?

await page.mouse.click(box.x, box.y, { button: 'left' })
await snooze(15000);

from puppeteer-real-browser.

TheRealStingo avatar TheRealStingo commented on July 16, 2024

@EgglezosK hi,
I do receive " Error: net::ERR_NO_SUPPORTED_PROXIES " error with sample code you provided. How I can resolve this ?
Thank you

Make sure you have change the proxy from example with your own. ( Webshare for example )

await ByPassCloudFlare(ANY_INT_NUMBER,'127.0.0.1:5555');

in case you don't want to use proxies, you have to comment this part of the code:


proxy: {
            host: proxynew[0], 
            port: proxynew[1], 
            username: "-",
            password: "-"
          },

Tried your code on windows , it didnt want to work , doesnt click , tried to investigate a bit found that
const elements = await page.$$("iframe"); console.log(elements)

returns an empty array for some reason

Here is my code on Windows :

import { connect } from "puppeteer-real-browser";
import path from "path";
import { fileURLToPath } from "url";
import { exec } from "child_process";

// Function to wait for a specified amount of time
function wait(ms) {
  return new Promise((resolve) => setTimeout(resolve, ms));
}

const __dirname = path.dirname(fileURLToPath(import.meta.url));
const cloudflareBypassScriptPath = path.join(__dirname, "click.ahk");

async function clickInCloudflareCheckbox(page) {
  console.log("Clicking function");
  try {
    const elements = await page.$$("iframe");
    console.log(elements);

    for (const element of elements) {
      const iframeSrcURL = await element.evaluate((node) => node.src);

      if (!iframeSrcURL.includes("turnstile")) {
        console.log("there is no turnstile");
        continue;
      }

      const box = await element.boundingBox();
      if (!box) {
        console.log("There is no BOX");
        continue;
      }

      const x = box.x * 1.3; // Manually curated adjustment coefficient
      const y = box.y * 1.7; // Manually curated adjustment coefficient
      console.log({ x, y });

      exec(`"${cloudflareBypassScriptPath}" ${x} ${y}`);
      await wait(2000);
      exec(`"${cloudflareBypassScriptPath}" ${x} ${y}`);

      return;
    }
  } catch (error) {
    console.log(`Error in clickInCloudflareCheckbox. Error: ${error}`);
  }
}

async function ByPassCloudFlare(number) {
  try {
    const { page, browser } = await connect({
      headless: "auto",
      args: ["--no-sandbox", "--disable-setuid-sandbox"],
      customConfig: {},
      skipTarget: [],
      fingerprint: false,
      turnstile: false,
      connectOption: {},
      englezos_custom: 5,
    });

    console.log("Connected to browser");

    await page.goto("https://nopecha.com/demo/cloudflare", {
      waitUntil: "domcontentloaded",
    });

    const page_title = await page.title();

    if (page_title.includes("Just a") || page_title.includes("Cloudflare")) {
      await wait(6000);
      console.log("Clicking");
      await clickInCloudflareCheckbox(page);
    }

    console.log("Navigated to page");

    try {
      await page.waitForSelector(".link_row", {
        timeout: 60000,
      });
    } catch {
      await browser.close();
      return null;
    }

    const cookies = await page.cookies();
    const userAgent = await page.evaluate(() => navigator.userAgent);

    await browser.close();

    return {
      cookies: cookies,
      agent: userAgent,
    };
  } catch (err) {
    console.error(`Error in ByPassCloudFlare: ${err}`);
    return null;
  }
}

// Call the function
ByPassCloudFlare(99)
  .then((result) => {
    console.log(result);
  })
  .catch((err) => {
    console.error(err);
  });

Setup :
image

from puppeteer-real-browser.

EgglezosK avatar EgglezosK commented on July 16, 2024

@EgglezosK hi,
I do receive " Error: net::ERR_NO_SUPPORTED_PROXIES " error with sample code you provided. How I can resolve this ?
Thank you

Make sure you have change the proxy from example with your own. ( Webshare for example )

await ByPassCloudFlare(ANY_INT_NUMBER,'127.0.0.1:5555');

in case you don't want to use proxies, you have to comment this part of the code:


proxy: {
            host: proxynew[0], 
            port: proxynew[1], 
            username: "-",
            password: "-"
          },

Tried your code on windows , it didnt want to work , doesnt click , tried to investigate a bit found that const elements = await page.$$("iframe"); console.log(elements)

returns an empty array for some reason

Here is my code on Windows :

import { connect } from "puppeteer-real-browser";
import path from "path";
import { fileURLToPath } from "url";
import { exec } from "child_process";

// Function to wait for a specified amount of time
function wait(ms) {
  return new Promise((resolve) => setTimeout(resolve, ms));
}

const __dirname = path.dirname(fileURLToPath(import.meta.url));
const cloudflareBypassScriptPath = path.join(__dirname, "click.ahk");

async function clickInCloudflareCheckbox(page) {
  console.log("Clicking function");
  try {
    const elements = await page.$$("iframe");
    console.log(elements);

    for (const element of elements) {
      const iframeSrcURL = await element.evaluate((node) => node.src);

      if (!iframeSrcURL.includes("turnstile")) {
        console.log("there is no turnstile");
        continue;
      }

      const box = await element.boundingBox();
      if (!box) {
        console.log("There is no BOX");
        continue;
      }

      const x = box.x * 1.3; // Manually curated adjustment coefficient
      const y = box.y * 1.7; // Manually curated adjustment coefficient
      console.log({ x, y });

      exec(`"${cloudflareBypassScriptPath}" ${x} ${y}`);
      await wait(2000);
      exec(`"${cloudflareBypassScriptPath}" ${x} ${y}`);

      return;
    }
  } catch (error) {
    console.log(`Error in clickInCloudflareCheckbox. Error: ${error}`);
  }
}

async function ByPassCloudFlare(number) {
  try {
    const { page, browser } = await connect({
      headless: "auto",
      args: ["--no-sandbox", "--disable-setuid-sandbox"],
      customConfig: {},
      skipTarget: [],
      fingerprint: false,
      turnstile: false,
      connectOption: {},
      englezos_custom: 5,
    });

    console.log("Connected to browser");

    await page.goto("https://nopecha.com/demo/cloudflare", {
      waitUntil: "domcontentloaded",
    });

    const page_title = await page.title();

    if (page_title.includes("Just a") || page_title.includes("Cloudflare")) {
      await wait(6000);
      console.log("Clicking");
      await clickInCloudflareCheckbox(page);
    }

    console.log("Navigated to page");

    try {
      await page.waitForSelector(".link_row", {
        timeout: 60000,
      });
    } catch {
      await browser.close();
      return null;
    }

    const cookies = await page.cookies();
    const userAgent = await page.evaluate(() => navigator.userAgent);

    await browser.close();

    return {
      cookies: cookies,
      agent: userAgent,
    };
  } catch (err) {
    console.error(`Error in ByPassCloudFlare: ${err}`);
    return null;
  }
}

// Call the function
ByPassCloudFlare(99)
  .then((result) => {
    console.log(result);
  })
  .catch((err) => {
    console.error(err);
  });

Setup : image

yesterday cf change their iframe shadow and its been not detectable, thanks to zcdsowatre try this:



async function clickInCloudflareCheckbox(page) {

  const elements = await page.$$('.cf-turnstile-wrapper');

            if (elements.length <= 0){
              console.log('still no box');
            }

            for (const element of elements) {
                try {
                    const box = await element.boundingBox();

                    const x = box.x + box.width / 2;
                    const y = box.y + box.height / 2;
                    console.log(x + ' The X of the box');

                    await wait(3000);
                    console.log('now click');
                    exec(`"${cloudflareBypassScriptPath}" ${x-50} ${y*1.55}`);
                } catch (err) { }
            }
}

from puppeteer-real-browser.

zfcsoftware avatar zfcsoftware commented on July 16, 2024

Can you please try again with the latest version of the library?

from puppeteer-real-browser.

EgglezosK avatar EgglezosK commented on July 16, 2024

Can you please try again with the latest version of the library?
@zfcsoftware
Thanks for the recent update! I face the same problem while using proxies, without them working like a charm.

from puppeteer-real-browser.

DivMode avatar DivMode commented on July 16, 2024

Same issue here, it works with my residential ip but with webshare proxies im failing 90% of the time now.

Was wondering is there a way to detect when the turnstile captcha has failed and close the browser instead of waiting for the timeout? With the recent captcha failures its keeping my lambda up until it times out and closes the broser increasing my costs.

from puppeteer-real-browser.

Related Issues (20)

Recommend Projects

  • React photo React

    A declarative, efficient, and flexible JavaScript library for building user interfaces.

  • Vue.js photo Vue.js

    🖖 Vue.js is a progressive, incrementally-adoptable JavaScript framework for building UI on the web.

  • Typescript photo Typescript

    TypeScript is a superset of JavaScript that compiles to clean JavaScript output.

  • TensorFlow photo TensorFlow

    An Open Source Machine Learning Framework for Everyone

  • Django photo Django

    The Web framework for perfectionists with deadlines.

  • D3 photo D3

    Bring data to life with SVG, Canvas and HTML. 📊📈🎉

Recommend Topics

  • javascript

    JavaScript (JS) is a lightweight interpreted programming language with first-class functions.

  • web

    Some thing interesting about web. New door for the world.

  • server

    A server is a program made to process requests and deliver data to clients.

  • Machine learning

    Machine learning is a way of modeling and interpreting data that allows a piece of software to respond intelligently.

  • Game

    Some thing interesting about game, make everyone happy.

Recommend Org

  • Facebook photo Facebook

    We are working to build community through open source technology. NB: members must have two-factor auth.

  • Microsoft photo Microsoft

    Open source projects and samples from Microsoft.

  • Google photo Google

    Google ❤️ Open Source for everyone.

  • D3 photo D3

    Data-Driven Documents codes.