@skrillex1224/playwright-toolkit 2.1.56 → 2.1.57

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.js CHANGED
@@ -2301,8 +2301,9 @@ var Mutation = {
2301
2301
  * @param {import('playwright').Page} page - Playwright page 对象
2302
2302
  * @param {string | string[]} selectors - 要监控的 CSS 选择器,单个或多个
2303
2303
  * @param {Object} [options] - 配置选项
2304
+ * @param {number} [options.initialTimeout] - 等待元素出现的超时 (毫秒, 默认: 30000)
2304
2305
  * @param {number} [options.stableTime] - 无变化持续时间后 resolve (毫秒, 默认: 5000)
2305
- * @param {number} [options.timeout] - 整体超时时间 (毫秒, 默认: 60000)
2306
+ * @param {number} [options.timeout] - 整体超时时间 (毫秒, 默认: 120000)
2306
2307
  * @param {Function} [options.onMutation] - 变化时的回调钩子
2307
2308
  * 签名: ({ mutationCount, innerHTML, innerText }) => any
2308
2309
  * 返回 null/undefined: 正常重置稳定计时
@@ -2311,10 +2312,21 @@ var Mutation = {
2311
2312
  */
2312
2313
  async waitForStable(page, selectors, options = {}) {
2313
2314
  const selectorList = Array.isArray(selectors) ? selectors : [selectors];
2314
- const stableTime = options.stableTime ?? 5e3;
2315
- const timeout = options.timeout ?? 6e4;
2315
+ const initialTimeout = options.initialTimeout ?? 30 * 1e3;
2316
+ const stableTime = options.stableTime ?? 5 * 1e3;
2317
+ const timeout = options.timeout ?? 120 * 1e3;
2316
2318
  const onMutation = options.onMutation;
2317
2319
  logger10.start("waitForStable", `\u76D1\u63A7 ${selectorList.length} \u4E2A\u9009\u62E9\u5668, \u7A33\u5B9A\u65F6\u95F4=${stableTime}ms`);
2320
+ if (initialTimeout > 0) {
2321
+ const selectorQuery = selectorList.join(",");
2322
+ try {
2323
+ await page.waitForSelector(selectorQuery, { timeout: initialTimeout });
2324
+ logger10.info(`waitForStable \u5DF2\u68C0\u6D4B\u5230\u5143\u7D20: ${selectorQuery}`);
2325
+ } catch (e) {
2326
+ logger10.warning(`waitForStable \u521D\u59CB\u7B49\u5F85\u8D85\u65F6 (${initialTimeout}ms): ${selectorQuery}`);
2327
+ throw e;
2328
+ }
2329
+ }
2318
2330
  const callbackName = generateKey("pk_mut_cb");
2319
2331
  if (onMutation) {
2320
2332
  try {
@@ -2382,9 +2394,14 @@ var Mutation = {
2382
2394
  innerHTML,
2383
2395
  innerText
2384
2396
  });
2385
- setPaused(signal === "__PAUSE__");
2397
+ const shouldPause = signal === "__PAUSE__";
2398
+ setPaused(shouldPause);
2399
+ if (!shouldPause) {
2400
+ resetStableTimer();
2401
+ }
2386
2402
  } catch (e) {
2387
2403
  setPaused(false);
2404
+ resetStableTimer();
2388
2405
  }
2389
2406
  } else {
2390
2407
  resetStableTimer();
@@ -2418,7 +2435,7 @@ var Mutation = {
2418
2435
  innerText
2419
2436
  });
2420
2437
  if (signal === "__PAUSE__") {
2421
- pauseStableTimer();
2438
+ setPaused(true);
2422
2439
  return;
2423
2440
  }
2424
2441
  } catch (e) {