@skrillex1224/playwright-toolkit 2.1.97 → 2.1.98
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 +14 -1
- package/dist/index.cjs.map +2 -2
- package/dist/index.js +14 -1
- package/dist/index.js.map +2 -2
- package/index.d.ts +1 -0
- package/package.json +1 -1
package/dist/index.cjs
CHANGED
|
@@ -1332,6 +1332,7 @@ var Sse = {
|
|
|
1332
1332
|
* @param {number} [options.initialTimeout=90000] - 初始数据接收超时 (ms),默认 90s
|
|
1333
1333
|
* @param {number} [options.timeout=180000] - 整体请求超时时间 (ms),默认 180s
|
|
1334
1334
|
* @param {boolean} [options.autoUnroute=true] - resolve/reject 后是否自动取消拦截
|
|
1335
|
+
* @param {boolean} [options.firstMatchOnly=false] - 只拦截第一个命中的请求,后续请求全部放行
|
|
1335
1336
|
* @returns {Promise<any>} - 返回 Promise,当流满足条件时 resolve
|
|
1336
1337
|
*/
|
|
1337
1338
|
async intercept(page, urlPattern, options = {}) {
|
|
@@ -1341,7 +1342,8 @@ var Sse = {
|
|
|
1341
1342
|
onTimeout,
|
|
1342
1343
|
initialTimeout = 9e4,
|
|
1343
1344
|
overallTimeout = 18e4,
|
|
1344
|
-
autoUnroute = true
|
|
1345
|
+
autoUnroute = true,
|
|
1346
|
+
firstMatchOnly = false
|
|
1345
1347
|
} = options;
|
|
1346
1348
|
let initialTimer = null;
|
|
1347
1349
|
let overallTimer = null;
|
|
@@ -1355,6 +1357,7 @@ var Sse = {
|
|
|
1355
1357
|
const workPromise = new Promise((resolve, reject) => {
|
|
1356
1358
|
let finished = false;
|
|
1357
1359
|
let unrouteRequested = false;
|
|
1360
|
+
let hasMatchedOnce = false;
|
|
1358
1361
|
const safeUnroute = () => {
|
|
1359
1362
|
if (!autoUnroute) return;
|
|
1360
1363
|
if (unrouteRequested) return;
|
|
@@ -1377,6 +1380,16 @@ var Sse = {
|
|
|
1377
1380
|
reject(error);
|
|
1378
1381
|
};
|
|
1379
1382
|
const routeHandler = async (route) => {
|
|
1383
|
+
if (firstMatchOnly && hasMatchedOnce) {
|
|
1384
|
+
route.continue().catch(() => {
|
|
1385
|
+
});
|
|
1386
|
+
return;
|
|
1387
|
+
}
|
|
1388
|
+
if (firstMatchOnly && !hasMatchedOnce) {
|
|
1389
|
+
hasMatchedOnce = true;
|
|
1390
|
+
page.unroute(urlPattern, routeHandler).catch(() => {
|
|
1391
|
+
});
|
|
1392
|
+
}
|
|
1380
1393
|
const request = route.request();
|
|
1381
1394
|
logger8.info(`[MITM] \u5DF2\u62E6\u622A\u8BF7\u6C42: ${request.url()}`);
|
|
1382
1395
|
try {
|