Rename to hkt.sh
This commit is contained in:
66
node_modules/puppeteer-extra-plugin-stealth/evasions/navigator.vendor/index.js
generated
vendored
Normal file
66
node_modules/puppeteer-extra-plugin-stealth/evasions/navigator.vendor/index.js
generated
vendored
Normal file
@@ -0,0 +1,66 @@
|
||||
'use strict'
|
||||
|
||||
const { PuppeteerExtraPlugin } = require('puppeteer-extra-plugin')
|
||||
|
||||
const withUtils = require('../_utils/withUtils')
|
||||
|
||||
/**
|
||||
* By default puppeteer will have a fixed `navigator.vendor` property.
|
||||
*
|
||||
* This plugin makes it possible to change this property.
|
||||
*
|
||||
* @example
|
||||
* const puppeteer = require("puppeteer-extra")
|
||||
*
|
||||
* const StealthPlugin = require("puppeteer-extra-plugin-stealth")
|
||||
* const stealth = StealthPlugin()
|
||||
* // Remove this specific stealth plugin from the default set
|
||||
* stealth.enabledEvasions.delete("navigator.vendor")
|
||||
* puppeteer.use(stealth)
|
||||
*
|
||||
* // Stealth plugins are just regular `puppeteer-extra` plugins and can be added as such
|
||||
* const NavigatorVendorPlugin = require("puppeteer-extra-plugin-stealth/evasions/navigator.vendor")
|
||||
* const nvp = NavigatorVendorPlugin({ vendor: 'Apple Computer, Inc.' }) // Custom vendor
|
||||
* puppeteer.use(nvp)
|
||||
*
|
||||
* @param {Object} [opts] - Options
|
||||
* @param {string} [opts.vendor] - The vendor to use in `navigator.vendor` (default: `Google Inc.`)
|
||||
*
|
||||
*/
|
||||
class Plugin extends PuppeteerExtraPlugin {
|
||||
constructor(opts = {}) {
|
||||
super(opts)
|
||||
}
|
||||
|
||||
get name() {
|
||||
return 'stealth/evasions/navigator.vendor'
|
||||
}
|
||||
|
||||
get defaults() {
|
||||
return {
|
||||
vendor: 'Google Inc.'
|
||||
}
|
||||
}
|
||||
|
||||
async onPageCreated(page) {
|
||||
this.debug('onPageCreated', {
|
||||
opts: this.opts
|
||||
})
|
||||
|
||||
await withUtils(page).evaluateOnNewDocument(
|
||||
(utils, { opts }) => {
|
||||
utils.replaceGetterWithProxy(
|
||||
Object.getPrototypeOf(navigator),
|
||||
'vendor',
|
||||
utils.makeHandler().getterValue(opts.vendor)
|
||||
)
|
||||
},
|
||||
{
|
||||
opts: this.opts
|
||||
}
|
||||
)
|
||||
} // onPageCreated
|
||||
}
|
||||
|
||||
const defaultExport = opts => new Plugin(opts)
|
||||
module.exports = defaultExport
|
||||
69
node_modules/puppeteer-extra-plugin-stealth/evasions/navigator.vendor/index.test.js
generated
vendored
Normal file
69
node_modules/puppeteer-extra-plugin-stealth/evasions/navigator.vendor/index.test.js
generated
vendored
Normal file
@@ -0,0 +1,69 @@
|
||||
const test = require('ava')
|
||||
|
||||
const { vanillaPuppeteer, addExtra } = require('../../test/util')
|
||||
const Plugin = require('.')
|
||||
|
||||
test('vanilla: navigator.vendor is always Google Inc.', async t => {
|
||||
const browser = await vanillaPuppeteer.launch({ headless: true })
|
||||
const page = await browser.newPage()
|
||||
|
||||
const vendor = await page.evaluate(() => navigator.vendor)
|
||||
t.is(vendor, 'Google Inc.')
|
||||
})
|
||||
|
||||
test('stealth: navigator.vendor set to custom value', async t => {
|
||||
const puppeteer = addExtra(vanillaPuppeteer).use(
|
||||
Plugin({ vendor: 'Apple Computer, Inc.' })
|
||||
)
|
||||
const browser = await puppeteer.launch({ headless: true })
|
||||
const page = await browser.newPage()
|
||||
|
||||
const vendor = await page.evaluate(() => navigator.vendor)
|
||||
t.is(vendor, 'Apple Computer, Inc.')
|
||||
})
|
||||
|
||||
test('stealth: will not leak modifications', async t => {
|
||||
const puppeteer = addExtra(vanillaPuppeteer).use(Plugin())
|
||||
const browser = await puppeteer.launch({ headless: true })
|
||||
const page = await browser.newPage()
|
||||
|
||||
const test1 = await page.evaluate(
|
||||
() => Object.getOwnPropertyDescriptor(navigator, 'vendor') // Must be undefined if native
|
||||
)
|
||||
t.is(test1, undefined)
|
||||
|
||||
const test2 = await page.evaluate(
|
||||
() => Object.getOwnPropertyNames(navigator) // Must be an empty array if native
|
||||
)
|
||||
t.false(test2.includes('vendor'))
|
||||
})
|
||||
|
||||
test('stealth: does patch getters properly', async t => {
|
||||
const puppeteer = addExtra(vanillaPuppeteer).use(Plugin())
|
||||
const browser = await puppeteer.launch({ headless: true })
|
||||
const page = await browser.newPage()
|
||||
|
||||
const results = await page.evaluate(() => {
|
||||
const hasInvocationError = (() => {
|
||||
try {
|
||||
// eslint-disable-next-line dot-notation
|
||||
Object['seal'](Object.getPrototypeOf(navigator)['vendor'])
|
||||
return false
|
||||
} catch (err) {
|
||||
return true
|
||||
}
|
||||
})()
|
||||
return {
|
||||
hasInvocationError,
|
||||
toString: Object.getOwnPropertyDescriptor(
|
||||
Object.getPrototypeOf(navigator),
|
||||
'vendor'
|
||||
).get.toString()
|
||||
}
|
||||
})
|
||||
|
||||
t.deepEqual(results, {
|
||||
hasInvocationError: true,
|
||||
toString: 'function get vendor() { [native code] }'
|
||||
})
|
||||
})
|
||||
4
node_modules/puppeteer-extra-plugin-stealth/evasions/navigator.vendor/package.json
generated
vendored
Normal file
4
node_modules/puppeteer-extra-plugin-stealth/evasions/navigator.vendor/package.json
generated
vendored
Normal file
@@ -0,0 +1,4 @@
|
||||
{
|
||||
"private": true,
|
||||
"main": "index.js"
|
||||
}
|
||||
37
node_modules/puppeteer-extra-plugin-stealth/evasions/navigator.vendor/readme.md
generated
vendored
Normal file
37
node_modules/puppeteer-extra-plugin-stealth/evasions/navigator.vendor/readme.md
generated
vendored
Normal file
@@ -0,0 +1,37 @@
|
||||
## API
|
||||
|
||||
<!-- Generated by documentation.js. Update this documentation by updating the source code. -->
|
||||
|
||||
#### Table of Contents
|
||||
|
||||
- [class: Plugin](#class-plugin)
|
||||
|
||||
### class: [Plugin](https://github.com/berstend/puppeteer-extra/blob/e6133619b051febed630ada35241664eba59b9fa/packages/puppeteer-extra-plugin-stealth/evasions/navigator.vendor/index.js#L28-L55)
|
||||
|
||||
- `opts` **[Object](https://developer.mozilla.org/docs/Web/JavaScript/Reference/Global_Objects/Object)?** Options (optional, default `{}`)
|
||||
- `opts.vendor` **[string](https://developer.mozilla.org/docs/Web/JavaScript/Reference/Global_Objects/String)?** The vendor to use in `navigator.vendor` (default: `Google Inc.`)
|
||||
|
||||
**Extends: PuppeteerExtraPlugin**
|
||||
|
||||
By default puppeteer will have a fixed `navigator.vendor` property.
|
||||
|
||||
This plugin makes it possible to change this property.
|
||||
|
||||
Example:
|
||||
|
||||
```javascript
|
||||
const puppeteer = require('puppeteer-extra')
|
||||
|
||||
const StealthPlugin = require('puppeteer-extra-plugin-stealth')
|
||||
const stealth = StealthPlugin()
|
||||
// Remove this specific stealth plugin from the default set
|
||||
stealth.enabledEvasions.delete('navigator.vendor')
|
||||
puppeteer.use(stealth)
|
||||
|
||||
// Stealth plugins are just regular `puppeteer-extra` plugins and can be added as such
|
||||
const NavigatorVendorPlugin = require('puppeteer-extra-plugin-stealth/evasions/navigator.vendor')
|
||||
const nvp = NavigatorVendorPlugin({ vendor: 'Apple Computer, Inc.' }) // Custom vendor
|
||||
puppeteer.use(nvp)
|
||||
```
|
||||
|
||||
---
|
||||
Reference in New Issue
Block a user