Skip to content

Commit

Permalink
first commit
Browse files Browse the repository at this point in the history
  • Loading branch information
mdervisaygan committed Aug 23, 2024
0 parents commit cfc211d
Show file tree
Hide file tree
Showing 5,787 changed files with 714,661 additions and 0 deletions.
The diff you're trying to view is too large. We only load the first 3000 changed files.
1 change: 1 addition & 0 deletions .gitignore
Original file line number Diff line number Diff line change
@@ -0,0 +1 @@
./node_modules
38 changes: 38 additions & 0 deletions Dockerfile
Original file line number Diff line number Diff line change
@@ -0,0 +1,38 @@
# Use the official Node.js 16 image as the base image
FROM node:latest
RUN npm config set registry https://registry.npmjs.org/
RUN npm cache clean --force
# Install necessary dependencies for running Chrome
RUN apt-get update && apt-get install -y \
wget \
gnupg \
ca-certificates \
apt-transport-https \
xvfb \
&& rm -rf /var/lib/apt/lists/*

# Install Google Chrome
RUN wget -q -O - https://dl-ssl.google.com/linux/linux_signing_key.pub | apt-key add - \
&& echo "deb [arch=amd64] https://dl.google.com/linux/chrome/deb/ stable main" >> /etc/apt/sources.list.d/google.list \
&& apt-get update \
&& apt-get install -y google-chrome-stable \
&& rm -rf /var/lib/apt/lists/*

# Set up the working directory in the container
WORKDIR /app

# Copy package.json and package-lock.json to the working directory
COPY package*.json ./

# Install Node.js dependencies
RUN npm update --verbose
RUN npm install --verbose

# Copy the rest of the application code
COPY . .

# Expose the port your app runs on
EXPOSE 3000

# Command to run the application
CMD ["npm", "run","cjs_test"]
21 changes: 21 additions & 0 deletions LICENSE.md
Original file line number Diff line number Diff line change
@@ -0,0 +1,21 @@
MIT License

Copyright (c) 2023 - 2024 @zfcsoftware

Permission is hereby granted, free of charge, to any person obtaining a copy
of this software and associated documentation files (the "Software"), to deal
in the Software without restriction, including without limitation the rights
to use, copy, modify, merge, publish, distribute, sublicense, and/or sell
copies of the Software, and to permit persons to whom the Software is
furnished to do so, subject to the following conditions:

The above copyright notice and this permission notice shall be included in all
copies or substantial portions of the Software.

THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND, EXPRESS OR
IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF MERCHANTABILITY,
FITNESS FOR A PARTICULAR PURPOSE AND NONINFRINGEMENT. IN NO EVENT SHALL THE
AUTHORS OR COPYRIGHT HOLDERS BE LIABLE FOR ANY CLAIM, DAMAGES OR OTHER
LIABILITY, WHETHER IN AN ACTION OF CONTRACT, TORT OR OTHERWISE, ARISING FROM,
OUT OF OR IN CONNECTION WITH THE SOFTWARE OR THE USE OR OTHER DEALINGS IN THE
SOFTWARE.
175 changes: 175 additions & 0 deletions README.md
Original file line number Diff line number Diff line change
@@ -0,0 +1,175 @@
<br/>
<p align="center">
<a href="https://github.com/zfcsoftware/puppeteer-real-browser">
<img src="https://github.com/zfcsoftware/puppeteer-real-browser/assets/123484092/cc8b5fb9-504a-4fd3-97f6-a51990bb4303" alt="Logo" width="80" height="80">
</a>

<h3 align="center">Puppeteer Real Browser</h3>

<p align="center">
This package prevents Puppeteer from being detected as a bot in services like Cloudflare and allows you to pass captchas without any problems. It behaves like a real browser.
<br/>
<br/>
If you are only interested in Cloudflare WAF, please check this repo:<br/> https://github.com/zfcsoftware/cf-clearance-scraper
</p>
</p>

<p align="center">
<iframe width="560" height="315" src="https://www.youtube.com/embed/v2faTBy9uI0" frameborder="0" allowfullscreen></iframe>
</p>


<p align="center">
<img src="https://img.shields.io/github/contributors/zfcsoftware/puppeteer-real-browser?color=dark-green" alt="Contributors" />
<img src="https://img.shields.io/github/forks/zfcsoftware/puppeteer-real-browser?style=social" alt="Forks" />
<img src="https://img.shields.io/github/stars/zfcsoftware/puppeteer-real-browser?style=social" alt="Stargazers" />
<img src="https://img.shields.io/github/issues/zfcsoftware/puppeteer-real-browser" alt="Issues" />
<img src="https://img.shields.io/github/license/zfcsoftware/puppeteer-real-browser" alt="License" />
</p>



## Installation

If you are using a Linux operating system, xvfb must be installed for the library to work correctly.


```bash
npm i puppeteer-real-browser
```

if you are using linux:

```bash
sudo apt-get install xvfb
```



## Include

### CommonJS

```js

const start = async () => {
const { connect } = require('puppeteer-real-browser');
const { page, browser } = await connect({})
}

```
### Module

```js

import { connect } from 'puppeteer-real-browser'

const { page, browser } = await connect({})

```

## Usage


```js

const { connect } = require("puppeteer-real-browser")

async function test() {

const { browser, page } = connect({

headless: false,

args: [],

customConfig: {},

turnstile: true,

connectOption: {},

disableXvfb: false,

// proxy:{
// host:'<proxy-host>',
// port:'<proxy-port>',
// username:'<proxy-username>',
// password:'<proxy-password>'
// }

})
await page.goto('<url>')

}

```

**headless**: The default value is false. Values such as “new”, true, “shell” can also be sent, but it works most stable when false is used.

**args:** If there is an additional flag you want to add when starting Chromium, you can send it with this string.

**customConfig:** When launch is executed, the variables you send in be object are added. For example, you can specify the browser path with executablePath.

**turnstile:** Cloudflare Turnstile automatically clicks on Captchas if set to true

**connectOption:** The variables you send when connecting to chromium created with puppeteer.connect are added

**disableXvfb:** In Linux, when headless is false, a virtual screen is created and the browser is run there. You can set this value to true if you want to see the browser.

## Docker

You can use the Dockerfile file in the main directory to use this library with docker. It has been tested with docker on Ubuntu server operating systems.

To run a test, you can follow these steps


```bash
git clone https://github.com/zfcsoftware/puppeteer-real-browser
```

```bash
cd puppeteer-real-browser
```

```bash
docker build -t puppeteer-real-browser-project .
```


```bash
docker run puppeteer-real-browser-project
```

## Support Us

This library is completely open source and is constantly being updated. Please star this repo to support this project. Starring and supporting the project will ensure that it receives updates. If you want to support it further, you can consider sponsoring me (https://github.com/sponsors/zfcsoftware)

## License

Distributed under the MIT License. See [LICENSE](https://github.com/zfcsoftware/puppeteer-real-browser/blob/main/LICENSE.md) for more information.

## Thank You

**Contributions to the current version**

* **rebrowser™** - [rebrowser™](https://github.com/rebrowser) - *Created a patch pack for Runtime, which left many traces behind. Since Runtime was not used, most problems were solved. TargetFilter, which was used in the past and caused many problems, was switched to this patch. The Puppeteer-core library was patched and added to this repo. A lot of good bot detection systems are not caught thanks to rebrowser. Please star the rebrowser repo. Thank you. (https://github.com/rebrowser/rebrowser-patches)*
*
* **Skill Issue™** - [TheFalloutOf76](https://github.com/TheFalloutOf76) - *He realized that mouse movements could not be simulated accurately and created a solution for this. His solution is used in this library. (https://github.com/TheFalloutOf76/CDP-bug-MouseEvent-.screenX-.screenY-patcher)*


**For older versions**

* **Jimmy Laurent** - [Jimmy Laurent](https://github.com/JimmyLaurent) - *Inspired by cloudflare-scraper library*
* **CrispyyBaconx** - [CrispyyBaconx](https://github.com/CrispyyBaconx) - *Contributed to converting this library to Typescript*
* **Pavle Aleksic** - [pavlealeksic](https://github.com/pavlealeksic) - *We change the fingerprint with the puppeteer-afp library.*

## Disclaimer of Liability

No responsibility is accepted for the use of this software. This software is intended for educational and informational purposes only. Users should use this software at their own risk. The developer cannot be held liable for any damages that may result from the use of this software.

This software is not intended to bypass Cloudflare Captcha or any other security measure. It must not be used for malicious purposes. Malicious use may result in legal consequences.

This software is not officially endorsed or guaranteed. Users can visit the GitHub page to report bugs or contribute to the software, but they are not entitled to make any claims or request service fixes.

By using this software, you agree to this disclaimer.
60 changes: 60 additions & 0 deletions lib/cjs/index.js
Original file line number Diff line number Diff line change
@@ -0,0 +1,60 @@
const puppeteer = require('../data/puppeteer-core/lib/cjs/puppeteer/puppeteer-core.js')
const { pageController } = require('./module/pageController.js')
const Xvfb = require('xvfb');

process.env.REBROWSER_PATCHES_RUNTIME_FIX_MODE = "alwaysIsolated"
// process.env.REBROWSER_PATCHES_DEBUG = 1
async function connect({ args = [], headless = false, customConfig = {}, proxy = {}, turnstile = false, connectOption = {}, disableXvfb = false }) {
const { launch, Launcher } = await import('chrome-launcher');

let xvfbsession = null
if (headless == 'auto') headless = false

if (process.platform === 'linux' && disableXvfb === false) {
try {
xvfbsession = new Xvfb({
silent: true,
xvfb_args: ['-screen', '0', '1920x1080x24', '-ac']
});
xvfbsession.startSync();
} catch (err) {
console.log('You are running on a Linux platform but do not have xvfb installed. The browser can be captured. Please install it with the following command\n\nsudo apt-get install xvfb\n\n' + err.message);
}
}

const chrome = await launch({
chromeFlags: [
...Launcher.defaultFlags().filter(item => !item.includes("--disable-features")),
...args, ...((headless !== false) ? [`--headless=${headless}`] : []),
...((proxy && proxy.host && proxy.port) ? [`--proxy-server=${proxy.host}:${proxy.port}`] : []),
'--disable-features=Translate,OptimizationHints,MediaRouter,DialMediaRouteProvider,CalculateNativeWinOcclusion,InterestFeedContentSuggestions,CertificateTransparencyComponentUpdater,AutofillServerCommunication,PrivacySandboxSettings4,AutomationControlled'
],
...customConfig
});

const browser = await puppeteer.connect({
browserURL: `http://127.0.0.1:${chrome.port}`,
...connectOption
});

let [page] = await browser.pages();

let pageControllerConfig = { browser, page, proxy, turnstile, xvfbsession, pid: chrome.pid }

page = await pageController(pageControllerConfig);

browser.on('targetcreated', async target => {
if (target.type() === 'page') {
let newPage = await target.page();
pageControllerConfig.page = newPage
newPage = await pageController(pageControllerConfig);
}
});

return {
browser,
page
}
}

module.exports = { connect }
60 changes: 60 additions & 0 deletions lib/cjs/module/pageController.js
Original file line number Diff line number Diff line change
@@ -0,0 +1,60 @@
const { createCursor } = require('ghost-cursor');
const { checkTurnstile } = require('./turnstile.js');
const kill = require('tree-kill');

function getRandomInt(min, max) {
min = Math.ceil(min);
max = Math.floor(max);
return Math.floor(Math.random() * (max - min + 1)) + min;
}

async function pageController({ browser, page, proxy, turnstile, xvfbsession, pid }) {
let solveStatus = turnstile

page.on('close', () => {
solveStatus = false
});


browser.on('disconnected', async () => {
solveStatus = false
if (xvfbsession) try { xvfbsession.stopSync() } catch (err) { }
if (pid) try { kill(pid, 'SIGKILL') } catch (err) { }
});

async function turnstileSolver() {
while (solveStatus) {
await checkTurnstile({ page }).catch(() => { });
await new Promise(r => setTimeout(r, 1000));
}
return
}

turnstileSolver()

if (proxy.username && proxy.password) await page.authenticate({ username: proxy.username, password: proxy.password });

await page.evaluateOnNewDocument(() => {
Object.defineProperty(MouseEvent.prototype, 'screenX', {
get: function () {
return this.clientX + window.screenX;
}
});

Object.defineProperty(MouseEvent.prototype, 'screenY', {
get: function () {
return this.clientY + window.screenY;
}
});

});

const cursor = createCursor(page);
await cursor.moveTo({ x: getRandomInt(0, 800), y: getRandomInt(0, 600) });
page.realCursor = cursor
page.realClick = cursor.click

return page
}

module.exports = { pageController }
Loading

0 comments on commit cfc211d

Please sign in to comment.