@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 CHANGED
@@ -9067,7 +9067,7 @@ var Share = {
9067
9067
  * @param {import('playwright').Page} page
9068
9068
  * @param {Object} [options]
9069
9069
  * @param {{ mode?: 'dom' | 'response' | 'custom', prefix: string, xurl?: Array<string | string[]> }} options.share
9070
- * @param {number} [options.timeoutMs=50000]
9070
+ * @param {number} [options.timeoutMs=50000] 传 0 表示关闭超时,直到捕获成功或 signal.abort()
9071
9071
  * @param {number} [options.payloadSnapshotMaxLen=500]
9072
9072
  * @param {string | string[]} [options.domSelectors='html']
9073
9073
  * @param {'added' | 'changed' | 'all'} [options.domMode='all']
@@ -9076,7 +9076,8 @@ var Share = {
9076
9076
  */
9077
9077
  async captureLink(page, options = {}) {
9078
9078
  const share = normalizeShare(options.share);
9079
- const timeoutMs = Math.max(0, Number(options.timeoutMs ?? DEFAULT_TIMEOUT_MS2) || 0);
9079
+ const timeoutMs = options.timeoutMs ?? DEFAULT_TIMEOUT_MS2;
9080
+ const timeoutDisabled = timeoutMs === 0;
9080
9081
  const payloadSnapshotMaxLen = options.payloadSnapshotMaxLen ?? DEFAULT_PAYLOAD_SNAPSHOT_MAX_LEN;
9081
9082
  const domSelectors = options.domSelectors ?? "html";
9082
9083
  const domMode = options.domMode ?? Mutation.Mode.All;
@@ -9100,7 +9101,7 @@ var Share = {
9100
9101
  if (share.mode === "response" && apiMatchers.length === 0) {
9101
9102
  throw new Error("Share.captureLink requires share.xurl[0] api matcher when mode=response");
9102
9103
  }
9103
- logger15.start("captureLink", `mode=${share.mode}, timeoutMs=${timeoutMs}, prefix=${share.prefix}`);
9104
+ logger15.start("captureLink", `mode=${share.mode}, timeoutMs=${timeoutDisabled ? "disabled" : timeoutMs}, prefix=${share.prefix}`);
9104
9105
  logger15.info(`captureLink \u914D\u7F6E: xurl=${toJsonInline(share.xurl)}, domMode=${domMode}, domSelectors=${toJsonInline(domSelectors, 120)}`);
9105
9106
  const stats = {
9106
9107
  actionTimedOut: false,
@@ -9228,19 +9229,21 @@ var Share = {
9228
9229
  if (share.mode === "custom") {
9229
9230
  logger15.info("\u5F53\u524D\u4E3A custom \u6A21\u5F0F\uFF0C\u5C06\u4F7F\u7528 performActions \u8FD4\u56DE\u503C");
9230
9231
  }
9231
- const deadline = Date.now() + timeoutMs;
9232
- const getRemainingMs = () => Math.max(0, deadline - Date.now());
9232
+ const deadline = timeoutDisabled ? Infinity : Date.now() + timeoutMs;
9233
+ const getRemainingMs = () => timeoutDisabled ? Infinity : Math.max(0, deadline - Date.now());
9233
9234
  try {
9234
9235
  const actionTimeout = getRemainingMs();
9235
- logger15.start("captureLink.performActions", `\u6267\u884C\u52A8\u4F5C\u9884\u7B97=${actionTimeout}ms`);
9236
+ logger15.start("captureLink.performActions", `\u6267\u884C\u52A8\u4F5C\u9884\u7B97=${timeoutDisabled ? "disabled" : `${actionTimeout}ms`}`);
9236
9237
  let actionValue;
9237
9238
  if (!isAborted() && actionTimeout > 0) {
9238
9239
  let timer = null;
9239
9240
  const actionPromise = Promise.resolve().then(() => performActions()).then((result) => ({ type: "done", result })).catch((error) => ({ type: "error", error }));
9240
- const timeoutPromise = new Promise((resolve) => {
9241
- timer = setTimeout(() => resolve({ type: "timeout" }), actionTimeout);
9242
- });
9243
- const actionResult = await Promise.race([actionPromise, timeoutPromise]);
9241
+ const actionResult = timeoutDisabled ? await actionPromise : await Promise.race([
9242
+ actionPromise,
9243
+ new Promise((resolve) => {
9244
+ timer = setTimeout(() => resolve({ type: "timeout" }), actionTimeout);
9245
+ })
9246
+ ]);
9244
9247
  if (timer) clearTimeout(timer);
9245
9248
  if (actionResult.type === "error") {
9246
9249
  logger15.fail("captureLink.performActions", actionResult.error);
@@ -9290,19 +9293,19 @@ var Share = {
9290
9293
  const now = Date.now();
9291
9294
  if (now >= nextProgressLogTs) {
9292
9295
  logger15.info(
9293
- `captureLink \u7B49\u5F85\u4E2D: remaining=${remaining}ms, domMutationCount=${stats.domMutationCount}, responseMatched=${stats.responseMatched}`
9296
+ `captureLink \u7B49\u5F85\u4E2D: remaining=${timeoutDisabled ? "disabled" : `${remaining}ms`}, domMutationCount=${stats.domMutationCount}, responseMatched=${stats.responseMatched}`
9294
9297
  );
9295
9298
  nextProgressLogTs = now + 5e3;
9296
9299
  }
9297
9300
  await (0, import_delay4.default)(Math.max(0, Math.min(DEFAULT_POLL_INTERVAL_MS, remaining)));
9298
9301
  }
9299
- if (share.mode === "response" && stats.responseMatched === 0) {
9302
+ if (!timeoutDisabled && share.mode === "response" && stats.responseMatched === 0) {
9300
9303
  logger15.warning(
9301
9304
  `\u63A5\u53E3\u76D1\u542C\u672A\u547D\u4E2D: apiMatchers=${toJsonInline(apiMatchers, 220)}, \u54CD\u5E94\u6837\u672CURLs=${toJsonInline(stats.responseSampleUrls, 420)}`
9302
9305
  );
9303
9306
  }
9304
9307
  logger15.warning(
9305
- `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"}`
9308
+ `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"}`
9306
9309
  );
9307
9310
  return {
9308
9311
  link: null,