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,73 @@
'use strict'
const { PuppeteerExtraPlugin } = require('puppeteer-extra-plugin')
const withUtils = require('../_utils/withUtils')
/**
* Mock the `chrome.csi` function if not available (e.g. when running headless).
* It's a deprecated (but unfortunately still existing) chrome specific API to fetch browser timings.
*
* Internally chromium switched the implementation to use the WebPerformance API,
* so we can do the same to create a fully functional mock. :-)
*
* Note: We're using the deprecated PerformanceTiming API instead of the new Navigation Timing Level 2 API on purpopse.
*
* @see https://bugs.chromium.org/p/chromium/issues/detail?id=113048
* @see https://codereview.chromium.org/2456293003/
* @see https://developers.google.com/web/updates/2017/12/chrome-loadtimes-deprecated
* @see https://developer.mozilla.org/en-US/docs/Web/API/PerformanceTiming
* @see https://source.chromium.org/chromium/chromium/src/+/master:chrome/renderer/loadtimes_extension_bindings.cc;l=124?q=loadtimes&ss=chromium
* @see `chrome.loadTimes` evasion
*
*/
class Plugin extends PuppeteerExtraPlugin {
constructor(opts = {}) {
super(opts)
}
get name() {
return 'stealth/evasions/chrome.csi'
}
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 ('csi' in window.chrome) {
return // Nothing to do here
}
// Check that the Navigation Timing API v1 is available, we need that
if (!window.performance || !window.performance.timing) {
return
}
const { timing } = window.performance
window.chrome.csi = function() {
return {
onloadT: timing.domContentLoadedEventEnd,
startE: timing.navigationStart,
pageT: Date.now() - timing.navigationStart,
tran: 15 // Transition type or something
}
}
utils.patchToString(window.chrome.csi)
})
}
}
module.exports = function(pluginConfig) {
return new Plugin(pluginConfig)
}

View File

@@ -0,0 +1,48 @@
const test = require('ava')
const { vanillaPuppeteer, addExtra } = require('../../test/util')
const Plugin = require('.')
/* global chrome */
test('stealth: will add functional chrome.csi function mock', async t => {
const puppeteer = addExtra(vanillaPuppeteer).use(
Plugin({
runOnInsecureOrigins: true // for testing
})
)
const browser = await puppeteer.launch({ headless: true })
const page = await browser.newPage()
const results = await page.evaluate(() => {
const { timing } = window.performance
const csi = window.chrome.csi()
return {
csi: {
exists: window.chrome && 'csi' in window.chrome,
toString: chrome.csi.toString()
},
dataOK: {
onloadT: csi.onloadT === timing.domContentLoadedEventEnd,
startE: csi.startE === timing.navigationStart,
pageT: Number.isInteger(csi.pageT),
tran: Number.isInteger(csi.tran)
}
}
})
t.deepEqual(results, {
csi: {
exists: true,
toString: 'function () { [native code] }'
},
dataOK: {
onloadT: true,
pageT: true,
startE: true,
tran: true
}
})
})

View File

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

View File

@@ -0,0 +1,30 @@
## 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.csi/index.js#L25-L70)
- `opts` (optional, default `{}`)
**Extends: PuppeteerExtraPlugin**
Mock the `chrome.csi` function if not available (e.g. when running headless).
It's a deprecated (but unfortunately still existing) chrome specific API to fetch browser timings.
Internally chromium switched the implementation to use the WebPerformance API,
so we can do the same to create a fully functional mock. :-)
Note: We're using the deprecated PerformanceTiming API instead of the new Navigation Timing Level 2 API on purpopse.
- **See: <https://bugs.chromium.org/p/chromium/issues/detail?id=113048>**
- **See: <https://codereview.chromium.org/2456293003/>**
- **See: <https://developers.google.com/web/updates/2017/12/chrome-loadtimes-deprecated>**
- **See: <https://developer.mozilla.org/en-US/docs/Web/API/PerformanceTiming>**
- **See: <https://source.chromium.org/chromium/chromium/src/+/master:chrome/renderer/loadtimes_extension_bindings.cc;l=124?q=loadtimes&ss=chromium>**
- **See: `chrome.loadTimes` evasion**
---