Rename to hkt.sh

This commit is contained in:
mango
2026-03-21 01:10:53 +08:00
parent 76a263d0f9
commit 8f1171fe99
6676 changed files with 1724268 additions and 0 deletions

View File

@@ -0,0 +1,49 @@
'use strict'
const { PuppeteerExtraPlugin } = require('puppeteer-extra-plugin')
const withUtils = require('../_utils/withUtils')
/**
* Set the hardwareConcurrency to 4 (optionally configurable with `hardwareConcurrency`)
*
* @see https://arh.antoinevastel.com/reports/stats/osName_hardwareConcurrency_report.html
*
* @param {Object} [opts] - Options
* @param {number} [opts.hardwareConcurrency] - The value to use in `navigator.hardwareConcurrency` (default: `4`)
*/
class Plugin extends PuppeteerExtraPlugin {
constructor(opts = {}) {
super(opts)
}
get name() {
return 'stealth/evasions/navigator.hardwareConcurrency'
}
get defaults() {
return {
hardwareConcurrency: 4
}
}
async onPageCreated(page) {
await withUtils(page).evaluateOnNewDocument(
(utils, { opts }) => {
utils.replaceGetterWithProxy(
Object.getPrototypeOf(navigator),
'hardwareConcurrency',
utils.makeHandler().getterValue(opts.hardwareConcurrency)
)
},
{
opts: this.opts
}
)
}
}
module.exports = function (pluginConfig) {
return new Plugin(pluginConfig)
}

View File

@@ -0,0 +1,59 @@
const test = require('ava')
const os = require('os')
const { vanillaPuppeteer, addExtra } = require('../../test/util')
const {
getVanillaFingerPrint,
getStealthFingerPrint
} = require('../../test/util')
const Plugin = require('.')
const fingerprintFn = page => page.evaluate('navigator.hardwareConcurrency')
test('vanilla: matches real core count', async t => {
const { pageFnResult } = await getVanillaFingerPrint(fingerprintFn)
t.is(pageFnResult, os.cpus().length)
})
test('stealth: default is set to 4', async t => {
const { pageFnResult } = await getStealthFingerPrint(Plugin, fingerprintFn)
t.is(pageFnResult, 4)
})
test('stealth: will override value correctly', async t => {
const { pageFnResult } = await getStealthFingerPrint(Plugin, fingerprintFn, {
hardwareConcurrency: 8
})
t.is(pageFnResult, 8)
})
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)['hardwareConcurrency'])
return false
} catch (err) {
return true
}
})()
return {
hasInvocationError,
toString: Object.getOwnPropertyDescriptor(
Object.getPrototypeOf(navigator),
'hardwareConcurrency'
).get.toString()
}
})
t.deepEqual(results, {
hasInvocationError: true,
toString: 'function get hardwareConcurrency() { [native code] }'
})
})

View File

@@ -0,0 +1,4 @@
{
"private": true,
"main": "index.js"
}

View File

@@ -0,0 +1,20 @@
## 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/9534845cc95088e65c2d53bfb029263976fc9add/packages/puppeteer-extra-plugin-stealth/evasions/navigator.hardwareConcurrency/index.js#L16-L37)
- `opts` **[Object](https://developer.mozilla.org/docs/Web/JavaScript/Reference/Global_Objects/Object)?** Options (optional, default `{}`)
- `opts.hardwareConcurrency` **[number](https://developer.mozilla.org/docs/Web/JavaScript/Reference/Global_Objects/Number)?** The value to use in `navigator.hardwareConcurrency` (default: `4`)
**Extends: PuppeteerExtraPlugin**
Set the hardwareConcurrency to 4 (optionally configurable with `hardwareConcurrency`)
- **See: <https://arh.antoinevastel.com/reports/stats/osName_hardwareConcurrency_report.html>**
---