Eltik / Puppeteer-Bypass

Bypassing CloudFlare's anti-bot challenge with Puppeteer optimizations
61 stars 8 forks source link

How to use with an existing puppeteer project ? #4

Closed KaKi87 closed 7 months ago

KaKi87 commented 8 months ago

Hi,

I have an existing puppeteer project on which I've been using puppeteer-extra-plugin-stealth, like the following :

import puppeteer from 'puppeteer-extra';
import puppeteerStealth from 'puppeteer-extra-plugin-stealth';
puppeteer.use(puppeteerStealth());
const browser = await puppeteer.launch({ headless: false });
// etc...

Which bypassed Cloudflare for a while, but failed at it lately.

So, I'd like to try your project instead, but I don't understand how to import it ?

Thanks

Eltik commented 7 months ago

Hey sorry for the late reply. You can clone the repository or just copy the API.ts file into your project. Then, use import * as Puppeteer-Bypass from "./API.ts".

KaKi87 commented 7 months ago

Would it be possible to import it as JS instead of TS ? Also, how to use the Puppeteer-Bypass variable then ?

Eltik commented 7 months ago

Well in that case, you'd import the API.js file from the ./built folder. And as shown in the documentation, simply const bypass = new PuppeteerBypass() (assuming your import is import * as PuppeteerBypass from "./API.js").

KaKi87 commented 7 months ago

Okay but then what, do I do puppeteer.use(bypass) or something ? Thanks

Eltik commented 7 months ago

I see what you want, but that isn't how this project works. It can't be used as a puppeteer extension. I suggest reading the documentation here.

KaKi87 commented 7 months ago

It can't be used as a puppeteer extension.

Well, that answers my question, yes I've seen the README, but that's indeed not what I need 😅

Thanks anyway.

rainb3rry commented 3 months ago

It can't be used as a puppeteer extension.

Well, that answers my question, yes I've seen the README, but that's indeed not what I need 😅

Thanks anyway.

Hey @KaKi87 I have exactly the same problems lately, have you found any solution about that?

KaKi87 commented 3 months ago

I did !

Here's the config that works :

import puppeteer from 'puppeteer-extra';
import createPuppeteerStealth from 'puppeteer-extra-plugin-stealth';

const puppeteerStealth = createPuppeteerStealth();
puppeteerStealth.enabledEvasions.delete('user-agent-override'); // <-- Only for Linux
puppeteer.use(puppeteerStealth);

const browser = await puppeteer.launch({
    headless: false,
    targetFilter: target => target.type() !== 'other'
});

Source discussion : berstend/puppeteer-extra#817

++