@skrillex1224/playwright-toolkit 2.1.139 → 2.1.140
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/dist/index.cjs +77 -77
- package/dist/index.cjs.map +3 -3
- package/dist/index.js +77 -77
- package/dist/index.js.map +3 -3
- package/index.d.ts +0 -1
- package/package.json +1 -1
package/dist/index.js
CHANGED
|
@@ -269,18 +269,18 @@ var fallbackLog = {
|
|
|
269
269
|
error: (...args) => console.error(...args),
|
|
270
270
|
debug: (...args) => console.debug ? console.debug(...args) : console.log(...args)
|
|
271
271
|
};
|
|
272
|
-
var resolveLogMethod = (
|
|
273
|
-
if (
|
|
274
|
-
return
|
|
272
|
+
var resolveLogMethod = (logger13, name) => {
|
|
273
|
+
if (logger13 && typeof logger13[name] === "function") {
|
|
274
|
+
return logger13[name].bind(logger13);
|
|
275
275
|
}
|
|
276
|
-
if (name === "warning" &&
|
|
277
|
-
return
|
|
276
|
+
if (name === "warning" && logger13 && typeof logger13.warn === "function") {
|
|
277
|
+
return logger13.warn.bind(logger13);
|
|
278
278
|
}
|
|
279
279
|
return fallbackLog[name];
|
|
280
280
|
};
|
|
281
281
|
var defaultLogger = null;
|
|
282
|
-
var setDefaultLogger = (
|
|
283
|
-
defaultLogger =
|
|
282
|
+
var setDefaultLogger = (logger13) => {
|
|
283
|
+
defaultLogger = logger13;
|
|
284
284
|
};
|
|
285
285
|
var resolveLogger = (explicitLogger) => {
|
|
286
286
|
if (explicitLogger && typeof explicitLogger.info === "function") {
|
|
@@ -307,8 +307,8 @@ var colorize = (text, color) => {
|
|
|
307
307
|
var createBaseLogger = (prefix = "", explicitLogger) => {
|
|
308
308
|
const name = prefix ? String(prefix) : "";
|
|
309
309
|
const dispatch = (methodName, icon, message, color) => {
|
|
310
|
-
const
|
|
311
|
-
const logFn = resolveLogMethod(
|
|
310
|
+
const logger13 = resolveLogger(explicitLogger);
|
|
311
|
+
const logFn = resolveLogMethod(logger13, methodName);
|
|
312
312
|
const timestamp = colorize(`[${formatTimestamp()}]`, ANSI.gray);
|
|
313
313
|
const line = formatLine(name, icon, message);
|
|
314
314
|
const coloredLine = colorize(line, color);
|
|
@@ -1233,6 +1233,7 @@ var Humanize = {
|
|
|
1233
1233
|
};
|
|
1234
1234
|
|
|
1235
1235
|
// src/launch.js
|
|
1236
|
+
var logger6 = createInternalLogger("Launch");
|
|
1236
1237
|
var normalizeByPassDomains = (domains) => {
|
|
1237
1238
|
if (!Array.isArray(domains)) return [];
|
|
1238
1239
|
return domains.map((item) => String(item || "").trim()).filter(Boolean);
|
|
@@ -1281,17 +1282,16 @@ var Launch = {
|
|
|
1281
1282
|
launchOptions.proxy = launchProxy;
|
|
1282
1283
|
}
|
|
1283
1284
|
const enableByPassLogger = Boolean(logOptions && logOptions.enable);
|
|
1284
|
-
const customLogger = logOptions && typeof logOptions.customLogger === "function" ? logOptions.customLogger : console.log;
|
|
1285
1285
|
if (enableByPassLogger && launchProxy) {
|
|
1286
|
-
|
|
1286
|
+
logger6.info(
|
|
1287
1287
|
`[\u4EE3\u7406\u5DF2\u542F\u7528] \u4EE3\u7406\u670D\u52A1=${launchProxy.server} \u76F4\u8FDE\u57DF\u540D=${(byPassDomains || []).join(",")}`
|
|
1288
1288
|
);
|
|
1289
1289
|
} else if (enableByPassLogger && enableProxy && !launchProxy) {
|
|
1290
|
-
|
|
1290
|
+
logger6.info(
|
|
1291
1291
|
`[\u4EE3\u7406\u672A\u542F\u7528] enable_proxy=true \u4F46 proxy_url \u4E3A\u7A7A`
|
|
1292
1292
|
);
|
|
1293
1293
|
} else if (enableByPassLogger && !enableProxy && proxyUrl) {
|
|
1294
|
-
|
|
1294
|
+
logger6.info(
|
|
1295
1295
|
`[\u4EE3\u7406\u672A\u542F\u7528] enable_proxy=false \u4E14 proxy_url \u5DF2\u914D\u7F6E`
|
|
1296
1296
|
);
|
|
1297
1297
|
}
|
|
@@ -1310,7 +1310,7 @@ var Launch = {
|
|
|
1310
1310
|
return;
|
|
1311
1311
|
}
|
|
1312
1312
|
if (!domainSet.has(hostname)) return;
|
|
1313
|
-
|
|
1313
|
+
logger6.info(`[\u76F4\u8FDE\u547D\u4E2D] \u57DF\u540D=${hostname} \u8D44\u6E90\u7C7B\u578B=${req.resourceType()} \u65B9\u6CD5=${req.method()} \u5730\u5740=${requestUrl}`);
|
|
1314
1314
|
};
|
|
1315
1315
|
page.on("request", requestHandler);
|
|
1316
1316
|
return () => page.off("request", requestHandler);
|
|
@@ -1329,7 +1329,7 @@ var Launch = {
|
|
|
1329
1329
|
// src/live-view.js
|
|
1330
1330
|
import express from "express";
|
|
1331
1331
|
import { Actor } from "apify";
|
|
1332
|
-
var
|
|
1332
|
+
var logger7 = createInternalLogger("LiveView");
|
|
1333
1333
|
async function startLiveViewServer(liveViewKey) {
|
|
1334
1334
|
const app = express();
|
|
1335
1335
|
app.get("/", async (req, res) => {
|
|
@@ -1354,13 +1354,13 @@ async function startLiveViewServer(liveViewKey) {
|
|
|
1354
1354
|
</html>
|
|
1355
1355
|
`);
|
|
1356
1356
|
} catch (error) {
|
|
1357
|
-
|
|
1357
|
+
logger7.fail("Live View Server", error);
|
|
1358
1358
|
res.status(500).send(`\u65E0\u6CD5\u52A0\u8F7D\u5C4F\u5E55\u622A\u56FE: ${error.message}`);
|
|
1359
1359
|
}
|
|
1360
1360
|
});
|
|
1361
1361
|
const port = process.env.APIFY_CONTAINER_PORT || 4321;
|
|
1362
1362
|
app.listen(port, () => {
|
|
1363
|
-
|
|
1363
|
+
logger7.success("startLiveViewServer", `\u76D1\u542C\u7AEF\u53E3 ${port}`);
|
|
1364
1364
|
});
|
|
1365
1365
|
}
|
|
1366
1366
|
async function takeLiveScreenshot(liveViewKey, page, logMessage) {
|
|
@@ -1368,10 +1368,10 @@ async function takeLiveScreenshot(liveViewKey, page, logMessage) {
|
|
|
1368
1368
|
const buffer = await page.screenshot({ type: "png" });
|
|
1369
1369
|
await Actor.setValue(liveViewKey, buffer, { contentType: "image/png" });
|
|
1370
1370
|
if (logMessage) {
|
|
1371
|
-
|
|
1371
|
+
logger7.info(`(\u622A\u56FE): ${logMessage}`);
|
|
1372
1372
|
}
|
|
1373
1373
|
} catch (e) {
|
|
1374
|
-
|
|
1374
|
+
logger7.warn(`\u65E0\u6CD5\u6355\u83B7 Live View \u5C4F\u5E55\u622A\u56FE: ${e.message}`);
|
|
1375
1375
|
}
|
|
1376
1376
|
}
|
|
1377
1377
|
var useLiveView = (liveViewKey = PresetOfLiveViewKey) => {
|
|
@@ -1390,7 +1390,7 @@ var LiveView = {
|
|
|
1390
1390
|
|
|
1391
1391
|
// src/captcha-monitor.js
|
|
1392
1392
|
import { v4 as uuidv4 } from "uuid";
|
|
1393
|
-
var
|
|
1393
|
+
var logger8 = createInternalLogger("Captcha");
|
|
1394
1394
|
function useCaptchaMonitor(page, options) {
|
|
1395
1395
|
const { domSelector, urlPattern, onDetected } = options;
|
|
1396
1396
|
if (!domSelector && !urlPattern) {
|
|
@@ -1462,7 +1462,7 @@ function useCaptchaMonitor(page, options) {
|
|
|
1462
1462
|
};
|
|
1463
1463
|
})();
|
|
1464
1464
|
}, { selector: domSelector, callbackName: exposedFunctionName, cleanerName });
|
|
1465
|
-
|
|
1465
|
+
logger8.success("useCaptchaMonitor", `DOM \u76D1\u63A7\u5DF2\u542F\u7528: ${domSelector}`);
|
|
1466
1466
|
cleanupFns.push(async () => {
|
|
1467
1467
|
try {
|
|
1468
1468
|
await page.evaluate((name) => {
|
|
@@ -1485,14 +1485,14 @@ function useCaptchaMonitor(page, options) {
|
|
|
1485
1485
|
}
|
|
1486
1486
|
};
|
|
1487
1487
|
page.on("framenavigated", frameHandler);
|
|
1488
|
-
|
|
1488
|
+
logger8.success("useCaptchaMonitor", `URL \u76D1\u63A7\u5DF2\u542F\u7528: ${urlPattern}`);
|
|
1489
1489
|
cleanupFns.push(async () => {
|
|
1490
1490
|
page.off("framenavigated", frameHandler);
|
|
1491
1491
|
});
|
|
1492
1492
|
}
|
|
1493
1493
|
return {
|
|
1494
1494
|
stop: async () => {
|
|
1495
|
-
|
|
1495
|
+
logger8.info("useCaptchaMonitor", "\u6B63\u5728\u505C\u6B62\u76D1\u63A7...");
|
|
1496
1496
|
for (const fn of cleanupFns) {
|
|
1497
1497
|
await fn();
|
|
1498
1498
|
}
|
|
@@ -1507,7 +1507,7 @@ var Captcha = {
|
|
|
1507
1507
|
// src/sse.js
|
|
1508
1508
|
import https from "https";
|
|
1509
1509
|
import { URL as URL2 } from "url";
|
|
1510
|
-
var
|
|
1510
|
+
var logger9 = createInternalLogger("Sse");
|
|
1511
1511
|
var Sse = {
|
|
1512
1512
|
/**
|
|
1513
1513
|
* 解析 SSE 流文本
|
|
@@ -1526,11 +1526,11 @@ var Sse = {
|
|
|
1526
1526
|
events.push(JSON.parse(jsonContent));
|
|
1527
1527
|
}
|
|
1528
1528
|
} catch (e) {
|
|
1529
|
-
|
|
1529
|
+
logger9.debug("parseSseStream", `JSON \u89E3\u6790\u5931\u8D25: ${e.message}, line: ${line.substring(0, 100)}...`);
|
|
1530
1530
|
}
|
|
1531
1531
|
}
|
|
1532
1532
|
}
|
|
1533
|
-
|
|
1533
|
+
logger9.success("parseSseStream", `\u89E3\u6790\u5B8C\u6210, events \u6570\u91CF: ${events.length}`);
|
|
1534
1534
|
return events;
|
|
1535
1535
|
},
|
|
1536
1536
|
/**
|
|
@@ -1580,7 +1580,7 @@ var Sse = {
|
|
|
1580
1580
|
if (!autoUnroute) return;
|
|
1581
1581
|
if (unrouteRequested) return;
|
|
1582
1582
|
unrouteRequested = true;
|
|
1583
|
-
|
|
1583
|
+
logger9.info("[MITM] autoUnroute: \u53D6\u6D88\u540E\u7EED\u62E6\u622A");
|
|
1584
1584
|
page.unroute(urlPattern, routeHandler).catch(() => {
|
|
1585
1585
|
});
|
|
1586
1586
|
};
|
|
@@ -1600,19 +1600,19 @@ var Sse = {
|
|
|
1600
1600
|
};
|
|
1601
1601
|
const routeHandler = async (route) => {
|
|
1602
1602
|
if (firstMatchOnly && hasMatchedOnce) {
|
|
1603
|
-
|
|
1603
|
+
logger9.info(`[MITM] firstMatchOnly: \u653E\u884C\u540E\u7EED\u8BF7\u6C42: ${route.request().url()}`);
|
|
1604
1604
|
route.continue().catch(() => {
|
|
1605
1605
|
});
|
|
1606
1606
|
return;
|
|
1607
1607
|
}
|
|
1608
1608
|
if (firstMatchOnly && !hasMatchedOnce) {
|
|
1609
1609
|
hasMatchedOnce = true;
|
|
1610
|
-
|
|
1610
|
+
logger9.info("[MITM] firstMatchOnly: \u547D\u4E2D\u9996\u4E2A\u8BF7\u6C42\uFF0C\u53D6\u6D88\u540E\u7EED\u62E6\u622A");
|
|
1611
1611
|
page.unroute(urlPattern, routeHandler).catch(() => {
|
|
1612
1612
|
});
|
|
1613
1613
|
}
|
|
1614
1614
|
const request = route.request();
|
|
1615
|
-
|
|
1615
|
+
logger9.info(`[MITM] \u5DF2\u62E6\u622A\u8BF7\u6C42: ${request.url()}`);
|
|
1616
1616
|
try {
|
|
1617
1617
|
const headers = await request.allHeaders();
|
|
1618
1618
|
const postData = request.postData();
|
|
@@ -1637,7 +1637,7 @@ var Sse = {
|
|
|
1637
1637
|
clearTimeout(initialTimer);
|
|
1638
1638
|
initialTimer = null;
|
|
1639
1639
|
}
|
|
1640
|
-
|
|
1640
|
+
logger9.debug("[Intercept] \u5DF2\u63A5\u6536\u521D\u59CB\u6570\u636E");
|
|
1641
1641
|
}
|
|
1642
1642
|
chunks.push(chunk);
|
|
1643
1643
|
const textChunk = chunk.toString("utf-8");
|
|
@@ -1646,18 +1646,18 @@ var Sse = {
|
|
|
1646
1646
|
try {
|
|
1647
1647
|
onData(textChunk, safeResolve, accumulatedText);
|
|
1648
1648
|
} catch (e) {
|
|
1649
|
-
|
|
1649
|
+
logger9.fail(`onData \u9519\u8BEF`, e);
|
|
1650
1650
|
}
|
|
1651
1651
|
}
|
|
1652
1652
|
});
|
|
1653
1653
|
res.on("end", () => {
|
|
1654
|
-
|
|
1654
|
+
logger9.info("[MITM] \u4E0A\u6E38\u54CD\u5E94\u7ED3\u675F");
|
|
1655
1655
|
clearAllTimers();
|
|
1656
1656
|
if (onEnd) {
|
|
1657
1657
|
try {
|
|
1658
1658
|
onEnd(accumulatedText, safeResolve);
|
|
1659
1659
|
} catch (e) {
|
|
1660
|
-
|
|
1660
|
+
logger9.fail(`onEnd \u9519\u8BEF`, e);
|
|
1661
1661
|
}
|
|
1662
1662
|
} else if (!onData) {
|
|
1663
1663
|
safeResolve(accumulatedText);
|
|
@@ -1740,7 +1740,7 @@ var Sse = {
|
|
|
1740
1740
|
import { gotScraping } from "got-scraping";
|
|
1741
1741
|
import { Agent as HttpAgent } from "http";
|
|
1742
1742
|
import { Agent as HttpsAgent } from "https";
|
|
1743
|
-
var
|
|
1743
|
+
var logger10 = createInternalLogger("Interception");
|
|
1744
1744
|
var SHARED_HTTP_AGENT = new HttpAgent({
|
|
1745
1745
|
keepAlive: true,
|
|
1746
1746
|
keepAliveMsecs: 15e3,
|
|
@@ -1948,9 +1948,9 @@ var Interception = {
|
|
|
1948
1948
|
const directRules = [];
|
|
1949
1949
|
if (hasDirectDomains) directRules.push(`\u76F4\u8FDE\u57DF\u540D: [${normalizedDirectDomains.length} \u4E2A]`);
|
|
1950
1950
|
if (hasDirectExtensions) directRules.push(`\u76F4\u8FDE\u6269\u5C55\u540D: [${normalizedDirectExtensions.join(", ")}]`);
|
|
1951
|
-
|
|
1951
|
+
logger10.start("setup", directRules.length > 0 ? `${directRules.join(" | ")} | \u5C4F\u853D: [${enabledCategories.join(", ")}]` : `\u4EC5\u8D44\u6E90\u5C4F\u853D\u6A21\u5F0F | \u5C4F\u853D: [${enabledCategories.join(", ")}]`);
|
|
1952
1952
|
if (!hasInterceptionRules) {
|
|
1953
|
-
|
|
1953
|
+
logger10.info("\u65E0\u547D\u4E2D\u89C4\u5219\uFF0C\u8DF3\u8FC7 page.route \u6CE8\u518C");
|
|
1954
1954
|
return;
|
|
1955
1955
|
}
|
|
1956
1956
|
const directRouteHandler = async (route) => {
|
|
@@ -1994,7 +1994,7 @@ var Interception = {
|
|
|
1994
1994
|
delete resHeaders["transfer-encoding"];
|
|
1995
1995
|
delete resHeaders["connection"];
|
|
1996
1996
|
delete resHeaders["keep-alive"];
|
|
1997
|
-
isSilent ?
|
|
1997
|
+
isSilent ? logger10.debug(`\u76F4\u8FDE\u6210\u529F: ${urlPath}`) : logger10.info(`\u76F4\u8FDE\u6210\u529F: ${urlPath}`);
|
|
1998
1998
|
await safeFulfill(route, {
|
|
1999
1999
|
status: response.statusCode,
|
|
2000
2000
|
headers: resHeaders,
|
|
@@ -2005,7 +2005,7 @@ var Interception = {
|
|
|
2005
2005
|
const isTimeout = err?.code === "ETIMEDOUT" || message.toLowerCase().includes("timeout");
|
|
2006
2006
|
const action = fallbackToProxy ? "\u56DE\u9000\u4EE3\u7406" : "\u5DF2\u653E\u5F03";
|
|
2007
2007
|
const reason = isTimeout ? `\u8D85\u65F6(${DirectConfig.directTimeout}s)` : `\u5F02\u5E38: ${message}`;
|
|
2008
|
-
|
|
2008
|
+
logger10.warn(`\u76F4\u8FDE${reason}\uFF0C${action}`);
|
|
2009
2009
|
if (fallbackToProxy) {
|
|
2010
2010
|
await safeContinue(route);
|
|
2011
2011
|
} else {
|
|
@@ -2079,7 +2079,7 @@ function escapeRegex(value) {
|
|
|
2079
2079
|
|
|
2080
2080
|
// src/mutation.js
|
|
2081
2081
|
import { v4 as uuidv42 } from "uuid";
|
|
2082
|
-
var
|
|
2082
|
+
var logger11 = createInternalLogger("Mutation");
|
|
2083
2083
|
var MUTATION_MONITOR_MODE = Object.freeze({
|
|
2084
2084
|
Added: "added",
|
|
2085
2085
|
Changed: "changed",
|
|
@@ -2112,14 +2112,14 @@ var Mutation = {
|
|
|
2112
2112
|
const stableTime = options.stableTime ?? 5 * 1e3;
|
|
2113
2113
|
const timeout = options.timeout ?? 120 * 1e3;
|
|
2114
2114
|
const onMutation = options.onMutation;
|
|
2115
|
-
|
|
2115
|
+
logger11.start("waitForStable", `\u76D1\u63A7 ${selectorList.length} \u4E2A\u9009\u62E9\u5668, \u7A33\u5B9A\u65F6\u95F4=${stableTime}ms`);
|
|
2116
2116
|
if (initialTimeout > 0) {
|
|
2117
2117
|
const selectorQuery = selectorList.join(",");
|
|
2118
2118
|
try {
|
|
2119
2119
|
await page.waitForSelector(selectorQuery, { timeout: initialTimeout });
|
|
2120
|
-
|
|
2120
|
+
logger11.info(`waitForStable \u5DF2\u68C0\u6D4B\u5230\u5143\u7D20: ${selectorQuery}`);
|
|
2121
2121
|
} catch (e) {
|
|
2122
|
-
|
|
2122
|
+
logger11.warning(`waitForStable \u521D\u59CB\u7B49\u5F85\u8D85\u65F6 (${initialTimeout}ms): ${selectorQuery}`);
|
|
2123
2123
|
throw e;
|
|
2124
2124
|
}
|
|
2125
2125
|
}
|
|
@@ -2135,7 +2135,7 @@ var Mutation = {
|
|
|
2135
2135
|
return "__CONTINUE__";
|
|
2136
2136
|
}
|
|
2137
2137
|
});
|
|
2138
|
-
|
|
2138
|
+
logger11.info("waitForStable \u5DF2\u542F\u7528 onMutation \u56DE\u8C03");
|
|
2139
2139
|
} catch (e) {
|
|
2140
2140
|
}
|
|
2141
2141
|
}
|
|
@@ -2250,9 +2250,9 @@ var Mutation = {
|
|
|
2250
2250
|
{ selectorList, stableTime, timeout, callbackName, hasCallback: !!onMutation }
|
|
2251
2251
|
);
|
|
2252
2252
|
if (result.mutationCount === 0 && result.stableTime === 0) {
|
|
2253
|
-
|
|
2253
|
+
logger11.warning("waitForStable \u672A\u627E\u5230\u53EF\u76D1\u63A7\u7684\u5143\u7D20");
|
|
2254
2254
|
}
|
|
2255
|
-
|
|
2255
|
+
logger11.success("waitForStable", `DOM \u7A33\u5B9A, \u603B\u5171 ${result.mutationCount} \u6B21\u53D8\u5316${result.wasPaused ? ", \u66FE\u6682\u505C\u8BA1\u65F6" : ""}`);
|
|
2256
2256
|
return result;
|
|
2257
2257
|
},
|
|
2258
2258
|
/**
|
|
@@ -2272,7 +2272,7 @@ var Mutation = {
|
|
|
2272
2272
|
const onMutation = options.onMutation;
|
|
2273
2273
|
const rawMode = String(options.mode || MUTATION_MONITOR_MODE.Added).toLowerCase();
|
|
2274
2274
|
const mode = [MUTATION_MONITOR_MODE.Added, MUTATION_MONITOR_MODE.Changed, MUTATION_MONITOR_MODE.All].includes(rawMode) ? rawMode : MUTATION_MONITOR_MODE.Added;
|
|
2275
|
-
|
|
2275
|
+
logger11.start("useMonitor", `\u76D1\u63A7 ${selectorList.length} \u4E2A\u9009\u62E9\u5668, mode=${mode}`);
|
|
2276
2276
|
const monitorKey = generateKey("pk_mon");
|
|
2277
2277
|
const callbackName = generateKey("pk_mon_cb");
|
|
2278
2278
|
const cleanerName = generateKey("pk_mon_clean");
|
|
@@ -2415,7 +2415,7 @@ var Mutation = {
|
|
|
2415
2415
|
return total;
|
|
2416
2416
|
};
|
|
2417
2417
|
}, { selectorList, monitorKey, callbackName, cleanerName, hasCallback: !!onMutation, mode });
|
|
2418
|
-
|
|
2418
|
+
logger11.success("useMonitor", "\u76D1\u63A7\u5668\u5DF2\u542F\u52A8");
|
|
2419
2419
|
return {
|
|
2420
2420
|
stop: async () => {
|
|
2421
2421
|
let totalMutations = 0;
|
|
@@ -2428,7 +2428,7 @@ var Mutation = {
|
|
|
2428
2428
|
}, cleanerName);
|
|
2429
2429
|
} catch (e) {
|
|
2430
2430
|
}
|
|
2431
|
-
|
|
2431
|
+
logger11.success("useMonitor.stop", `\u76D1\u63A7\u5DF2\u505C\u6B62, \u5171 ${totalMutations} \u6B21\u53D8\u5316`);
|
|
2432
2432
|
return { totalMutations };
|
|
2433
2433
|
}
|
|
2434
2434
|
};
|
|
@@ -3249,7 +3249,7 @@ var createTemplateLogger = (baseLogger = createBaseLogger()) => {
|
|
|
3249
3249
|
};
|
|
3250
3250
|
var getDefaultBaseLogger = () => createBaseLogger("");
|
|
3251
3251
|
var Logger = {
|
|
3252
|
-
setLogger: (
|
|
3252
|
+
setLogger: (logger13) => setDefaultLogger(logger13),
|
|
3253
3253
|
info: (message) => getDefaultBaseLogger().info(message),
|
|
3254
3254
|
success: (message) => getDefaultBaseLogger().success(message),
|
|
3255
3255
|
warning: (message) => getDefaultBaseLogger().warning(message),
|
|
@@ -3257,15 +3257,15 @@ var Logger = {
|
|
|
3257
3257
|
error: (message) => getDefaultBaseLogger().error(message),
|
|
3258
3258
|
debug: (message) => getDefaultBaseLogger().debug(message),
|
|
3259
3259
|
start: (message) => getDefaultBaseLogger().start(message),
|
|
3260
|
-
useTemplate: (
|
|
3261
|
-
if (
|
|
3260
|
+
useTemplate: (logger13) => {
|
|
3261
|
+
if (logger13) return createTemplateLogger(createBaseLogger("", logger13));
|
|
3262
3262
|
return createTemplateLogger();
|
|
3263
3263
|
}
|
|
3264
3264
|
};
|
|
3265
3265
|
|
|
3266
3266
|
// src/share.js
|
|
3267
3267
|
import delay3 from "delay";
|
|
3268
|
-
var
|
|
3268
|
+
var logger12 = createInternalLogger("Share");
|
|
3269
3269
|
var DEFAULT_TIMEOUT_MS = 50 * 1e3;
|
|
3270
3270
|
var DEFAULT_PAYLOAD_SNAPSHOT_MAX_LEN = 500;
|
|
3271
3271
|
var DEFAULT_POLL_INTERVAL_MS = 120;
|
|
@@ -3385,7 +3385,7 @@ var createDomShareMonitor = async (page, options = {}) => {
|
|
|
3385
3385
|
const onMatch = typeof options.onMatch === "function" ? options.onMatch : null;
|
|
3386
3386
|
const onTelemetry = typeof options.onTelemetry === "function" ? options.onTelemetry : null;
|
|
3387
3387
|
let matched = false;
|
|
3388
|
-
|
|
3388
|
+
logger12.info(`DOM \u76D1\u542C\u51C6\u5907\u6302\u8F7D: selectors=${toJsonInline(selectors, 120)}, mode=${mode}`);
|
|
3389
3389
|
const monitor = await Mutation.useMonitor(page, selectors, {
|
|
3390
3390
|
mode,
|
|
3391
3391
|
onMutation: (context = {}) => {
|
|
@@ -3403,12 +3403,12 @@ ${text}`;
|
|
|
3403
3403
|
});
|
|
3404
3404
|
}
|
|
3405
3405
|
if (mutationCount <= 5 || mutationCount % 50 === 0) {
|
|
3406
|
-
|
|
3406
|
+
logger12.info(`DOM \u53D8\u5316\u5DF2\u6355\u83B7: mutationCount=${mutationCount}, mutationNodes=${mutationNodes.length}`);
|
|
3407
3407
|
}
|
|
3408
3408
|
const [candidate] = Utils.parseLinks(rawDom, { prefix }) || [];
|
|
3409
3409
|
if (!candidate) return;
|
|
3410
3410
|
matched = true;
|
|
3411
|
-
|
|
3411
|
+
logger12.success("captureLink.domHit", `DOM \u547D\u4E2D\u5206\u4EAB\u94FE\u63A5: mutationCount=${mutationCount}, link=${candidate}`);
|
|
3412
3412
|
if (onMatch) {
|
|
3413
3413
|
onMatch({
|
|
3414
3414
|
link: candidate,
|
|
@@ -3424,7 +3424,7 @@ ${text}`;
|
|
|
3424
3424
|
return {
|
|
3425
3425
|
stop: async () => {
|
|
3426
3426
|
const result = await monitor.stop();
|
|
3427
|
-
|
|
3427
|
+
logger12.info(`DOM \u76D1\u542C\u5DF2\u505C\u6B62: totalMutations=${result?.totalMutations || 0}`);
|
|
3428
3428
|
return result;
|
|
3429
3429
|
}
|
|
3430
3430
|
};
|
|
@@ -3464,8 +3464,8 @@ var Share = {
|
|
|
3464
3464
|
if (share.mode === "response" && apiMatchers.length === 0) {
|
|
3465
3465
|
throw new Error("Share.captureLink requires share.xurl[0] api matcher when mode=response");
|
|
3466
3466
|
}
|
|
3467
|
-
|
|
3468
|
-
|
|
3467
|
+
logger12.start("captureLink", `mode=${share.mode}, timeoutMs=${timeoutMs}, prefix=${share.prefix}`);
|
|
3468
|
+
logger12.info(`captureLink \u914D\u7F6E: xurl=${toJsonInline(share.xurl)}, domMode=${domMode}, domSelectors=${toJsonInline(domSelectors, 120)}`);
|
|
3469
3469
|
const stats = {
|
|
3470
3470
|
actionTimedOut: false,
|
|
3471
3471
|
domMutationCount: 0,
|
|
@@ -3490,7 +3490,7 @@ var Share = {
|
|
|
3490
3490
|
link: validated,
|
|
3491
3491
|
payloadText: String(payloadText || "")
|
|
3492
3492
|
};
|
|
3493
|
-
|
|
3493
|
+
logger12.info(`\u5019\u9009\u94FE\u63A5\u5DF2\u786E\u8BA4: source=${source}, link=${validated}`);
|
|
3494
3494
|
return true;
|
|
3495
3495
|
};
|
|
3496
3496
|
const resolveResponseCandidate = (responseText) => {
|
|
@@ -3525,7 +3525,7 @@ var Share = {
|
|
|
3525
3525
|
try {
|
|
3526
3526
|
await monitor.stop();
|
|
3527
3527
|
} catch (error) {
|
|
3528
|
-
|
|
3528
|
+
logger12.warning(`\u505C\u6B62 DOM \u76D1\u542C\u5931\u8D25: ${error instanceof Error ? error.message : String(error)}`);
|
|
3529
3529
|
}
|
|
3530
3530
|
};
|
|
3531
3531
|
const onResponse = async (response) => {
|
|
@@ -3538,29 +3538,29 @@ var Share = {
|
|
|
3538
3538
|
stats.responseSampleUrls.push(url);
|
|
3539
3539
|
}
|
|
3540
3540
|
if (stats.responseObserved <= 5) {
|
|
3541
|
-
|
|
3541
|
+
logger12.info(`\u63A5\u53E3\u54CD\u5E94\u91C7\u6837(${stats.responseObserved}): ${url}`);
|
|
3542
3542
|
}
|
|
3543
3543
|
if (!apiMatchers.some((matcher) => url.includes(matcher))) return;
|
|
3544
3544
|
stats.responseMatched += 1;
|
|
3545
3545
|
stats.lastMatchedUrl = url;
|
|
3546
|
-
|
|
3546
|
+
logger12.info(`\u63A5\u53E3\u547D\u4E2D\u5339\u914D(${stats.responseMatched}): ${url}`);
|
|
3547
3547
|
const text = await response.text();
|
|
3548
3548
|
const hit = resolveResponseCandidate(text);
|
|
3549
3549
|
if (!hit?.link) {
|
|
3550
3550
|
if (stats.responseMatched <= 3) {
|
|
3551
|
-
|
|
3551
|
+
logger12.info(`\u63A5\u53E3\u89E3\u6790\u5B8C\u6210\u4F46\u672A\u63D0\u53D6\u5230\u5206\u4EAB\u94FE\u63A5: payloadSize=${text.length}`);
|
|
3552
3552
|
}
|
|
3553
3553
|
return;
|
|
3554
3554
|
}
|
|
3555
3555
|
stats.responseResolved += 1;
|
|
3556
|
-
|
|
3556
|
+
logger12.success("captureLink.responseHit", `\u63A5\u53E3\u547D\u4E2D\u5206\u4EAB\u94FE\u63A5: url=${url}, link=${hit.link}`);
|
|
3557
3557
|
setCandidate("response", hit.link, hit.payloadText);
|
|
3558
3558
|
} catch (error) {
|
|
3559
|
-
|
|
3559
|
+
logger12.warning(`\u63A5\u53E3\u54CD\u5E94\u5904\u7406\u5F02\u5E38: ${error instanceof Error ? error.message : String(error)}`);
|
|
3560
3560
|
}
|
|
3561
3561
|
};
|
|
3562
3562
|
if (share.mode === "dom") {
|
|
3563
|
-
|
|
3563
|
+
logger12.info("\u5F53\u524D\u4E3A DOM \u6A21\u5F0F\uFF0C\u4EC5\u542F\u7528 DOM \u76D1\u542C");
|
|
3564
3564
|
domMonitor = await createDomShareMonitor(page, {
|
|
3565
3565
|
prefix: share.prefix,
|
|
3566
3566
|
selectors: domSelectors,
|
|
@@ -3575,14 +3575,14 @@ var Share = {
|
|
|
3575
3575
|
});
|
|
3576
3576
|
}
|
|
3577
3577
|
if (share.mode === "response") {
|
|
3578
|
-
|
|
3578
|
+
logger12.info(`\u5F53\u524D\u4E3A\u63A5\u53E3\u6A21\u5F0F\uFF0C\u6302\u8F7D response \u76D1\u542C: apiMatchers=${toJsonInline(apiMatchers, 160)}`);
|
|
3579
3579
|
page.on("response", onResponse);
|
|
3580
3580
|
}
|
|
3581
3581
|
const deadline = Date.now() + timeoutMs;
|
|
3582
3582
|
const getRemainingMs = () => Math.max(0, deadline - Date.now());
|
|
3583
3583
|
try {
|
|
3584
3584
|
const actionTimeout = getRemainingMs();
|
|
3585
|
-
|
|
3585
|
+
logger12.start("captureLink.performActions", `\u6267\u884C\u52A8\u4F5C\u9884\u7B97=${actionTimeout}ms`);
|
|
3586
3586
|
if (actionTimeout > 0) {
|
|
3587
3587
|
let timer = null;
|
|
3588
3588
|
let actionError = null;
|
|
@@ -3596,21 +3596,21 @@ var Share = {
|
|
|
3596
3596
|
const actionResult = await Promise.race([actionPromise, timeoutPromise]);
|
|
3597
3597
|
if (timer) clearTimeout(timer);
|
|
3598
3598
|
if (actionResult === "__ACTION_ERROR__") {
|
|
3599
|
-
|
|
3599
|
+
logger12.fail("captureLink.performActions", actionError);
|
|
3600
3600
|
throw actionError;
|
|
3601
3601
|
}
|
|
3602
3602
|
if (actionResult === "__ACTION_TIMEOUT__") {
|
|
3603
3603
|
stats.actionTimedOut = true;
|
|
3604
|
-
|
|
3604
|
+
logger12.warning(`performActions \u5DF2\u8D85\u65F6 (${actionTimeout}ms)\uFF0C\u52A8\u4F5C\u53EF\u80FD\u4ECD\u5728\u5F02\u6B65\u6267\u884C`);
|
|
3605
3605
|
} else {
|
|
3606
|
-
|
|
3606
|
+
logger12.success("captureLink.performActions", "\u6267\u884C\u52A8\u4F5C\u5B8C\u6210");
|
|
3607
3607
|
}
|
|
3608
3608
|
}
|
|
3609
3609
|
let nextProgressLogTs = Date.now() + 3e3;
|
|
3610
3610
|
while (true) {
|
|
3611
3611
|
const selected = share.mode === "dom" ? candidates.dom : candidates.response;
|
|
3612
3612
|
if (selected?.link) {
|
|
3613
|
-
|
|
3613
|
+
logger12.success("captureLink", `\u6355\u83B7\u6210\u529F: source=${share.mode}, link=${selected.link}`);
|
|
3614
3614
|
return {
|
|
3615
3615
|
link: selected.link,
|
|
3616
3616
|
payloadText: selected.payloadText,
|
|
@@ -3622,7 +3622,7 @@ var Share = {
|
|
|
3622
3622
|
if (remaining <= 0) break;
|
|
3623
3623
|
const now = Date.now();
|
|
3624
3624
|
if (now >= nextProgressLogTs) {
|
|
3625
|
-
|
|
3625
|
+
logger12.info(
|
|
3626
3626
|
`captureLink \u7B49\u5F85\u4E2D: remaining=${remaining}ms, domMutationCount=${stats.domMutationCount}, responseMatched=${stats.responseMatched}`
|
|
3627
3627
|
);
|
|
3628
3628
|
nextProgressLogTs = now + 5e3;
|
|
@@ -3630,11 +3630,11 @@ var Share = {
|
|
|
3630
3630
|
await delay3(Math.max(0, Math.min(DEFAULT_POLL_INTERVAL_MS, remaining)));
|
|
3631
3631
|
}
|
|
3632
3632
|
if (share.mode === "response" && stats.responseMatched === 0) {
|
|
3633
|
-
|
|
3633
|
+
logger12.warning(
|
|
3634
3634
|
`\u63A5\u53E3\u76D1\u542C\u672A\u547D\u4E2D: apiMatchers=${toJsonInline(apiMatchers, 220)}, \u54CD\u5E94\u6837\u672CURLs=${toJsonInline(stats.responseSampleUrls, 420)}`
|
|
3635
3635
|
);
|
|
3636
3636
|
}
|
|
3637
|
-
|
|
3637
|
+
logger12.warning(
|
|
3638
3638
|
`captureLink \u8D85\u65F6\u672A\u62FF\u5230\u94FE\u63A5: mode=${share.mode}, actionTimedOut=${stats.actionTimedOut}, domMutationCount=${stats.domMutationCount}, responseObserved=${stats.responseObserved}, responseMatched=${stats.responseMatched}, lastMatchedUrl=${stats.lastMatchedUrl || "none"}`
|
|
3639
3639
|
);
|
|
3640
3640
|
return {
|
|
@@ -3646,7 +3646,7 @@ var Share = {
|
|
|
3646
3646
|
} finally {
|
|
3647
3647
|
if (share.mode === "response") {
|
|
3648
3648
|
page.off("response", onResponse);
|
|
3649
|
-
|
|
3649
|
+
logger12.info("response \u76D1\u542C\u5DF2\u5378\u8F7D");
|
|
3650
3650
|
}
|
|
3651
3651
|
await stopDomMonitor();
|
|
3652
3652
|
}
|