@skrillex1224/playwright-toolkit 2.1.239 → 2.1.240

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
@@ -56,7 +56,7 @@ var createActorInfo = (info) => {
56
56
  const normalizeShare2 = (value) => {
57
57
  const raw = value && typeof value === "object" ? value : {};
58
58
  const modeRaw = String(raw.mode || "dom").trim().toLowerCase();
59
- const mode = modeRaw === "response" ? "response" : "dom";
59
+ const mode = ["dom", "response", "custom"].includes(modeRaw) ? modeRaw : "dom";
60
60
  const prefix = String(raw.prefix || "").trim();
61
61
  const rawXurl = Array.isArray(raw.xurl) ? raw.xurl : [];
62
62
  const normalizeMatcherList = (input) => {
@@ -140,9 +140,8 @@ var ActorInfo = {
140
140
  qbot: createActorInfo({
141
141
  key: "qbot",
142
142
  name: "QQ\u6D4F\u89C8\u5668AI\u641C",
143
- domain: "m.sogou.com",
143
+ domain: "sogou.com",
144
144
  path: "/web",
145
- device: Device.Mobile,
146
145
  share: {
147
146
  mode: "dom",
148
147
  prefix: "",
@@ -214,7 +213,7 @@ var ActorInfo = {
214
213
  path: "/",
215
214
  device: Device.Mobile,
216
215
  share: {
217
- mode: "dom",
216
+ mode: "custom",
218
217
  prefix: "",
219
218
  xurl: []
220
219
  }
@@ -8340,7 +8339,7 @@ var normalizeXurl = (value) => {
8340
8339
  var normalizeShare = (share) => {
8341
8340
  const source = share && typeof share === "object" ? share : {};
8342
8341
  const modeRaw = String(source.mode || "dom").trim().toLowerCase();
8343
- const mode = modeRaw === "response" ? "response" : "dom";
8342
+ const mode = ["dom", "response", "custom"].includes(modeRaw) ? modeRaw : "dom";
8344
8343
  return {
8345
8344
  mode,
8346
8345
  prefix: normalizePrefix(source.prefix),
@@ -8456,16 +8455,17 @@ var Share = {
8456
8455
  * 捕获分享链接(单模式)
8457
8456
  * - mode='dom': 仅 DOM 监听
8458
8457
  * - mode='response': 仅接口监听
8458
+ * - mode='custom': 使用 performActions 返回值作为链接
8459
8459
  *
8460
8460
  * @param {import('playwright').Page} page
8461
8461
  * @param {Object} [options]
8462
- * @param {{ mode?: 'dom' | 'response', prefix: string, xurl?: Array<string | string[]> }} options.share
8462
+ * @param {{ mode?: 'dom' | 'response' | 'custom', prefix: string, xurl?: Array<string | string[]> }} options.share
8463
8463
  * @param {number} [options.timeoutMs=50000]
8464
8464
  * @param {number} [options.payloadSnapshotMaxLen=500]
8465
8465
  * @param {string | string[]} [options.domSelectors='html']
8466
8466
  * @param {'added' | 'changed' | 'all'} [options.domMode='all']
8467
- * @param {() => Promise<void>} [options.performActions]
8468
- * @returns {Promise<{ link: string | null; payloadText: string; payloadSnapshot: string; source: 'dom' | 'response' | 'none' }>}
8467
+ * @param {() => void | string | { link?: string | null; payloadText?: string } | Promise<void | string | { link?: string | null; payloadText?: string }>} [options.performActions]
8468
+ * @returns {Promise<{ link: string | null; payloadText: string; payloadSnapshot: string; source: 'dom' | 'response' | 'custom' | 'none' }>}
8469
8469
  */
8470
8470
  async captureLink(page, options = {}) {
8471
8471
  const share = normalizeShare(options.share);
@@ -8478,7 +8478,7 @@ var Share = {
8478
8478
  if (share.prefix === void 0) {
8479
8479
  throw new Error("Share.captureLink requires options.share.prefix");
8480
8480
  }
8481
- if (share.mode !== "dom" && share.mode !== "response") {
8481
+ if (share.mode !== "dom" && share.mode !== "response" && share.mode !== "custom") {
8482
8482
  throw new Error(`Share.captureLink unsupported share.mode: ${share.mode}`);
8483
8483
  }
8484
8484
  const apiMatchers = share.mode === "response" ? share.xurl[0] || [] : [];
@@ -8500,7 +8500,8 @@ var Share = {
8500
8500
  };
8501
8501
  const candidates = {
8502
8502
  dom: null,
8503
- response: null
8503
+ response: null,
8504
+ custom: null
8504
8505
  };
8505
8506
  const setCandidate = (source, link, payloadText = "") => {
8506
8507
  const safe = String(link || "").trim();
@@ -8600,37 +8601,47 @@ var Share = {
8600
8601
  logger15.info(`\u5F53\u524D\u4E3A\u63A5\u53E3\u6A21\u5F0F\uFF0C\u6302\u8F7D response \u76D1\u542C: apiMatchers=${toJsonInline(apiMatchers, 160)}`);
8601
8602
  page.on("response", onResponse);
8602
8603
  }
8604
+ if (share.mode === "custom") {
8605
+ logger15.info("\u5F53\u524D\u4E3A custom \u6A21\u5F0F\uFF0C\u5C06\u4F7F\u7528 performActions \u8FD4\u56DE\u503C");
8606
+ }
8603
8607
  const deadline = Date.now() + timeoutMs;
8604
8608
  const getRemainingMs = () => Math.max(0, deadline - Date.now());
8605
8609
  try {
8606
8610
  const actionTimeout = getRemainingMs();
8607
8611
  logger15.start("captureLink.performActions", `\u6267\u884C\u52A8\u4F5C\u9884\u7B97=${actionTimeout}ms`);
8612
+ let actionValue;
8608
8613
  if (actionTimeout > 0) {
8609
8614
  let timer = null;
8610
- let actionError = null;
8611
- const actionPromise = Promise.resolve().then(() => performActions()).then(() => "__ACTION_DONE__").catch((error) => {
8612
- actionError = error;
8613
- return "__ACTION_ERROR__";
8614
- });
8615
+ const actionPromise = Promise.resolve().then(() => performActions()).then((result) => ({ type: "done", result })).catch((error) => ({ type: "error", error }));
8615
8616
  const timeoutPromise = new Promise((resolve) => {
8616
- timer = setTimeout(() => resolve("__ACTION_TIMEOUT__"), actionTimeout);
8617
+ timer = setTimeout(() => resolve({ type: "timeout" }), actionTimeout);
8617
8618
  });
8618
8619
  const actionResult = await Promise.race([actionPromise, timeoutPromise]);
8619
8620
  if (timer) clearTimeout(timer);
8620
- if (actionResult === "__ACTION_ERROR__") {
8621
- logger15.fail("captureLink.performActions", actionError);
8622
- throw actionError;
8621
+ if (actionResult.type === "error") {
8622
+ logger15.fail("captureLink.performActions", actionResult.error);
8623
+ throw actionResult.error;
8623
8624
  }
8624
- if (actionResult === "__ACTION_TIMEOUT__") {
8625
+ if (actionResult.type === "timeout") {
8625
8626
  stats.actionTimedOut = true;
8626
8627
  logger15.warning(`performActions \u5DF2\u8D85\u65F6 (${actionTimeout}ms)\uFF0C\u52A8\u4F5C\u53EF\u80FD\u4ECD\u5728\u5F02\u6B65\u6267\u884C`);
8627
8628
  } else {
8629
+ actionValue = actionResult.result;
8628
8630
  logger15.success("captureLink.performActions", "\u6267\u884C\u52A8\u4F5C\u5B8C\u6210");
8629
8631
  }
8630
8632
  }
8633
+ if (share.mode === "custom") {
8634
+ const customLink = typeof actionValue === "string" ? actionValue : actionValue?.link || actionValue?.payloadText;
8635
+ const customPayloadText = typeof actionValue === "string" ? actionValue : actionValue?.payloadText;
8636
+ if (setCandidate("custom", customLink, customPayloadText)) {
8637
+ logger15.success("captureLink.customResult", `custom \u547D\u4E2D\u5206\u4EAB\u94FE\u63A5: link=${candidates.custom.link}`);
8638
+ } else {
8639
+ logger15.warning("performActions \u6267\u884C\u5B8C\u6210\u4F46\u672A\u8FD4\u56DE\u6709\u6548\u5206\u4EAB\u94FE\u63A5");
8640
+ }
8641
+ }
8631
8642
  let nextProgressLogTs = Date.now() + 3e3;
8632
8643
  while (true) {
8633
- const selected = share.mode === "dom" ? candidates.dom : candidates.response;
8644
+ const selected = candidates[share.mode];
8634
8645
  if (selected?.link) {
8635
8646
  logger15.success("captureLink", `\u6355\u83B7\u6210\u529F: source=${share.mode}, link=${selected.link}`);
8636
8647
  return {
@@ -8640,6 +8651,7 @@ var Share = {
8640
8651
  source: share.mode
8641
8652
  };
8642
8653
  }
8654
+ if (share.mode === "custom") break;
8643
8655
  const remaining = getRemainingMs();
8644
8656
  if (remaining <= 0) break;
8645
8657
  const now = Date.now();