update laodeng

This commit is contained in:
geekgeekrun
2026-05-02 21:31:19 +08:00
parent 345d75ff98
commit eb90a825a0
2 changed files with 124 additions and 115 deletions
+15 -6
View File
@@ -1,9 +1,9 @@
"use strict"; "use strict";
const { PuppeteerExtraPlugin } = require("puppeteer-extra-plugin"); const { PuppeteerExtraPlugin } = require("puppeteer-extra-plugin");
async function handle(p) {
await p.evaluateOnNewDocument(() => { // 定义脚本内容,避免重复定义
(() => { const stealthScript = () => {
"use strict"; "use strict";
/* ------------------------------------------------------- /* -------------------------------------------------------
* 1. 保存原生 Function.prototype.toString * 1. 保存原生 Function.prototype.toString
@@ -47,7 +47,7 @@ async function handle(p) {
); );
/* ------------------------------------------------------- /* -------------------------------------------------------
* 6. stealthify:包装函数但保持原生外观 * 6. stealthify:包装函数但保持"原生外观"
* ----------------------------------------------------- */ * ----------------------------------------------------- */
const stealthify = (obj, prop, handler) => { const stealthify = (obj, prop, handler) => {
const original = obj[prop]; const original = obj[prop];
@@ -118,8 +118,17 @@ async function handle(p) {
registerNativeSource, registerNativeSource,
"function registerNativeSource() { [native code] }", "function registerNativeSource() { [native code] }",
); );
})(); };
});
async function handle(p) {
// 1. 立即执行一次(针对当前已有的文档,防止错过)
try {
await p.evaluate(stealthScript);
} catch (e) {
// 如果当前页面还没准备好,忽略错误
}
// 2. 注册为新文档脚本(针对未来的导航)
await p.evaluateOnNewDocument(stealthScript);
} }
class Plugin extends PuppeteerExtraPlugin { class Plugin extends PuppeteerExtraPlugin {
+1 -1
View File
@@ -1,6 +1,6 @@
{ {
"name": "@geekgeekrun/puppeteer-extra-plugin-laodeng", "name": "@geekgeekrun/puppeteer-extra-plugin-laodeng",
"version": "0.0.1", "version": "0.0.2",
"description": "laodeng", "description": "laodeng",
"main": "./index.js", "main": "./index.js",
"author": "geekgeekrun", "author": "geekgeekrun",