@skrillex1224/playwright-toolkit 2.1.277 → 2.1.278
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 +109 -80
- package/dist/index.cjs.map +2 -2
- package/dist/index.js +109 -80
- package/dist/index.js.map +2 -2
- package/package.json +1 -1
package/dist/index.js
CHANGED
|
@@ -4692,6 +4692,29 @@ var buildActionOptions = (options = {}) => {
|
|
|
4692
4692
|
}
|
|
4693
4693
|
return actionOptions;
|
|
4694
4694
|
};
|
|
4695
|
+
var getErrorMessage = (error) => {
|
|
4696
|
+
if (typeof error === "string") return error;
|
|
4697
|
+
if (error && typeof error.message === "string") return error.message;
|
|
4698
|
+
return String(error ?? "");
|
|
4699
|
+
};
|
|
4700
|
+
var isPointerEventsCoveredError = (error) => {
|
|
4701
|
+
const message = getErrorMessage(error).toLowerCase();
|
|
4702
|
+
return message.includes("pointer_events") && (message.includes("covered by") || message.includes("receiving events"));
|
|
4703
|
+
};
|
|
4704
|
+
var withPointerEventsForceFallback = async (label, options, operation) => {
|
|
4705
|
+
try {
|
|
4706
|
+
return await operation(options);
|
|
4707
|
+
} catch (error) {
|
|
4708
|
+
if (options?.force || !isPointerEventsCoveredError(error)) {
|
|
4709
|
+
throw error;
|
|
4710
|
+
}
|
|
4711
|
+
logger7.warn(`${label}: cloakbrowser pointer_events check failed, retrying with force=true (${getErrorMessage(error)})`);
|
|
4712
|
+
return await operation({
|
|
4713
|
+
...options || {},
|
|
4714
|
+
force: true
|
|
4715
|
+
});
|
|
4716
|
+
}
|
|
4717
|
+
};
|
|
4695
4718
|
var ensureDesktopHumanized = async (page) => {
|
|
4696
4719
|
if (!page || typeof page !== "object") {
|
|
4697
4720
|
throw new Error("Humanize requires a Playwright page");
|
|
@@ -4769,53 +4792,55 @@ var humanMoveToPoint = async (page, point) => {
|
|
|
4769
4792
|
};
|
|
4770
4793
|
var doDesktopHumanClick = async (page, target, options = {}) => {
|
|
4771
4794
|
await ensureDesktopHumanized(page);
|
|
4772
|
-
|
|
4773
|
-
|
|
4774
|
-
|
|
4775
|
-
|
|
4776
|
-
}
|
|
4777
|
-
if (isPoint2(target)) {
|
|
4778
|
-
return humanMoveToPoint(page, target).then(async () => {
|
|
4779
|
-
await page.mouse.click(Number(target.x), Number(target.y));
|
|
4780
|
-
return true;
|
|
4781
|
-
});
|
|
4782
|
-
}
|
|
4783
|
-
const throwOnMissing = options.throwOnMissing !== false;
|
|
4784
|
-
if (typeof target === "string") {
|
|
4785
|
-
if (!throwOnMissing) {
|
|
4786
|
-
const existingHandle = await page.$(target);
|
|
4787
|
-
if (!existingHandle) {
|
|
4788
|
-
return false;
|
|
4789
|
-
}
|
|
4790
|
-
await existingHandle.click(buildActionOptions(options));
|
|
4795
|
+
return await withPointerEventsForceFallback("humanClick", options, async (effectiveOptions = {}) => {
|
|
4796
|
+
if (target == null) {
|
|
4797
|
+
const cursor = page._humanCursor || { x: 0, y: 0 };
|
|
4798
|
+
await page.mouse.click(cursor.x || 0, cursor.y || 0);
|
|
4791
4799
|
return true;
|
|
4792
4800
|
}
|
|
4793
|
-
|
|
4794
|
-
|
|
4795
|
-
|
|
4796
|
-
|
|
4797
|
-
|
|
4798
|
-
if (!resolvedTarget) {
|
|
4799
|
-
return false;
|
|
4801
|
+
if (isPoint2(target)) {
|
|
4802
|
+
return humanMoveToPoint(page, target).then(async () => {
|
|
4803
|
+
await page.mouse.click(Number(target.x), Number(target.y));
|
|
4804
|
+
return true;
|
|
4805
|
+
});
|
|
4800
4806
|
}
|
|
4801
|
-
|
|
4802
|
-
|
|
4807
|
+
const throwOnMissing = effectiveOptions.throwOnMissing !== false;
|
|
4808
|
+
if (typeof target === "string") {
|
|
4809
|
+
if (!throwOnMissing) {
|
|
4810
|
+
const existingHandle = await page.$(target);
|
|
4811
|
+
if (!existingHandle) {
|
|
4812
|
+
return false;
|
|
4813
|
+
}
|
|
4814
|
+
await existingHandle.click(buildActionOptions(effectiveOptions));
|
|
4815
|
+
return true;
|
|
4816
|
+
}
|
|
4817
|
+
await page.click(target, buildActionOptions(effectiveOptions));
|
|
4803
4818
|
return true;
|
|
4804
4819
|
}
|
|
4805
|
-
const
|
|
4806
|
-
|
|
4807
|
-
if (
|
|
4808
|
-
|
|
4820
|
+
const { target: resolvedTarget, dispose } = await resolvePatchedTarget(page, target, { throwOnMissing });
|
|
4821
|
+
try {
|
|
4822
|
+
if (!resolvedTarget) {
|
|
4823
|
+
return false;
|
|
4824
|
+
}
|
|
4825
|
+
if (typeof resolvedTarget.click === "function") {
|
|
4826
|
+
await resolvedTarget.click(buildActionOptions(effectiveOptions));
|
|
4827
|
+
return true;
|
|
4828
|
+
}
|
|
4829
|
+
const box = await resolvedTarget.boundingBox?.();
|
|
4830
|
+
if (!box) {
|
|
4831
|
+
if (throwOnMissing) {
|
|
4832
|
+
throw new Error("\u65E0\u6CD5\u83B7\u53D6\u5143\u7D20\u4F4D\u7F6E");
|
|
4833
|
+
}
|
|
4834
|
+
return false;
|
|
4835
|
+
}
|
|
4836
|
+
await page.mouse.click(box.x + box.width / 2, box.y + box.height / 2);
|
|
4837
|
+
return true;
|
|
4838
|
+
} finally {
|
|
4839
|
+
if (typeof dispose === "function") {
|
|
4840
|
+
await dispose();
|
|
4809
4841
|
}
|
|
4810
|
-
return false;
|
|
4811
|
-
}
|
|
4812
|
-
await page.mouse.click(box.x + box.width / 2, box.y + box.height / 2);
|
|
4813
|
-
return true;
|
|
4814
|
-
} finally {
|
|
4815
|
-
if (typeof dispose === "function") {
|
|
4816
|
-
await dispose();
|
|
4817
4842
|
}
|
|
4818
|
-
}
|
|
4843
|
+
});
|
|
4819
4844
|
};
|
|
4820
4845
|
var CloakBrowserHumanize = {
|
|
4821
4846
|
jitterMs(base, jitterPercent = 0.3) {
|
|
@@ -4944,22 +4969,24 @@ var CloakBrowserHumanize = {
|
|
|
4944
4969
|
return await MobileHumanize.humanType(page, selector, text, options);
|
|
4945
4970
|
}
|
|
4946
4971
|
await ensureDesktopHumanized(page);
|
|
4947
|
-
|
|
4948
|
-
|
|
4949
|
-
|
|
4950
|
-
|
|
4951
|
-
|
|
4952
|
-
const { target: resolvedTarget, dispose } = await resolvePatchedTarget(page, selector, { throwOnMissing: true });
|
|
4953
|
-
try {
|
|
4954
|
-
if (!resolvedTarget || typeof resolvedTarget.type !== "function") {
|
|
4955
|
-
throw new Error("\u76EE\u6807\u5143\u7D20\u4E0D\u652F\u6301 type()");
|
|
4972
|
+
await withPointerEventsForceFallback("humanType", options, async (effectiveOptions = {}) => {
|
|
4973
|
+
const actionOptions = buildActionOptions(effectiveOptions);
|
|
4974
|
+
if (typeof selector === "string") {
|
|
4975
|
+
await page.type(selector, text, actionOptions);
|
|
4976
|
+
return;
|
|
4956
4977
|
}
|
|
4957
|
-
await
|
|
4958
|
-
|
|
4959
|
-
|
|
4960
|
-
|
|
4978
|
+
const { target: resolvedTarget, dispose } = await resolvePatchedTarget(page, selector, { throwOnMissing: true });
|
|
4979
|
+
try {
|
|
4980
|
+
if (!resolvedTarget || typeof resolvedTarget.type !== "function") {
|
|
4981
|
+
throw new Error("\u76EE\u6807\u5143\u7D20\u4E0D\u652F\u6301 type()");
|
|
4982
|
+
}
|
|
4983
|
+
await resolvedTarget.type(text, actionOptions);
|
|
4984
|
+
} finally {
|
|
4985
|
+
if (typeof dispose === "function") {
|
|
4986
|
+
await dispose();
|
|
4987
|
+
}
|
|
4961
4988
|
}
|
|
4962
|
-
}
|
|
4989
|
+
});
|
|
4963
4990
|
},
|
|
4964
4991
|
async humanPress(page, targetOrKey, maybeKey, options = {}) {
|
|
4965
4992
|
if (isMobilePage(page)) {
|
|
@@ -4977,36 +5004,38 @@ var CloakBrowserHumanize = {
|
|
|
4977
5004
|
});
|
|
4978
5005
|
return true;
|
|
4979
5006
|
}
|
|
4980
|
-
|
|
4981
|
-
|
|
4982
|
-
|
|
4983
|
-
}
|
|
4984
|
-
const { target: resolvedTarget, dispose } = await resolvePatchedTarget(page, targetOrKey, {
|
|
4985
|
-
throwOnMissing: pressOptions.throwOnMissing !== false
|
|
4986
|
-
});
|
|
4987
|
-
try {
|
|
4988
|
-
if (!resolvedTarget) {
|
|
4989
|
-
return false;
|
|
4990
|
-
}
|
|
4991
|
-
if (typeof resolvedTarget.press === "function") {
|
|
4992
|
-
await resolvedTarget.press(key, buildActionOptions(pressOptions));
|
|
5007
|
+
return await withPointerEventsForceFallback("humanPress", pressOptions, async (effectiveOptions = {}) => {
|
|
5008
|
+
if (typeof targetOrKey === "string") {
|
|
5009
|
+
await page.press(targetOrKey, key, buildActionOptions(effectiveOptions));
|
|
4993
5010
|
return true;
|
|
4994
5011
|
}
|
|
4995
|
-
await
|
|
4996
|
-
|
|
4997
|
-
reactionDelay: pressOptions.focusDelay ?? 180
|
|
4998
|
-
});
|
|
4999
|
-
await jitterSleep(pressOptions.reactionDelay ?? 180, 0.45);
|
|
5000
|
-
await page.keyboard.press(key, {
|
|
5001
|
-
...pressOptions.keyboardOptions || {},
|
|
5002
|
-
delay: jitterMs(pressOptions.holdDelay ?? 45, 0.5)
|
|
5012
|
+
const { target: resolvedTarget, dispose } = await resolvePatchedTarget(page, targetOrKey, {
|
|
5013
|
+
throwOnMissing: effectiveOptions.throwOnMissing !== false
|
|
5003
5014
|
});
|
|
5004
|
-
|
|
5005
|
-
|
|
5006
|
-
|
|
5007
|
-
|
|
5015
|
+
try {
|
|
5016
|
+
if (!resolvedTarget) {
|
|
5017
|
+
return false;
|
|
5018
|
+
}
|
|
5019
|
+
if (typeof resolvedTarget.press === "function") {
|
|
5020
|
+
await resolvedTarget.press(key, buildActionOptions(effectiveOptions));
|
|
5021
|
+
return true;
|
|
5022
|
+
}
|
|
5023
|
+
await doDesktopHumanClick(page, targetOrKey, {
|
|
5024
|
+
...effectiveOptions,
|
|
5025
|
+
reactionDelay: effectiveOptions.focusDelay ?? 180
|
|
5026
|
+
});
|
|
5027
|
+
await jitterSleep(effectiveOptions.reactionDelay ?? 180, 0.45);
|
|
5028
|
+
await page.keyboard.press(key, {
|
|
5029
|
+
...effectiveOptions.keyboardOptions || {},
|
|
5030
|
+
delay: jitterMs(effectiveOptions.holdDelay ?? 45, 0.5)
|
|
5031
|
+
});
|
|
5032
|
+
return true;
|
|
5033
|
+
} finally {
|
|
5034
|
+
if (typeof dispose === "function") {
|
|
5035
|
+
await dispose();
|
|
5036
|
+
}
|
|
5008
5037
|
}
|
|
5009
|
-
}
|
|
5038
|
+
});
|
|
5010
5039
|
},
|
|
5011
5040
|
async humanClear(page, selector) {
|
|
5012
5041
|
if (isMobilePage(page)) {
|