@skrillex1224/playwright-toolkit 2.1.138 → 2.1.139
This diff represents the content of publicly available package versions that have been released to one of the supported registries. The information contained in this diff is provided for informational purposes only and reflects changes between package versions as they appear in their respective public registries.
- package/README.md +1 -1
- package/dist/index.cjs +76 -2
- package/dist/index.cjs.map +2 -2
- package/dist/index.js +78 -4
- package/dist/index.js.map +3 -3
- package/index.d.ts +27 -1
- package/package.json +1 -1
package/README.md
CHANGED
|
@@ -85,7 +85,7 @@ await Actor.exit();
|
|
|
85
85
|
| 模块 | 方法 | 说明 |
|
|
86
86
|
| ----------- | ------------------------------------------- | -------------------------------------- |
|
|
87
87
|
| `Launch` | `getAdvancedLaunchOptions()` | 增强版启动参数 |
|
|
88
|
-
| `Launch` | `getLaunchOptions()`
|
|
88
|
+
| `Launch` | `getLaunchOptions({ proxyConfiguration, log? })` | 基础启动参数(统一代理解析,可选 bypass 日志) |
|
|
89
89
|
| `Launch` | `getFingerprintGeneratorOptions()` | 指纹生成器选项 |
|
|
90
90
|
| `AntiCheat` | `applyPage(page, options?)` | 应用时区/语言/权限/视口 |
|
|
91
91
|
| `AntiCheat` | `applyContext(context, options?)` | 仅应用 Context 设置 |
|
package/dist/index.cjs
CHANGED
|
@@ -1260,15 +1260,89 @@ var Humanize = {
|
|
|
1260
1260
|
};
|
|
1261
1261
|
|
|
1262
1262
|
// src/launch.js
|
|
1263
|
+
var normalizeByPassDomains = (domains) => {
|
|
1264
|
+
if (!Array.isArray(domains)) return [];
|
|
1265
|
+
return domains.map((item) => String(item || "").trim()).filter(Boolean);
|
|
1266
|
+
};
|
|
1267
|
+
var resolveProxyLaunchOptions = (proxyConfiguration = {}) => {
|
|
1268
|
+
const config = proxyConfiguration && typeof proxyConfiguration === "object" && !Array.isArray(proxyConfiguration) ? proxyConfiguration : {};
|
|
1269
|
+
const proxyUrl = String(config.proxy_url || "").trim();
|
|
1270
|
+
const enableProxy = typeof config.enable_proxy === "boolean" ? config.enable_proxy : proxyUrl !== "";
|
|
1271
|
+
if (!enableProxy || !proxyUrl) {
|
|
1272
|
+
return { launchProxy: null, byPassDomains: [], enableProxy, proxyUrl };
|
|
1273
|
+
}
|
|
1274
|
+
const byPassDomains = normalizeByPassDomains(config.by_pass_domains);
|
|
1275
|
+
let parsedProxyUrl;
|
|
1276
|
+
parsedProxyUrl = new URL(proxyUrl);
|
|
1277
|
+
const launchProxy = {
|
|
1278
|
+
server: `${parsedProxyUrl.protocol}//${parsedProxyUrl.host}`
|
|
1279
|
+
};
|
|
1280
|
+
if (parsedProxyUrl.username) {
|
|
1281
|
+
launchProxy.username = decodeURIComponent(parsedProxyUrl.username);
|
|
1282
|
+
}
|
|
1283
|
+
if (parsedProxyUrl.password) {
|
|
1284
|
+
launchProxy.password = decodeURIComponent(parsedProxyUrl.password);
|
|
1285
|
+
}
|
|
1286
|
+
if (byPassDomains.length > 0) {
|
|
1287
|
+
launchProxy.bypass = byPassDomains.join(",");
|
|
1288
|
+
}
|
|
1289
|
+
return { launchProxy, byPassDomains, enableProxy, proxyUrl };
|
|
1290
|
+
};
|
|
1263
1291
|
var Launch = {
|
|
1264
|
-
getLaunchOptions(
|
|
1265
|
-
|
|
1292
|
+
getLaunchOptions(options = {}) {
|
|
1293
|
+
const normalizedOptions = Array.isArray(options) ? { customArgs: options } : options || {};
|
|
1294
|
+
const {
|
|
1295
|
+
customArgs = [],
|
|
1296
|
+
proxyConfiguration = {},
|
|
1297
|
+
log: logOptions = null
|
|
1298
|
+
} = normalizedOptions;
|
|
1299
|
+
const { launchProxy, byPassDomains, enableProxy, proxyUrl } = resolveProxyLaunchOptions(proxyConfiguration);
|
|
1300
|
+
const launchOptions = {
|
|
1266
1301
|
args: [
|
|
1267
1302
|
...AntiCheat.getLaunchArgs(),
|
|
1268
1303
|
...customArgs
|
|
1269
1304
|
],
|
|
1270
1305
|
ignoreDefaultArgs: ["--enable-automation"]
|
|
1271
1306
|
};
|
|
1307
|
+
if (launchProxy) {
|
|
1308
|
+
launchOptions.proxy = launchProxy;
|
|
1309
|
+
}
|
|
1310
|
+
const enableByPassLogger = Boolean(logOptions && logOptions.enable);
|
|
1311
|
+
const customLogger = logOptions && typeof logOptions.customLogger === "function" ? logOptions.customLogger : console.log;
|
|
1312
|
+
if (enableByPassLogger && launchProxy) {
|
|
1313
|
+
customLogger(
|
|
1314
|
+
`[\u4EE3\u7406\u5DF2\u542F\u7528] \u4EE3\u7406\u670D\u52A1=${launchProxy.server} \u76F4\u8FDE\u57DF\u540D=${(byPassDomains || []).join(",")}`
|
|
1315
|
+
);
|
|
1316
|
+
} else if (enableByPassLogger && enableProxy && !launchProxy) {
|
|
1317
|
+
customLogger(
|
|
1318
|
+
`[\u4EE3\u7406\u672A\u542F\u7528] enable_proxy=true \u4F46 proxy_url \u4E3A\u7A7A`
|
|
1319
|
+
);
|
|
1320
|
+
} else if (enableByPassLogger && !enableProxy && proxyUrl) {
|
|
1321
|
+
customLogger(
|
|
1322
|
+
`[\u4EE3\u7406\u672A\u542F\u7528] enable_proxy=false \u4E14 proxy_url \u5DF2\u914D\u7F6E`
|
|
1323
|
+
);
|
|
1324
|
+
}
|
|
1325
|
+
const onPageCreated = (page) => {
|
|
1326
|
+
if (!enableByPassLogger || byPassDomains.length === 0 || !page || typeof page.on !== "function") {
|
|
1327
|
+
return () => {
|
|
1328
|
+
};
|
|
1329
|
+
}
|
|
1330
|
+
const domainSet = new Set(byPassDomains.map((domain) => domain.toLowerCase()));
|
|
1331
|
+
const requestHandler = (req) => {
|
|
1332
|
+
const requestUrl = req.url();
|
|
1333
|
+
let hostname = "";
|
|
1334
|
+
try {
|
|
1335
|
+
hostname = new URL(requestUrl).hostname.toLowerCase();
|
|
1336
|
+
} catch {
|
|
1337
|
+
return;
|
|
1338
|
+
}
|
|
1339
|
+
if (!domainSet.has(hostname)) return;
|
|
1340
|
+
customLogger(`[\u76F4\u8FDE\u547D\u4E2D] \u57DF\u540D=${hostname} \u8D44\u6E90\u7C7B\u578B=${req.resourceType()} \u65B9\u6CD5=${req.method()} \u5730\u5740=${requestUrl}`);
|
|
1341
|
+
};
|
|
1342
|
+
page.on("request", requestHandler);
|
|
1343
|
+
return () => page.off("request", requestHandler);
|
|
1344
|
+
};
|
|
1345
|
+
return { launchOptions, onPageCreated };
|
|
1272
1346
|
},
|
|
1273
1347
|
/**
|
|
1274
1348
|
* 推荐的 Fingerprint Generator 选项
|