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,100 @@
'use strict'
const { PuppeteerExtraPlugin } = require('puppeteer-extra-plugin')
const withUtils = require('../_utils/withUtils')
/**
* Mock the `chrome.app` object if not available (e.g. when running headless).
*/
class Plugin extends PuppeteerExtraPlugin {
constructor(opts = {}) {
super(opts)
}
get name() {
return 'stealth/evasions/chrome.app'
}
async onPageCreated(page) {
await withUtils(page).evaluateOnNewDocument(utils => {
if (!window.chrome) {
// Use the exact property descriptor found in headful Chrome
// fetch it via `Object.getOwnPropertyDescriptor(window, 'chrome')`
Object.defineProperty(window, 'chrome', {
writable: true,
enumerable: true,
configurable: false, // note!
value: {} // We'll extend that later
})
}
// That means we're running headful and don't need to mock anything
if ('app' in window.chrome) {
return // Nothing to do here
}
const makeError = {
ErrorInInvocation: fn => {
const err = new TypeError(`Error in invocation of app.${fn}()`)
return utils.stripErrorWithAnchor(
err,
`at ${fn} (eval at <anonymous>`
)
}
}
// There's a some static data in that property which doesn't seem to change,
// we should periodically check for updates: `JSON.stringify(window.app, null, 2)`
const STATIC_DATA = JSON.parse(
`
{
"isInstalled": false,
"InstallState": {
"DISABLED": "disabled",
"INSTALLED": "installed",
"NOT_INSTALLED": "not_installed"
},
"RunningState": {
"CANNOT_RUN": "cannot_run",
"READY_TO_RUN": "ready_to_run",
"RUNNING": "running"
}
}
`.trim()
)
window.chrome.app = {
...STATIC_DATA,
get isInstalled() {
return false
},
getDetails: function getDetails() {
if (arguments.length) {
throw makeError.ErrorInInvocation(`getDetails`)
}
return null
},
getIsInstalled: function getDetails() {
if (arguments.length) {
throw makeError.ErrorInInvocation(`getIsInstalled`)
}
return false
},
runningState: function getDetails() {
if (arguments.length) {
throw makeError.ErrorInInvocation(`runningState`)
}
return 'cannot_run'
}
}
utils.patchToStringNested(window.chrome.app)
})
}
}
module.exports = function(pluginConfig) {
return new Plugin(pluginConfig)
}

View File

@@ -0,0 +1,71 @@
const test = require('ava')
const { vanillaPuppeteer, addExtra } = require('../../test/util')
const Plugin = require('.')
/* global chrome */
test('stealth: will add convincing chrome.app object', 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 catchErr = (fn, ...args) => {
try {
return fn.apply(this, args)
} catch ({ name, message, stack }) {
return { name, message, stack }
}
}
return {
app: {
exists: window.chrome && 'app' in window.chrome,
toString: chrome.app.toString(),
deepToString: chrome.app.runningState.toString()
},
data: {
getIsInstalled: chrome.app.getIsInstalled(),
runningState: chrome.app.runningState(),
getDetails: chrome.app.getDetails(),
InstallState: chrome.app.InstallState,
RunningState: chrome.app.RunningState
},
errors: {
getIsInstalled: catchErr(chrome.app.getDetails, 'foo').message,
stackOK: !catchErr(chrome.app.getDetails, 'foo').stack.includes(
'at getDetails'
)
}
}
})
t.deepEqual(results, {
app: {
exists: true,
toString: '[object Object]',
deepToString: 'function getDetails() { [native code] }'
},
data: {
InstallState: {
DISABLED: 'disabled',
INSTALLED: 'installed',
NOT_INSTALLED: 'not_installed'
},
RunningState: {
CANNOT_RUN: 'cannot_run',
READY_TO_RUN: 'ready_to_run',
RUNNING: 'running'
},
getDetails: null,
getIsInstalled: false,
runningState: 'cannot_run'
},
errors: {
getIsInstalled: 'Error in invocation of app.getDetails()',
stackOK: true
}
})
})

View File

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

View File

@@ -0,0 +1,17 @@
## 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/chrome.app/index.js#L11-L97)
- `opts` (optional, default `{}`)
**Extends: PuppeteerExtraPlugin**
Mock the `chrome.app` object if not available (e.g. when running headless).
---