@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.js CHANGED
@@ -1305,6 +1305,7 @@ var Sse = {
1305
1305
  * @param {number} [options.initialTimeout=90000] - 初始数据接收超时 (ms),默认 90s
1306
1306
  * @param {number} [options.timeout=180000] - 整体请求超时时间 (ms),默认 180s
1307
1307
  * @param {boolean} [options.autoUnroute=true] - resolve/reject 后是否自动取消拦截
1308
+ * @param {boolean} [options.firstMatchOnly=false] - 只拦截第一个命中的请求,后续请求全部放行
1308
1309
  * @returns {Promise<any>} - 返回 Promise,当流满足条件时 resolve
1309
1310
  */
1310
1311
  async intercept(page, urlPattern, options = {}) {
@@ -1314,7 +1315,8 @@ var Sse = {
1314
1315
  onTimeout,
1315
1316
  initialTimeout = 9e4,
1316
1317
  overallTimeout = 18e4,
1317
- autoUnroute = true
1318
+ autoUnroute = true,
1319
+ firstMatchOnly = false
1318
1320
  } = options;
1319
1321
  let initialTimer = null;
1320
1322
  let overallTimer = null;
@@ -1328,6 +1330,7 @@ var Sse = {
1328
1330
  const workPromise = new Promise((resolve, reject) => {
1329
1331
  let finished = false;
1330
1332
  let unrouteRequested = false;
1333
+ let hasMatchedOnce = false;
1331
1334
  const safeUnroute = () => {
1332
1335
  if (!autoUnroute) return;
1333
1336
  if (unrouteRequested) return;
@@ -1350,6 +1353,16 @@ var Sse = {
1350
1353
  reject(error);
1351
1354
  };
1352
1355
  const routeHandler = async (route) => {
1356
+ if (firstMatchOnly && hasMatchedOnce) {
1357
+ route.continue().catch(() => {
1358
+ });
1359
+ return;
1360
+ }
1361
+ if (firstMatchOnly && !hasMatchedOnce) {
1362
+ hasMatchedOnce = true;
1363
+ page.unroute(urlPattern, routeHandler).catch(() => {
1364
+ });
1365
+ }
1353
1366
  const request = route.request();
1354
1367
  logger8.info(`[MITM] \u5DF2\u62E6\u622A\u8BF7\u6C42: ${request.url()}`);
1355
1368
  try {