@skrillex1224/playwright-toolkit 2.1.56 → 2.1.58
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 +22 -5
- package/dist/index.cjs.map +2 -2
- package/dist/index.js +22 -5
- package/dist/index.js.map +2 -2
- package/index.d.ts +3 -1
- package/package.json +1 -1
package/dist/index.cjs
CHANGED
|
@@ -2328,8 +2328,9 @@ var Mutation = {
|
|
|
2328
2328
|
* @param {import('playwright').Page} page - Playwright page 对象
|
|
2329
2329
|
* @param {string | string[]} selectors - 要监控的 CSS 选择器,单个或多个
|
|
2330
2330
|
* @param {Object} [options] - 配置选项
|
|
2331
|
+
* @param {number} [options.initialTimeout] - 等待元素出现的超时 (毫秒, 默认: 30000)
|
|
2331
2332
|
* @param {number} [options.stableTime] - 无变化持续时间后 resolve (毫秒, 默认: 5000)
|
|
2332
|
-
* @param {number} [options.timeout] - 整体超时时间 (毫秒, 默认:
|
|
2333
|
+
* @param {number} [options.timeout] - 整体超时时间 (毫秒, 默认: 120000)
|
|
2333
2334
|
* @param {Function} [options.onMutation] - 变化时的回调钩子
|
|
2334
2335
|
* 签名: ({ mutationCount, innerHTML, innerText }) => any
|
|
2335
2336
|
* 返回 null/undefined: 正常重置稳定计时
|
|
@@ -2338,10 +2339,21 @@ var Mutation = {
|
|
|
2338
2339
|
*/
|
|
2339
2340
|
async waitForStable(page, selectors, options = {}) {
|
|
2340
2341
|
const selectorList = Array.isArray(selectors) ? selectors : [selectors];
|
|
2341
|
-
const
|
|
2342
|
-
const
|
|
2342
|
+
const initialTimeout = options.initialTimeout ?? 30 * 1e3;
|
|
2343
|
+
const stableTime = options.stableTime ?? 5 * 1e3;
|
|
2344
|
+
const timeout = options.timeout ?? 120 * 1e3;
|
|
2343
2345
|
const onMutation = options.onMutation;
|
|
2344
2346
|
logger10.start("waitForStable", `\u76D1\u63A7 ${selectorList.length} \u4E2A\u9009\u62E9\u5668, \u7A33\u5B9A\u65F6\u95F4=${stableTime}ms`);
|
|
2347
|
+
if (initialTimeout > 0) {
|
|
2348
|
+
const selectorQuery = selectorList.join(",");
|
|
2349
|
+
try {
|
|
2350
|
+
await page.waitForSelector(selectorQuery, { timeout: initialTimeout });
|
|
2351
|
+
logger10.info(`waitForStable \u5DF2\u68C0\u6D4B\u5230\u5143\u7D20: ${selectorQuery}`);
|
|
2352
|
+
} catch (e) {
|
|
2353
|
+
logger10.warning(`waitForStable \u521D\u59CB\u7B49\u5F85\u8D85\u65F6 (${initialTimeout}ms): ${selectorQuery}`);
|
|
2354
|
+
throw e;
|
|
2355
|
+
}
|
|
2356
|
+
}
|
|
2345
2357
|
const callbackName = generateKey("pk_mut_cb");
|
|
2346
2358
|
if (onMutation) {
|
|
2347
2359
|
try {
|
|
@@ -2409,9 +2421,14 @@ var Mutation = {
|
|
|
2409
2421
|
innerHTML,
|
|
2410
2422
|
innerText
|
|
2411
2423
|
});
|
|
2412
|
-
|
|
2424
|
+
const shouldPause = signal === "__PAUSE__";
|
|
2425
|
+
setPaused(shouldPause);
|
|
2426
|
+
if (!shouldPause) {
|
|
2427
|
+
resetStableTimer();
|
|
2428
|
+
}
|
|
2413
2429
|
} catch (e) {
|
|
2414
2430
|
setPaused(false);
|
|
2431
|
+
resetStableTimer();
|
|
2415
2432
|
}
|
|
2416
2433
|
} else {
|
|
2417
2434
|
resetStableTimer();
|
|
@@ -2445,7 +2462,7 @@ var Mutation = {
|
|
|
2445
2462
|
innerText
|
|
2446
2463
|
});
|
|
2447
2464
|
if (signal === "__PAUSE__") {
|
|
2448
|
-
|
|
2465
|
+
setPaused(true);
|
|
2449
2466
|
return;
|
|
2450
2467
|
}
|
|
2451
2468
|
} catch (e) {
|