@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/browser.js +3 -4
- package/dist/browser.js.map +2 -2
- package/dist/index.cjs +33 -21
- package/dist/index.cjs.map +2 -2
- package/dist/index.js +33 -21
- package/dist/index.js.map +2 -2
- package/index.d.ts +3 -3
- package/package.json +1 -1
package/dist/index.cjs
CHANGED
|
@@ -83,7 +83,7 @@ var createActorInfo = (info) => {
|
|
|
83
83
|
const normalizeShare2 = (value) => {
|
|
84
84
|
const raw = value && typeof value === "object" ? value : {};
|
|
85
85
|
const modeRaw = String(raw.mode || "dom").trim().toLowerCase();
|
|
86
|
-
const mode =
|
|
86
|
+
const mode = ["dom", "response", "custom"].includes(modeRaw) ? modeRaw : "dom";
|
|
87
87
|
const prefix = String(raw.prefix || "").trim();
|
|
88
88
|
const rawXurl = Array.isArray(raw.xurl) ? raw.xurl : [];
|
|
89
89
|
const normalizeMatcherList = (input) => {
|
|
@@ -167,9 +167,8 @@ var ActorInfo = {
|
|
|
167
167
|
qbot: createActorInfo({
|
|
168
168
|
key: "qbot",
|
|
169
169
|
name: "QQ\u6D4F\u89C8\u5668AI\u641C",
|
|
170
|
-
domain: "
|
|
170
|
+
domain: "sogou.com",
|
|
171
171
|
path: "/web",
|
|
172
|
-
device: Device.Mobile,
|
|
173
172
|
share: {
|
|
174
173
|
mode: "dom",
|
|
175
174
|
prefix: "",
|
|
@@ -241,7 +240,7 @@ var ActorInfo = {
|
|
|
241
240
|
path: "/",
|
|
242
241
|
device: Device.Mobile,
|
|
243
242
|
share: {
|
|
244
|
-
mode: "
|
|
243
|
+
mode: "custom",
|
|
245
244
|
prefix: "",
|
|
246
245
|
xurl: []
|
|
247
246
|
}
|
|
@@ -8368,7 +8367,7 @@ var normalizeXurl = (value) => {
|
|
|
8368
8367
|
var normalizeShare = (share) => {
|
|
8369
8368
|
const source = share && typeof share === "object" ? share : {};
|
|
8370
8369
|
const modeRaw = String(source.mode || "dom").trim().toLowerCase();
|
|
8371
|
-
const mode =
|
|
8370
|
+
const mode = ["dom", "response", "custom"].includes(modeRaw) ? modeRaw : "dom";
|
|
8372
8371
|
return {
|
|
8373
8372
|
mode,
|
|
8374
8373
|
prefix: normalizePrefix(source.prefix),
|
|
@@ -8484,16 +8483,17 @@ var Share = {
|
|
|
8484
8483
|
* 捕获分享链接(单模式)
|
|
8485
8484
|
* - mode='dom': 仅 DOM 监听
|
|
8486
8485
|
* - mode='response': 仅接口监听
|
|
8486
|
+
* - mode='custom': 使用 performActions 返回值作为链接
|
|
8487
8487
|
*
|
|
8488
8488
|
* @param {import('playwright').Page} page
|
|
8489
8489
|
* @param {Object} [options]
|
|
8490
|
-
* @param {{ mode?: 'dom' | 'response', prefix: string, xurl?: Array<string | string[]> }} options.share
|
|
8490
|
+
* @param {{ mode?: 'dom' | 'response' | 'custom', prefix: string, xurl?: Array<string | string[]> }} options.share
|
|
8491
8491
|
* @param {number} [options.timeoutMs=50000]
|
|
8492
8492
|
* @param {number} [options.payloadSnapshotMaxLen=500]
|
|
8493
8493
|
* @param {string | string[]} [options.domSelectors='html']
|
|
8494
8494
|
* @param {'added' | 'changed' | 'all'} [options.domMode='all']
|
|
8495
|
-
* @param {() => Promise<void>} [options.performActions]
|
|
8496
|
-
* @returns {Promise<{ link: string | null; payloadText: string; payloadSnapshot: string; source: 'dom' | 'response' | 'none' }>}
|
|
8495
|
+
* @param {() => void | string | { link?: string | null; payloadText?: string } | Promise<void | string | { link?: string | null; payloadText?: string }>} [options.performActions]
|
|
8496
|
+
* @returns {Promise<{ link: string | null; payloadText: string; payloadSnapshot: string; source: 'dom' | 'response' | 'custom' | 'none' }>}
|
|
8497
8497
|
*/
|
|
8498
8498
|
async captureLink(page, options = {}) {
|
|
8499
8499
|
const share = normalizeShare(options.share);
|
|
@@ -8506,7 +8506,7 @@ var Share = {
|
|
|
8506
8506
|
if (share.prefix === void 0) {
|
|
8507
8507
|
throw new Error("Share.captureLink requires options.share.prefix");
|
|
8508
8508
|
}
|
|
8509
|
-
if (share.mode !== "dom" && share.mode !== "response") {
|
|
8509
|
+
if (share.mode !== "dom" && share.mode !== "response" && share.mode !== "custom") {
|
|
8510
8510
|
throw new Error(`Share.captureLink unsupported share.mode: ${share.mode}`);
|
|
8511
8511
|
}
|
|
8512
8512
|
const apiMatchers = share.mode === "response" ? share.xurl[0] || [] : [];
|
|
@@ -8528,7 +8528,8 @@ var Share = {
|
|
|
8528
8528
|
};
|
|
8529
8529
|
const candidates = {
|
|
8530
8530
|
dom: null,
|
|
8531
|
-
response: null
|
|
8531
|
+
response: null,
|
|
8532
|
+
custom: null
|
|
8532
8533
|
};
|
|
8533
8534
|
const setCandidate = (source, link, payloadText = "") => {
|
|
8534
8535
|
const safe = String(link || "").trim();
|
|
@@ -8628,37 +8629,47 @@ var Share = {
|
|
|
8628
8629
|
logger15.info(`\u5F53\u524D\u4E3A\u63A5\u53E3\u6A21\u5F0F\uFF0C\u6302\u8F7D response \u76D1\u542C: apiMatchers=${toJsonInline(apiMatchers, 160)}`);
|
|
8629
8630
|
page.on("response", onResponse);
|
|
8630
8631
|
}
|
|
8632
|
+
if (share.mode === "custom") {
|
|
8633
|
+
logger15.info("\u5F53\u524D\u4E3A custom \u6A21\u5F0F\uFF0C\u5C06\u4F7F\u7528 performActions \u8FD4\u56DE\u503C");
|
|
8634
|
+
}
|
|
8631
8635
|
const deadline = Date.now() + timeoutMs;
|
|
8632
8636
|
const getRemainingMs = () => Math.max(0, deadline - Date.now());
|
|
8633
8637
|
try {
|
|
8634
8638
|
const actionTimeout = getRemainingMs();
|
|
8635
8639
|
logger15.start("captureLink.performActions", `\u6267\u884C\u52A8\u4F5C\u9884\u7B97=${actionTimeout}ms`);
|
|
8640
|
+
let actionValue;
|
|
8636
8641
|
if (actionTimeout > 0) {
|
|
8637
8642
|
let timer = null;
|
|
8638
|
-
|
|
8639
|
-
const actionPromise = Promise.resolve().then(() => performActions()).then(() => "__ACTION_DONE__").catch((error) => {
|
|
8640
|
-
actionError = error;
|
|
8641
|
-
return "__ACTION_ERROR__";
|
|
8642
|
-
});
|
|
8643
|
+
const actionPromise = Promise.resolve().then(() => performActions()).then((result) => ({ type: "done", result })).catch((error) => ({ type: "error", error }));
|
|
8643
8644
|
const timeoutPromise = new Promise((resolve) => {
|
|
8644
|
-
timer = setTimeout(() => resolve("
|
|
8645
|
+
timer = setTimeout(() => resolve({ type: "timeout" }), actionTimeout);
|
|
8645
8646
|
});
|
|
8646
8647
|
const actionResult = await Promise.race([actionPromise, timeoutPromise]);
|
|
8647
8648
|
if (timer) clearTimeout(timer);
|
|
8648
|
-
if (actionResult === "
|
|
8649
|
-
logger15.fail("captureLink.performActions",
|
|
8650
|
-
throw
|
|
8649
|
+
if (actionResult.type === "error") {
|
|
8650
|
+
logger15.fail("captureLink.performActions", actionResult.error);
|
|
8651
|
+
throw actionResult.error;
|
|
8651
8652
|
}
|
|
8652
|
-
if (actionResult === "
|
|
8653
|
+
if (actionResult.type === "timeout") {
|
|
8653
8654
|
stats.actionTimedOut = true;
|
|
8654
8655
|
logger15.warning(`performActions \u5DF2\u8D85\u65F6 (${actionTimeout}ms)\uFF0C\u52A8\u4F5C\u53EF\u80FD\u4ECD\u5728\u5F02\u6B65\u6267\u884C`);
|
|
8655
8656
|
} else {
|
|
8657
|
+
actionValue = actionResult.result;
|
|
8656
8658
|
logger15.success("captureLink.performActions", "\u6267\u884C\u52A8\u4F5C\u5B8C\u6210");
|
|
8657
8659
|
}
|
|
8658
8660
|
}
|
|
8661
|
+
if (share.mode === "custom") {
|
|
8662
|
+
const customLink = typeof actionValue === "string" ? actionValue : actionValue?.link || actionValue?.payloadText;
|
|
8663
|
+
const customPayloadText = typeof actionValue === "string" ? actionValue : actionValue?.payloadText;
|
|
8664
|
+
if (setCandidate("custom", customLink, customPayloadText)) {
|
|
8665
|
+
logger15.success("captureLink.customResult", `custom \u547D\u4E2D\u5206\u4EAB\u94FE\u63A5: link=${candidates.custom.link}`);
|
|
8666
|
+
} else {
|
|
8667
|
+
logger15.warning("performActions \u6267\u884C\u5B8C\u6210\u4F46\u672A\u8FD4\u56DE\u6709\u6548\u5206\u4EAB\u94FE\u63A5");
|
|
8668
|
+
}
|
|
8669
|
+
}
|
|
8659
8670
|
let nextProgressLogTs = Date.now() + 3e3;
|
|
8660
8671
|
while (true) {
|
|
8661
|
-
const selected = share.mode
|
|
8672
|
+
const selected = candidates[share.mode];
|
|
8662
8673
|
if (selected?.link) {
|
|
8663
8674
|
logger15.success("captureLink", `\u6355\u83B7\u6210\u529F: source=${share.mode}, link=${selected.link}`);
|
|
8664
8675
|
return {
|
|
@@ -8668,6 +8679,7 @@ var Share = {
|
|
|
8668
8679
|
source: share.mode
|
|
8669
8680
|
};
|
|
8670
8681
|
}
|
|
8682
|
+
if (share.mode === "custom") break;
|
|
8671
8683
|
const remaining = getRemainingMs();
|
|
8672
8684
|
if (remaining <= 0) break;
|
|
8673
8685
|
const now = Date.now();
|