puppeteer-extra-plugin-stealth
Advanced tools
Comparing version 2.1.4 to 2.1.5
{ | ||
"name": "puppeteer-extra-plugin-stealth", | ||
"version": "2.1.4", | ||
"version": "2.1.5", | ||
"description": "Stealth mode: Applies various techniques to make detection of headless puppeteer harder.", | ||
@@ -38,5 +38,6 @@ "main": "index.js", | ||
"debug": "^3.1.0", | ||
"puppeteer-extra-plugin": "^2.1.1" | ||
"puppeteer-extra-plugin": "^2.1.1", | ||
"puppeteer-extra-plugin-anonymize-ua": "^2.1.1" | ||
}, | ||
"gitHead": "fa1fb7b878311b3406316638d0e351cf0d2c3bf2" | ||
"gitHead": "1ce4f6c7d671886003670efe5a37887a4700d534" | ||
} |
103
readme.md
@@ -13,8 +13,30 @@ # puppeteer-extra-plugin-stealth | ||
If this is your first [puppeteer-extra](https://github.com/berstend/puppeteer-extra) plugin here's everything you need: | ||
```bash | ||
yarn add puppeteer puppeteer-extra puppeteer-extra-plugin-stealth | ||
# - or - | ||
npm install puppeteer puppeteer-extra puppeteer-extra-plugin-stealth | ||
``` | ||
### Usage | ||
```js | ||
// puppeteer-extra is a drop-in replacement for puppeteer, | ||
// it augments the installed puppeteer with plugin functionality | ||
const puppeteer = require("puppeteer-extra") | ||
// add stealth plugin and use defaults (all evasion techniques) | ||
const pluginStealth = require("puppeteer-extra-plugin-stealth") | ||
puppeteer.use(pluginStealth()) | ||
// puppeteer usage as normal | ||
puppeteer.launch({ headless: true }).then(async browser => { | ||
const page = await browser.newPage() | ||
await page.setViewport({ width: 800, height: 600 }) | ||
await page.goto("https://bot.sannysoft.com") | ||
await page.waitFor(5000) | ||
await page.screenshot({ path: "testresult.png", fullPage: true }) | ||
await browser.close() | ||
}) | ||
``` | ||
@@ -26,6 +48,6 @@ | ||
- Improved: `navigator.plugins` - we fully emulate plugins/mimetypes in headless now 🎉 | ||
- New: `webgl.vendor` - is otherwise set to "Google" in headless | ||
- New: `window.outerdimensions` - fix missing window.outerWidth/outerHeight and viewport | ||
- Fixed: `navigator.webdriver` now returns undefined instead of false | ||
- Improved: `navigator.plugins` - we fully emulate plugins/mimetypes in headless now 🎉 | ||
- New: `webgl.vendor` - is otherwise set to "Google" in headless | ||
- New: `window.outerdimensions` - fix missing window.outerWidth/outerHeight and viewport | ||
- Fixed: `navigator.webdriver` now returns undefined instead of false | ||
@@ -62,2 +84,17 @@ ## Test results (red is bad) | ||
#### Improved reCAPTCHA v3 scores | ||
Using stealth also seems to help with maintaining a normal [reCAPTCHA v3 score](https://developers.google.com/recaptcha/docs/v3#score). | ||
<table class="image"> | ||
<tr> | ||
<td><figure class="image"><figcaption><code>Regular Puppeteer</code></figcaption><br/><img src="https://i.imgur.com/rHEH69b.png"></figure></td> | ||
<td><figure class="image"><figcaption><code>Stealth Puppeteer</code></figcaption><br/><img src="https://i.imgur.com/2if496Z.png"></figure></td> | ||
</tr> | ||
</table> | ||
Note: The [official test](https://recaptcha-demo.appspot.com/recaptcha-v3-request-scores.php) is to be taken with a grain of salt, as the score is calculated individually per site and multiple other factors (past behaviour, IP address, etc). Based on anecdotal observations it still seems to work as a rough indicator. | ||
## API | ||
@@ -69,9 +106,9 @@ | ||
- [Plugin](#plugin) | ||
- [Purpose](#purpose) | ||
- [Modularity](#modularity) | ||
- [Contributing](#contributing) | ||
- [Kudos](#kudos) | ||
- [availableEvasions](#availableevasions) | ||
- [enabledEvasions](#enabledevasions) | ||
- [Plugin](#plugin) | ||
- [Purpose](#purpose) | ||
- [Modularity](#modularity) | ||
- [Contributing](#contributing) | ||
- [Kudos](#kudos) | ||
- [availableEvasions](#availableevasions) | ||
- [enabledEvasions](#enabledevasions) | ||
@@ -106,3 +143,5 @@ ### [Plugin](https://git@github.com/:berstend/puppeteer-extra/blob/ff112879545e8e68d6500d731ceeafc22d187dd3/packages/puppeteer-extra-plugin-stealth/index.js#L72-L151) | ||
// bypass main module and require a specific stealth plugin directly: | ||
puppeteer.use(require('puppeteer-extra-plugin-stealth/evasions/console.debug')()) | ||
puppeteer.use( | ||
require("puppeteer-extra-plugin-stealth/evasions/console.debug")() | ||
) | ||
``` | ||
@@ -119,8 +158,8 @@ | ||
* * * | ||
--- | ||
Type: `function (opts)` | ||
- `opts` **[Object](https://developer.mozilla.org/docs/Web/JavaScript/Reference/Global_Objects/Object)** Options (optional, default `{}`) | ||
- `opts.enabledEvasions` **[Set](https://developer.mozilla.org/docs/Web/JavaScript/Reference/Global_Objects/Set)<[string](https://developer.mozilla.org/docs/Web/JavaScript/Reference/Global_Objects/String)>?** Specify which evasions to use (by default all) | ||
- `opts` **[Object](https://developer.mozilla.org/docs/Web/JavaScript/Reference/Global_Objects/Object)** Options (optional, default `{}`) | ||
- `opts.enabledEvasions` **[Set](https://developer.mozilla.org/docs/Web/JavaScript/Reference/Global_Objects/Set)<[string](https://developer.mozilla.org/docs/Web/JavaScript/Reference/Global_Objects/String)>?** Specify which evasions to use (by default all) | ||
@@ -130,21 +169,23 @@ Example: | ||
```javascript | ||
const puppeteer = require('puppeteer-extra') | ||
const puppeteer = require("puppeteer-extra") | ||
// Enable stealth plugin with all evasions | ||
puppeteer.use(require('puppeteer-extra-plugin-stealth')()) | ||
puppeteer.use(require("puppeteer-extra-plugin-stealth")()) | ||
;(async () => { | ||
// Launch the browser in headless mode and set up a page. | ||
const browser = await puppeteer.launch({ args: ['--no-sandbox'], headless: true }) | ||
const browser = await puppeteer.launch({ | ||
args: ["--no-sandbox"], | ||
headless: true | ||
}) | ||
const page = await browser.newPage() | ||
// Navigate to the page that will perform the tests. | ||
const testUrl = 'https://intoli.com/blog/' + | ||
'not-possible-to-block-chrome-headless/chrome-headless-test.html' | ||
const testUrl = | ||
"https://intoli.com/blog/" + | ||
"not-possible-to-block-chrome-headless/chrome-headless-test.html" | ||
await page.goto(testUrl) | ||
// Save a screenshot of the results. | ||
const screenshotPath = '/tmp/headless-test-result.png' | ||
await page.screenshot({path: screenshotPath}) | ||
console.log('have a look at the screenshot:', screenshotPath) | ||
const screenshotPath = "/tmp/headless-test-result.png" | ||
await page.screenshot({ path: screenshotPath }) | ||
console.log("have a look at the screenshot:", screenshotPath) | ||
@@ -155,3 +196,3 @@ await browser.close() | ||
* * * | ||
--- | ||
@@ -169,3 +210,3 @@ #### [availableEvasions](https://git@github.com/:berstend/puppeteer-extra/blob/ff112879545e8e68d6500d731ceeafc22d187dd3/packages/puppeteer-extra-plugin-stealth/index.js#L124-L126) | ||
```javascript | ||
const pluginStealth = require('puppeteer-extra-plugin-stealth')() | ||
const pluginStealth = require("puppeteer-extra-plugin-stealth")() | ||
console.log(pluginStealth.availableEvasions) // => Set { 'user-agent', 'console.debug' } | ||
@@ -175,3 +216,3 @@ puppeteer.use(pluginStealth) | ||
* * * | ||
--- | ||
@@ -190,7 +231,7 @@ #### [enabledEvasions](https://git@github.com/:berstend/puppeteer-extra/blob/ff112879545e8e68d6500d731ceeafc22d187dd3/packages/puppeteer-extra-plugin-stealth/index.js#L141-L143) | ||
// Remove specific evasion from enabled ones dynamically | ||
const pluginStealth = require('puppeteer-extra-plugin-stealth')() | ||
pluginStealth.enabledEvasions.delete('console.debug') | ||
const pluginStealth = require("puppeteer-extra-plugin-stealth")() | ||
pluginStealth.enabledEvasions.delete("console.debug") | ||
puppeteer.use(pluginStealth) | ||
``` | ||
* * * | ||
--- |
License Policy Violation
LicenseThis package is not allowed per your license policy. Review the package's license to ensure compliance.
Found 1 instance in 1 package
License Policy Violation
LicenseThis package is not allowed per your license policy. Review the package's license to ensure compliance.
Found 1 instance in 1 package
52597
227
3
+ Addedpuppeteer-extra-plugin@3.2.3(transitive)
+ Addedpuppeteer-extra-plugin-anonymize-ua@2.4.6(transitive)