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,91 @@
'use strict'
const { PuppeteerExtraPlugin } = require('puppeteer-extra-plugin')
const withUtils = require('../_utils/withUtils')
/**
* Fix Chromium not reporting "probably" to codecs like `videoEl.canPlayType('video/mp4; codecs="avc1.42E01E"')`.
* (Chromium doesn't support proprietary codecs, only Chrome does)
*/
class Plugin extends PuppeteerExtraPlugin {
constructor(opts = {}) {
super(opts)
}
get name() {
return 'stealth/evasions/media.codecs'
}
async onPageCreated(page) {
await withUtils(page).evaluateOnNewDocument(utils => {
/**
* Input might look funky, we need to normalize it so e.g. whitespace isn't an issue for our spoofing.
*
* @example
* video/webm; codecs="vp8, vorbis"
* video/mp4; codecs="avc1.42E01E"
* audio/x-m4a;
* audio/ogg; codecs="vorbis"
* @param {String} arg
*/
const parseInput = arg => {
const [mime, codecStr] = arg.trim().split(';')
let codecs = []
if (codecStr && codecStr.includes('codecs="')) {
codecs = codecStr
.trim()
.replace(`codecs="`, '')
.replace(`"`, '')
.trim()
.split(',')
.filter(x => !!x)
.map(x => x.trim())
}
return {
mime,
codecStr,
codecs
}
}
const canPlayType = {
// Intercept certain requests
apply: function(target, ctx, args) {
if (!args || !args.length) {
return target.apply(ctx, args)
}
const { mime, codecs } = parseInput(args[0])
// This specific mp4 codec is missing in Chromium
if (mime === 'video/mp4') {
if (codecs.includes('avc1.42E01E')) {
return 'probably'
}
}
// This mimetype is only supported if no codecs are specified
if (mime === 'audio/x-m4a' && !codecs.length) {
return 'maybe'
}
// This mimetype is only supported if no codecs are specified
if (mime === 'audio/aac' && !codecs.length) {
return 'probably'
}
// Everything else as usual
return target.apply(ctx, args)
}
}
/* global HTMLMediaElement */
utils.replaceWithProxy(
HTMLMediaElement.prototype,
'canPlayType',
canPlayType
)
})
}
}
module.exports = function(pluginConfig) {
return new Plugin(pluginConfig)
}

View File

@@ -0,0 +1,104 @@
const test = require('ava')
const {
getVanillaFingerPrint,
getStealthFingerPrint
} = require('../../test/util')
const { vanillaPuppeteer, addExtra } = require('../../test/util')
const Plugin = require('.')
test('vanilla: doesnt support proprietary codecs', async t => {
const { videoCodecs, audioCodecs } = await getVanillaFingerPrint()
t.deepEqual(videoCodecs, { ogg: 'probably', h264: '', webm: 'probably' })
t.deepEqual(audioCodecs, {
ogg: 'probably',
mp3: 'probably',
wav: 'probably',
m4a: '',
aac: ''
})
})
test('vanilla: will not have modifications', async t => {
const browser = await vanillaPuppeteer.launch({ headless: true })
const page = await browser.newPage()
// https://datadome.co/bot-detection/client-side-detection-is-essential-for-bot-protection/
const test1 = await page.evaluate(() => {
const audioElt = document.createElement('audio')
return audioElt.canPlayType.toString()
})
t.is(test1, 'function canPlayType() { [native code] }')
const test2 = await page.evaluate(() => {
const audioElt = document.createElement('audio')
return audioElt.canPlayType.name
})
t.is(test2, 'canPlayType')
})
test('stealth: supports proprietary codecs', async t => {
const { videoCodecs, audioCodecs } = await getStealthFingerPrint(Plugin)
t.deepEqual(videoCodecs, {
ogg: 'probably',
h264: 'probably',
webm: 'probably'
})
t.deepEqual(audioCodecs, {
ogg: 'probably',
mp3: 'probably',
wav: 'probably',
m4a: 'maybe',
aac: 'probably'
})
})
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()
// https://datadome.co/bot-detection/client-side-detection-is-essential-for-bot-protection/
const test1 = await page.evaluate(() => {
const audioElt = document.createElement('audio')
return audioElt.canPlayType.toString()
})
t.is(test1, 'function canPlayType() { [native code] }')
const test2 = await page.evaluate(() => {
const audioElt = document.createElement('audio')
return audioElt.canPlayType.name
})
t.is(test2, 'canPlayType')
// Double check the plugin is active and spoofing e.g. the aac codec results
const isWorkingTest = await page.evaluate(() => {
const audioElt = document.createElement('audio')
return audioElt.canPlayType('audio/aac') === 'probably' // empty in Chromium without stealth plugin
})
t.true(isWorkingTest)
})
test('vanilla: normal toString stuff', async t => {
const browser = await vanillaPuppeteer.launch({ headless: true })
const page = await browser.newPage()
const test1 = await page.evaluate(() => {
const audioElt = document.createElement('audio')
return audioElt.canPlayType.toString + ''
})
t.is(test1, 'function toString() { [native code] }')
})
test('stealth: will not leak toString stuff', 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(() => {
const audioElt = document.createElement('audio')
return audioElt.canPlayType.toString + ''
})
t.is(test1, 'function toString() { [native code] }') // returns function () { [native code] }
})

View File

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

View File

@@ -0,0 +1,39 @@
## API
<!-- Generated by documentation.js. Update this documentation by updating the source code. -->
#### Table of Contents
- [class: Plugin](#class-plugin)
- [parseInput(arg)](#parseinputarg)
### class: [Plugin](https://github.com/berstend/puppeteer-extra/blob/e6133619b051febed630ada35241664eba59b9fa/packages/puppeteer-extra-plugin-stealth/evasions/media.codecs/index.js#L12-L88)
- `opts` (optional, default `{}`)
**Extends: PuppeteerExtraPlugin**
Fix Chromium not reporting "probably" to codecs like `videoEl.canPlayType('video/mp4; codecs="avc1.42E01E"')`.
(Chromium doesn't support proprietary codecs, only Chrome does)
---
### [parseInput(arg)](https://github.com/berstend/puppeteer-extra/blob/e6133619b051febed630ada35241664eba59b9fa/packages/puppeteer-extra-plugin-stealth/evasions/media.codecs/index.js#L33-L51)
- `arg` **[String](https://developer.mozilla.org/docs/Web/JavaScript/Reference/Global_Objects/String)**
Input might look funky, we need to normalize it so e.g. whitespace isn't an issue for our spoofing.
Example:
```javascript
video / webm
codecs = 'vp8, vorbis'
video / mp4
codecs = 'avc1.42E01E'
audio / x - m4a
audio / ogg
codecs = 'vorbis'
```
---