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,70 @@
'use strict'
const { PuppeteerExtraPlugin } = require('puppeteer-extra-plugin')
const withUtils = require('../_utils/withUtils')
/**
* Fix `Notification.permission` behaving weirdly in headless mode
*
* @see https://bugs.chromium.org/p/chromium/issues/detail?id=1052332
*/
class Plugin extends PuppeteerExtraPlugin {
constructor(opts = {}) {
super(opts)
}
get name() {
return 'stealth/evasions/navigator.permissions'
}
/* global Notification Permissions PermissionStatus */
async onPageCreated(page) {
await withUtils(page).evaluateOnNewDocument((utils, opts) => {
const isSecure = document.location.protocol.startsWith('https')
// In headful on secure origins the permission should be "default", not "denied"
if (isSecure) {
utils.replaceGetterWithProxy(Notification, 'permission', {
apply() {
return 'default'
}
})
}
// Another weird behavior:
// On insecure origins in headful the state is "denied",
// whereas in headless it's "prompt"
if (!isSecure) {
const handler = {
apply(target, ctx, args) {
const param = (args || [])[0]
const isNotifications =
param && param.name && param.name === 'notifications'
if (!isNotifications) {
return utils.cache.Reflect.apply(...arguments)
}
return Promise.resolve(
Object.setPrototypeOf(
{
state: 'denied',
onchange: null
},
PermissionStatus.prototype
)
)
}
}
// Note: Don't use `Object.getPrototypeOf` here
utils.replaceWithProxy(Permissions.prototype, 'query', handler)
}
}, this.opts)
}
}
module.exports = function (pluginConfig) {
return new Plugin(pluginConfig)
}

View File

@@ -0,0 +1,105 @@
/* global Notification */
const test = require('ava')
const {
getVanillaFingerPrint,
getStealthFingerPrint
} = require('../../test/util')
const { vanillaPuppeteer, addExtra } = require('../../test/util')
const Plugin = require('.')
test('vanilla: is prompt', async t => {
const { permissions } = await getVanillaFingerPrint()
t.deepEqual(permissions, {
permission: 'denied',
state: 'prompt' // this is WRONG behavior, it's "denied" in headful!
})
})
test('stealth: is denied', async t => {
const { permissions } = await getStealthFingerPrint(Plugin)
t.deepEqual(permissions, {
permission: 'denied',
state: 'denied' // this is FIXED behavior, it's "denied" in headful!
})
})
async function getNotificationPermission() {
const { state, onchange } = await navigator.permissions.query({
name: 'notifications'
})
return {
state,
onchange,
permission: Notification.permission
}
}
test('vanilla headful: as expected', async t => {
const puppeteer = addExtra(vanillaPuppeteer)
const browser = await puppeteer.launch({ headless: false })
const page = await browser.newPage()
const result = await page.evaluate(getNotificationPermission)
t.deepEqual(result, {
state: 'denied',
onchange: null,
permission: 'denied'
})
await page.goto('https://example.com', {
waitUntil: 'domcontentloaded'
})
const result2 = await page.evaluate(getNotificationPermission)
t.deepEqual(result2, {
state: 'prompt',
onchange: null,
permission: 'default'
})
})
test('vanilla headless: as expected', async t => {
const puppeteer = addExtra(vanillaPuppeteer)
const browser = await puppeteer.launch({ headless: true })
const page = await browser.newPage()
const result = await page.evaluate(getNotificationPermission)
t.deepEqual(result, {
state: 'prompt', // should be denied
onchange: null,
permission: 'denied'
})
await page.goto('https://example.com', {
waitUntil: 'domcontentloaded'
})
const result2 = await page.evaluate(getNotificationPermission)
t.deepEqual(result2, {
state: 'prompt',
onchange: null,
permission: 'denied' // should be default
})
})
test('stealth headless: as vanilla headful', async t => {
const puppeteer = addExtra(vanillaPuppeteer).use(Plugin())
const browser = await puppeteer.launch({ headless: true })
const page = await browser.newPage()
const result = await page.evaluate(getNotificationPermission)
t.deepEqual(result, {
state: 'denied',
onchange: null,
permission: 'denied'
})
await page.goto('https://example.com', {
waitUntil: 'domcontentloaded'
})
const result2 = await page.evaluate(getNotificationPermission)
t.deepEqual(result2, {
state: 'prompt',
onchange: null,
permission: 'default'
})
})

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/navigator.permissions/index.js#L12-L45)
- `opts` (optional, default `{}`)
**Extends: PuppeteerExtraPlugin**
Pass the Permissions Test.
---