puppeteer-extra-plugin-stealth
Advanced tools
Comparing version 2.2.2 to 2.2.5
@@ -11,11 +11,11 @@ 'use strict' | ||
class Plugin extends PuppeteerExtraPlugin { | ||
constructor (opts = {}) { | ||
constructor(opts = {}) { | ||
super(opts) | ||
} | ||
get name () { | ||
get name() { | ||
return 'stealth/evasions/_template' | ||
} | ||
async onPageCreated (page) { | ||
async onPageCreated(page) { | ||
await page.evaluateOnNewDocument(() => { | ||
@@ -27,4 +27,4 @@ console.debug('hello world') | ||
module.exports = function (pluginConfig) { | ||
module.exports = function(pluginConfig) { | ||
return new Plugin(pluginConfig) | ||
} |
@@ -11,11 +11,11 @@ 'use strict' | ||
class Plugin extends PuppeteerExtraPlugin { | ||
constructor (opts = {}) { | ||
constructor(opts = {}) { | ||
super(opts) | ||
} | ||
get name () { | ||
get name() { | ||
return 'stealth/evasions/chrome.runtime' | ||
} | ||
async onPageCreated (page) { | ||
async onPageCreated(page) { | ||
await page.evaluateOnNewDocument(() => { | ||
@@ -29,4 +29,4 @@ window.chrome = { | ||
module.exports = function (pluginConfig) { | ||
module.exports = function(pluginConfig) { | ||
return new Plugin(pluginConfig) | ||
} |
@@ -9,11 +9,11 @@ 'use strict' | ||
class Plugin extends PuppeteerExtraPlugin { | ||
constructor (opts = {}) { | ||
constructor(opts = {}) { | ||
super(opts) | ||
} | ||
get name () { | ||
get name() { | ||
return 'stealth/evasions/console.debug' | ||
} | ||
async onPageCreated (page) { | ||
async onPageCreated(page) { | ||
await page.evaluateOnNewDocument(() => { | ||
@@ -27,4 +27,4 @@ window.console.debug = () => { | ||
module.exports = function (pluginConfig) { | ||
module.exports = function(pluginConfig) { | ||
return new Plugin(pluginConfig) | ||
} |
@@ -9,11 +9,11 @@ 'use strict' | ||
class Plugin extends PuppeteerExtraPlugin { | ||
constructor (opts = {}) { | ||
constructor(opts = {}) { | ||
super(opts) | ||
} | ||
get name () { | ||
get name() { | ||
return 'stealth/evasions/navigator.languages' | ||
} | ||
async onPageCreated (page) { | ||
async onPageCreated(page) { | ||
await page.evaluateOnNewDocument(() => { | ||
@@ -28,4 +28,4 @@ // Overwrite the `plugins` property to use a custom getter. | ||
module.exports = function (pluginConfig) { | ||
module.exports = function(pluginConfig) { | ||
return new Plugin(pluginConfig) | ||
} |
@@ -9,11 +9,11 @@ 'use strict' | ||
class Plugin extends PuppeteerExtraPlugin { | ||
constructor (opts = {}) { | ||
constructor(opts = {}) { | ||
super(opts) | ||
} | ||
get name () { | ||
get name() { | ||
return 'stealth/evasions/navigator.permissions' | ||
} | ||
async onPageCreated (page) { | ||
async onPageCreated(page) { | ||
await page.evaluateOnNewDocument(() => { | ||
@@ -29,3 +29,3 @@ const originalQuery = window.navigator.permissions.query | ||
const oldCall = Function.prototype.call | ||
function call () { | ||
function call() { | ||
return oldCall.apply(this, arguments) | ||
@@ -42,3 +42,3 @@ } | ||
function functionToString () { | ||
function functionToString() { | ||
if (this === window.navigator.permissions.query) { | ||
@@ -58,4 +58,4 @@ return 'function query() { [native code] }' | ||
module.exports = function (pluginConfig) { | ||
module.exports = function(pluginConfig) { | ||
return new Plugin(pluginConfig) | ||
} |
@@ -11,13 +11,13 @@ 'use strict' | ||
class Plugin extends PuppeteerExtraPlugin { | ||
constructor (opts = {}) { | ||
constructor(opts = {}) { | ||
super(opts) | ||
} | ||
get name () { | ||
get name() { | ||
return 'stealth/evasions/navigator.plugins' | ||
} | ||
async onPageCreated (page) { | ||
async onPageCreated(page) { | ||
await page.evaluateOnNewDocument(() => { | ||
function mockPluginsAndMimeTypes () { | ||
function mockPluginsAndMimeTypes() { | ||
/* global MimeType MimeTypeArray PluginArray */ | ||
@@ -28,3 +28,3 @@ | ||
const oldCall = Function.prototype.call | ||
function call () { | ||
function call() { | ||
return oldCall.apply(this, arguments) | ||
@@ -41,3 +41,3 @@ } | ||
function functionToString () { | ||
function functionToString() { | ||
for (const fn of fns) { | ||
@@ -108,3 +108,3 @@ if (this === fn.ref) { | ||
// Returns the Plugin/MimeType with the specified name. | ||
const fn = function (name) { | ||
const fn = function(name) { | ||
if (!arguments.length) { | ||
@@ -122,3 +122,3 @@ throw new TypeError( | ||
// Returns the Plugin/MimeType at the specified index into the array. | ||
const fn = function (index) { | ||
const fn = function(index) { | ||
if (!arguments.length) { | ||
@@ -136,3 +136,3 @@ throw new TypeError( | ||
// Refreshes all plugins on the current page, optionally reloading documents. | ||
const fn = function () { | ||
const fn = function() { | ||
return undefined | ||
@@ -149,3 +149,3 @@ } | ||
function generateMimeTypeArray () { | ||
function generateMimeTypeArray() { | ||
const arr = fakeData.mimeTypes | ||
@@ -170,3 +170,3 @@ .map(obj => getSubset(['type', 'suffixes', 'description'], obj)) | ||
function generatePluginArray () { | ||
function generatePluginArray() { | ||
const arr = fakeData.plugins | ||
@@ -226,4 +226,4 @@ .map(obj => getSubset(['name', 'filename', 'description'], obj)) | ||
module.exports = function (pluginConfig) { | ||
module.exports = function(pluginConfig) { | ||
return new Plugin(pluginConfig) | ||
} |
@@ -10,11 +10,11 @@ 'use strict' | ||
class Plugin extends PuppeteerExtraPlugin { | ||
constructor (opts = {}) { | ||
constructor(opts = {}) { | ||
super(opts) | ||
} | ||
get name () { | ||
get name() { | ||
return 'stealth/evasions/navigator.webdriver' | ||
} | ||
async onPageCreated (page) { | ||
async onPageCreated(page) { | ||
// Chrome returns undefined, Firefox false | ||
@@ -31,4 +31,4 @@ await page.evaluateOnNewDocument(() => { | ||
module.exports = function (pluginConfig) { | ||
module.exports = function(pluginConfig) { | ||
return new Plugin(pluginConfig) | ||
} |
@@ -14,11 +14,11 @@ 'use strict' | ||
class Plugin extends PuppeteerExtraPlugin { | ||
constructor (opts = {}) { | ||
constructor(opts = {}) { | ||
super(opts) | ||
} | ||
get name () { | ||
get name() { | ||
return 'stealth/evasions/user-agent' | ||
} | ||
get dependencies () { | ||
get dependencies() { | ||
return new Set(['anonymize-ua']) | ||
@@ -28,4 +28,4 @@ } | ||
module.exports = function (pluginConfig) { | ||
module.exports = function(pluginConfig) { | ||
return new Plugin(pluginConfig) | ||
} |
@@ -9,11 +9,11 @@ 'use strict' | ||
class Plugin extends PuppeteerExtraPlugin { | ||
constructor (opts = {}) { | ||
constructor(opts = {}) { | ||
super(opts) | ||
} | ||
get name () { | ||
get name() { | ||
return 'stealth/evasions/webgl.vendor' | ||
} | ||
async onPageCreated (page) { | ||
async onPageCreated(page) { | ||
// Chrome returns undefined, Firefox false | ||
@@ -24,3 +24,3 @@ await page.evaluateOnNewDocument(() => { | ||
const getParameter = WebGLRenderingContext.getParameter | ||
WebGLRenderingContext.prototype.getParameter = function (parameter) { | ||
WebGLRenderingContext.prototype.getParameter = function(parameter) { | ||
// UNMASKED_VENDOR_WEBGL | ||
@@ -41,4 +41,4 @@ if (parameter === 37445) { | ||
module.exports = function (pluginConfig) { | ||
module.exports = function(pluginConfig) { | ||
return new Plugin(pluginConfig) | ||
} |
@@ -10,11 +10,11 @@ 'use strict' | ||
class Plugin extends PuppeteerExtraPlugin { | ||
constructor (opts = {}) { | ||
constructor(opts = {}) { | ||
super(opts) | ||
} | ||
get name () { | ||
get name() { | ||
return 'stealth/evasions/window.outerdimensions' | ||
} | ||
async onPageCreated (page) { | ||
async onPageCreated(page) { | ||
// Chrome returns undefined, Firefox false | ||
@@ -33,3 +33,3 @@ await page.evaluateOnNewDocument(() => { | ||
async beforeLaunch (options) { | ||
async beforeLaunch(options) { | ||
// Have viewport match window size, unless specified by user | ||
@@ -43,4 +43,4 @@ // https://github.com/GoogleChrome/puppeteer/issues/3688 | ||
module.exports = function (pluginConfig) { | ||
module.exports = function(pluginConfig) { | ||
return new Plugin(pluginConfig) | ||
} |
@@ -7,6 +7,6 @@ 'use strict' | ||
module.exports = async function () { | ||
module.exports = async function() { | ||
const results = {} | ||
async function test (name, fn) { | ||
async function test(name, fn) { | ||
const detectionPassed = await fn() | ||
@@ -36,5 +36,10 @@ if (detectionPassed) { | ||
await test('permissions API', async _ => { | ||
const permissionStatus = await navigator.permissions.query({name: 'notifications'}) | ||
const permissionStatus = await navigator.permissions.query({ | ||
name: 'notifications' | ||
}) | ||
// eslint-disable-next-line | ||
return Notification.permission === 'denied' && permissionStatus.state === 'prompt' | ||
return ( | ||
Notification.permission === 'denied' && // eslint-disable-line no-undef | ||
permissionStatus.state === 'prompt' | ||
) | ||
}) | ||
@@ -44,10 +49,16 @@ | ||
const permissions = window.navigator.permissions | ||
if (permissions.query.toString() !== 'function query() { [native code] }') return true | ||
if (permissions.query.toString.toString() !== 'function toString() { [native code] }') return true | ||
if (permissions.query.toString() !== 'function query() { [native code] }') | ||
return true | ||
if ( | ||
permissions.query.toString.hasOwnProperty('[[Handler]]') && | ||
permissions.query.toString.hasOwnProperty('[[Target]]') && | ||
permissions.query.toString.hasOwnProperty('[[IsRevoked]]') | ||
) return true | ||
if (permissions.hasOwnProperty('query')) return true | ||
permissions.query.toString.toString() !== | ||
'function toString() { [native code] }' | ||
) | ||
return true | ||
if ( | ||
permissions.query.toString.hasOwnProperty('[[Handler]]') && // eslint-disable-line no-prototype-builtins | ||
permissions.query.toString.hasOwnProperty('[[Target]]') && // eslint-disable-line no-prototype-builtins | ||
permissions.query.toString.hasOwnProperty('[[IsRevoked]]') // eslint-disable-line no-prototype-builtins | ||
) | ||
return true | ||
if (permissions.hasOwnProperty('query')) return true // eslint-disable-line no-prototype-builtins | ||
}) | ||
@@ -80,3 +91,3 @@ | ||
const spooky = /./ | ||
spooky.toString = function () { | ||
spooky.toString = function() { | ||
gotYou++ | ||
@@ -83,0 +94,0 @@ return 'spooky' |
@@ -9,3 +9,3 @@ 'use strict' | ||
;(async () => { | ||
const browser = await puppeteer.launch({args: ['--no-sandbox']}) | ||
const browser = await puppeteer.launch({ args: ['--no-sandbox'] }) | ||
const page = await browser.newPage() | ||
@@ -18,5 +18,8 @@ page.on('console', msg => { | ||
const detectionResults = await page.evaluate(detectHeadless) | ||
console.assert(Object.keys(detectionResults).length, 'No detection results returned.') | ||
console.assert( | ||
Object.keys(detectionResults).length, | ||
'No detection results returned.' | ||
) | ||
await browser.close() | ||
})() |
@@ -6,11 +6,14 @@ 'use strict' | ||
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) | ||
@@ -20,3 +23,3 @@ | ||
const screenshotPath = '/tmp/headless-test-result.png' | ||
await page.screenshot({path: screenshotPath}) | ||
await page.screenshot({ path: screenshotPath }) | ||
console.log('have a look at the screenshot:', screenshotPath) | ||
@@ -23,0 +26,0 @@ |
16
index.js
@@ -73,11 +73,11 @@ 'use strict' | ||
class Plugin extends PuppeteerExtraPlugin { | ||
constructor (opts = {}) { | ||
constructor(opts = {}) { | ||
super(opts) | ||
} | ||
get name () { | ||
get name() { | ||
return 'stealth' | ||
} | ||
get defaults () { | ||
get defaults() { | ||
const availableEvasions = new Set([ | ||
@@ -106,3 +106,3 @@ 'chrome.runtime', | ||
*/ | ||
get dependencies () { | ||
get dependencies() { | ||
return new Set( | ||
@@ -125,3 +125,3 @@ [...this.opts.enabledEvasions].map(e => `${this.name}/evasions/${e}`) | ||
*/ | ||
get availableEvasions () { | ||
get availableEvasions() { | ||
return this.defaults.availableEvasions | ||
@@ -143,3 +143,3 @@ } | ||
*/ | ||
get enabledEvasions () { | ||
get enabledEvasions() { | ||
return this.opts.enabledEvasions | ||
@@ -151,3 +151,3 @@ } | ||
*/ | ||
set enabledEvasions (evasions) { | ||
set enabledEvasions(evasions) { | ||
this.opts.enabledEvasions = evasions | ||
@@ -157,4 +157,4 @@ } | ||
module.exports = function (pluginConfig) { | ||
module.exports = function(pluginConfig) { | ||
return new Plugin(pluginConfig) | ||
} |
@@ -5,11 +5,11 @@ 'use strict' | ||
const { test } = require('ava') | ||
const test = require('ava') | ||
const Plugin = require('.') | ||
test('is a function', async (t) => { | ||
test('is a function', async t => { | ||
t.is(typeof Plugin, 'function') | ||
}) | ||
test('should have the basic class members', async (t) => { | ||
test('should have the basic class members', async t => { | ||
const instance = new Plugin() | ||
@@ -20,3 +20,3 @@ t.is(instance.name, PLUGIN_NAME) | ||
test('should have the public child class members', async (t) => { | ||
test('should have the public child class members', async t => { | ||
const instance = new Plugin() | ||
@@ -35,3 +35,3 @@ const prototype = Object.getPrototypeOf(instance) | ||
test('should have opts with default values', async (t) => { | ||
test('should have opts with default values', async t => { | ||
const instance = new Plugin() | ||
@@ -41,6 +41,6 @@ t.deepEqual(instance.opts.enabledEvasions, instance.availableEvasions) | ||
test('should add all dependencies dynamically', async (t) => { | ||
test('should add all dependencies dynamically', async t => { | ||
const instance = new Plugin() | ||
const deps = new Set([...instance.opts.enabledEvasions] | ||
.map(e => `${PLUGIN_NAME}/evasions/${e}`) | ||
const deps = new Set( | ||
[...instance.opts.enabledEvasions].map(e => `${PLUGIN_NAME}/evasions/${e}`) | ||
) | ||
@@ -50,7 +50,10 @@ t.deepEqual(instance.dependencies, deps) | ||
test('should add all dependencies dynamically including changes', async (t) => { | ||
test('should add all dependencies dynamically including changes', async t => { | ||
const instance = new Plugin() | ||
const fakeDep = 'foobar' | ||
instance.enabledEvasions = new Set([fakeDep]) | ||
t.deepEqual(instance.dependencies, new Set([`${PLUGIN_NAME}/evasions/${fakeDep}`])) | ||
t.deepEqual( | ||
instance.dependencies, | ||
new Set([`${PLUGIN_NAME}/evasions/${fakeDep}`]) | ||
) | ||
}) |
{ | ||
"name": "puppeteer-extra-plugin-stealth", | ||
"version": "2.2.2", | ||
"version": "2.2.5", | ||
"description": "Stealth mode: Applies various techniques to make detection of headless puppeteer harder.", | ||
@@ -13,3 +13,3 @@ "main": "index.js", | ||
"docs-for-evasions": "cd ./evasions && loop update-markdown-jsdoc", | ||
"test": "ava -v && standard", | ||
"test": "ava -v && eslint --ext .js .", | ||
"test-ci": "yarn test" | ||
@@ -33,14 +33,13 @@ }, | ||
"devDependencies": { | ||
"ava": "^0.25.0", | ||
"ava": "2.4.0", | ||
"loop": "^3.0.6", | ||
"puppeteer": "next", | ||
"standard": "^11.0.0", | ||
"update-markdown-jsdoc": "^1.0.2" | ||
"puppeteer": "^2.0.0", | ||
"update-markdown-jsdoc": "^1.0.11" | ||
}, | ||
"dependencies": { | ||
"debug": "^3.1.0", | ||
"puppeteer-extra-plugin": "^3.0.4", | ||
"puppeteer-extra-plugin-anonymize-ua": "^2.1.4" | ||
"debug": "^4.1.1", | ||
"puppeteer-extra-plugin": "^3.0.7", | ||
"puppeteer-extra-plugin-anonymize-ua": "^2.1.7" | ||
}, | ||
"gitHead": "17e693ccab5acf68c5153924490c8730449bf998" | ||
"gitHead": "21cf62f8aaa2b72479155ea02f178355a284080b" | ||
} |
@@ -1,2 +0,2 @@ | ||
# puppeteer-extra-plugin-stealth | ||
# puppeteer-extra-plugin-stealth [![Build Status](https://travis-ci.org/berstend/puppeteer-extra.svg?branch=master)](https://travis-ci.org/berstend/puppeteer-extra) [![npm](https://img.shields.io/npm/v/puppeteer-extra-plugin-stealth.svg)](https://www.npmjs.com/package/puppeteer-extra-plugin-stealth) | ||
@@ -97,2 +97,4 @@ > A plugin for [puppeteer-extra](https://github.com/berstend/puppeteer-extra) to prevent detection. | ||
_**Tip:** Have a look at the [recaptcha plugin](https://github.com/berstend/puppeteer-extra/tree/master/packages/puppeteer-extra-plugin-recaptcha) if you have issues with reCAPTCHAs._ | ||
## API | ||
@@ -99,0 +101,0 @@ |
Sorry, the diff of this file is not supported yet
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
53581
4
780
229
- Removeddebug@3.2.7(transitive)
Updateddebug@^4.1.1