@skrillex1224/playwright-toolkit 2.1.261 → 2.1.262
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 +16 -13
- package/dist/index.cjs.map +2 -2
- package/dist/index.js +16 -13
- package/dist/index.js.map +2 -2
- package/index.d.ts +1 -0
- package/package.json +1 -1
package/dist/index.js
CHANGED
|
@@ -9039,7 +9039,7 @@ var Share = {
|
|
|
9039
9039
|
* @param {import('playwright').Page} page
|
|
9040
9040
|
* @param {Object} [options]
|
|
9041
9041
|
* @param {{ mode?: 'dom' | 'response' | 'custom', prefix: string, xurl?: Array<string | string[]> }} options.share
|
|
9042
|
-
* @param {number} [options.timeoutMs=50000]
|
|
9042
|
+
* @param {number} [options.timeoutMs=50000] 传 0 表示关闭超时,直到捕获成功或 signal.abort()
|
|
9043
9043
|
* @param {number} [options.payloadSnapshotMaxLen=500]
|
|
9044
9044
|
* @param {string | string[]} [options.domSelectors='html']
|
|
9045
9045
|
* @param {'added' | 'changed' | 'all'} [options.domMode='all']
|
|
@@ -9048,7 +9048,8 @@ var Share = {
|
|
|
9048
9048
|
*/
|
|
9049
9049
|
async captureLink(page, options = {}) {
|
|
9050
9050
|
const share = normalizeShare(options.share);
|
|
9051
|
-
const timeoutMs =
|
|
9051
|
+
const timeoutMs = options.timeoutMs ?? DEFAULT_TIMEOUT_MS2;
|
|
9052
|
+
const timeoutDisabled = timeoutMs === 0;
|
|
9052
9053
|
const payloadSnapshotMaxLen = options.payloadSnapshotMaxLen ?? DEFAULT_PAYLOAD_SNAPSHOT_MAX_LEN;
|
|
9053
9054
|
const domSelectors = options.domSelectors ?? "html";
|
|
9054
9055
|
const domMode = options.domMode ?? Mutation.Mode.All;
|
|
@@ -9072,7 +9073,7 @@ var Share = {
|
|
|
9072
9073
|
if (share.mode === "response" && apiMatchers.length === 0) {
|
|
9073
9074
|
throw new Error("Share.captureLink requires share.xurl[0] api matcher when mode=response");
|
|
9074
9075
|
}
|
|
9075
|
-
logger15.start("captureLink", `mode=${share.mode}, timeoutMs=${timeoutMs}, prefix=${share.prefix}`);
|
|
9076
|
+
logger15.start("captureLink", `mode=${share.mode}, timeoutMs=${timeoutDisabled ? "disabled" : timeoutMs}, prefix=${share.prefix}`);
|
|
9076
9077
|
logger15.info(`captureLink \u914D\u7F6E: xurl=${toJsonInline(share.xurl)}, domMode=${domMode}, domSelectors=${toJsonInline(domSelectors, 120)}`);
|
|
9077
9078
|
const stats = {
|
|
9078
9079
|
actionTimedOut: false,
|
|
@@ -9200,19 +9201,21 @@ var Share = {
|
|
|
9200
9201
|
if (share.mode === "custom") {
|
|
9201
9202
|
logger15.info("\u5F53\u524D\u4E3A custom \u6A21\u5F0F\uFF0C\u5C06\u4F7F\u7528 performActions \u8FD4\u56DE\u503C");
|
|
9202
9203
|
}
|
|
9203
|
-
const deadline = Date.now() + timeoutMs;
|
|
9204
|
-
const getRemainingMs = () => Math.max(0, deadline - Date.now());
|
|
9204
|
+
const deadline = timeoutDisabled ? Infinity : Date.now() + timeoutMs;
|
|
9205
|
+
const getRemainingMs = () => timeoutDisabled ? Infinity : Math.max(0, deadline - Date.now());
|
|
9205
9206
|
try {
|
|
9206
9207
|
const actionTimeout = getRemainingMs();
|
|
9207
|
-
logger15.start("captureLink.performActions", `\u6267\u884C\u52A8\u4F5C\u9884\u7B97=${actionTimeout}ms`);
|
|
9208
|
+
logger15.start("captureLink.performActions", `\u6267\u884C\u52A8\u4F5C\u9884\u7B97=${timeoutDisabled ? "disabled" : `${actionTimeout}ms`}`);
|
|
9208
9209
|
let actionValue;
|
|
9209
9210
|
if (!isAborted() && actionTimeout > 0) {
|
|
9210
9211
|
let timer = null;
|
|
9211
9212
|
const actionPromise = Promise.resolve().then(() => performActions()).then((result) => ({ type: "done", result })).catch((error) => ({ type: "error", error }));
|
|
9212
|
-
const
|
|
9213
|
-
|
|
9214
|
-
|
|
9215
|
-
|
|
9213
|
+
const actionResult = timeoutDisabled ? await actionPromise : await Promise.race([
|
|
9214
|
+
actionPromise,
|
|
9215
|
+
new Promise((resolve) => {
|
|
9216
|
+
timer = setTimeout(() => resolve({ type: "timeout" }), actionTimeout);
|
|
9217
|
+
})
|
|
9218
|
+
]);
|
|
9216
9219
|
if (timer) clearTimeout(timer);
|
|
9217
9220
|
if (actionResult.type === "error") {
|
|
9218
9221
|
logger15.fail("captureLink.performActions", actionResult.error);
|
|
@@ -9262,19 +9265,19 @@ var Share = {
|
|
|
9262
9265
|
const now = Date.now();
|
|
9263
9266
|
if (now >= nextProgressLogTs) {
|
|
9264
9267
|
logger15.info(
|
|
9265
|
-
`captureLink \u7B49\u5F85\u4E2D: remaining=${remaining}ms, domMutationCount=${stats.domMutationCount}, responseMatched=${stats.responseMatched}`
|
|
9268
|
+
`captureLink \u7B49\u5F85\u4E2D: remaining=${timeoutDisabled ? "disabled" : `${remaining}ms`}, domMutationCount=${stats.domMutationCount}, responseMatched=${stats.responseMatched}`
|
|
9266
9269
|
);
|
|
9267
9270
|
nextProgressLogTs = now + 5e3;
|
|
9268
9271
|
}
|
|
9269
9272
|
await delay4(Math.max(0, Math.min(DEFAULT_POLL_INTERVAL_MS, remaining)));
|
|
9270
9273
|
}
|
|
9271
|
-
if (share.mode === "response" && stats.responseMatched === 0) {
|
|
9274
|
+
if (!timeoutDisabled && share.mode === "response" && stats.responseMatched === 0) {
|
|
9272
9275
|
logger15.warning(
|
|
9273
9276
|
`\u63A5\u53E3\u76D1\u542C\u672A\u547D\u4E2D: apiMatchers=${toJsonInline(apiMatchers, 220)}, \u54CD\u5E94\u6837\u672CURLs=${toJsonInline(stats.responseSampleUrls, 420)}`
|
|
9274
9277
|
);
|
|
9275
9278
|
}
|
|
9276
9279
|
logger15.warning(
|
|
9277
|
-
`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"}`
|
|
9280
|
+
`captureLink ${timeoutDisabled ? "\u672A\u62FF\u5230\u94FE\u63A5" : "\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"}`
|
|
9278
9281
|
);
|
|
9279
9282
|
return {
|
|
9280
9283
|
link: null,
|