@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.cjs
CHANGED
|
@@ -4720,6 +4720,29 @@ var buildActionOptions = (options = {}) => {
|
|
|
4720
4720
|
}
|
|
4721
4721
|
return actionOptions;
|
|
4722
4722
|
};
|
|
4723
|
+
var getErrorMessage = (error) => {
|
|
4724
|
+
if (typeof error === "string") return error;
|
|
4725
|
+
if (error && typeof error.message === "string") return error.message;
|
|
4726
|
+
return String(error ?? "");
|
|
4727
|
+
};
|
|
4728
|
+
var isPointerEventsCoveredError = (error) => {
|
|
4729
|
+
const message = getErrorMessage(error).toLowerCase();
|
|
4730
|
+
return message.includes("pointer_events") && (message.includes("covered by") || message.includes("receiving events"));
|
|
4731
|
+
};
|
|
4732
|
+
var withPointerEventsForceFallback = async (label, options, operation) => {
|
|
4733
|
+
try {
|
|
4734
|
+
return await operation(options);
|
|
4735
|
+
} catch (error) {
|
|
4736
|
+
if (options?.force || !isPointerEventsCoveredError(error)) {
|
|
4737
|
+
throw error;
|
|
4738
|
+
}
|
|
4739
|
+
logger7.warn(`${label}: cloakbrowser pointer_events check failed, retrying with force=true (${getErrorMessage(error)})`);
|
|
4740
|
+
return await operation({
|
|
4741
|
+
...options || {},
|
|
4742
|
+
force: true
|
|
4743
|
+
});
|
|
4744
|
+
}
|
|
4745
|
+
};
|
|
4723
4746
|
var ensureDesktopHumanized = async (page) => {
|
|
4724
4747
|
if (!page || typeof page !== "object") {
|
|
4725
4748
|
throw new Error("Humanize requires a Playwright page");
|
|
@@ -4797,53 +4820,55 @@ var humanMoveToPoint = async (page, point) => {
|
|
|
4797
4820
|
};
|
|
4798
4821
|
var doDesktopHumanClick = async (page, target, options = {}) => {
|
|
4799
4822
|
await ensureDesktopHumanized(page);
|
|
4800
|
-
|
|
4801
|
-
|
|
4802
|
-
|
|
4803
|
-
|
|
4804
|
-
}
|
|
4805
|
-
if (isPoint2(target)) {
|
|
4806
|
-
return humanMoveToPoint(page, target).then(async () => {
|
|
4807
|
-
await page.mouse.click(Number(target.x), Number(target.y));
|
|
4808
|
-
return true;
|
|
4809
|
-
});
|
|
4810
|
-
}
|
|
4811
|
-
const throwOnMissing = options.throwOnMissing !== false;
|
|
4812
|
-
if (typeof target === "string") {
|
|
4813
|
-
if (!throwOnMissing) {
|
|
4814
|
-
const existingHandle = await page.$(target);
|
|
4815
|
-
if (!existingHandle) {
|
|
4816
|
-
return false;
|
|
4817
|
-
}
|
|
4818
|
-
await existingHandle.click(buildActionOptions(options));
|
|
4823
|
+
return await withPointerEventsForceFallback("humanClick", options, async (effectiveOptions = {}) => {
|
|
4824
|
+
if (target == null) {
|
|
4825
|
+
const cursor = page._humanCursor || { x: 0, y: 0 };
|
|
4826
|
+
await page.mouse.click(cursor.x || 0, cursor.y || 0);
|
|
4819
4827
|
return true;
|
|
4820
4828
|
}
|
|
4821
|
-
|
|
4822
|
-
|
|
4823
|
-
|
|
4824
|
-
|
|
4825
|
-
|
|
4826
|
-
if (!resolvedTarget) {
|
|
4827
|
-
return false;
|
|
4829
|
+
if (isPoint2(target)) {
|
|
4830
|
+
return humanMoveToPoint(page, target).then(async () => {
|
|
4831
|
+
await page.mouse.click(Number(target.x), Number(target.y));
|
|
4832
|
+
return true;
|
|
4833
|
+
});
|
|
4828
4834
|
}
|
|
4829
|
-
|
|
4830
|
-
|
|
4835
|
+
const throwOnMissing = effectiveOptions.throwOnMissing !== false;
|
|
4836
|
+
if (typeof target === "string") {
|
|
4837
|
+
if (!throwOnMissing) {
|
|
4838
|
+
const existingHandle = await page.$(target);
|
|
4839
|
+
if (!existingHandle) {
|
|
4840
|
+
return false;
|
|
4841
|
+
}
|
|
4842
|
+
await existingHandle.click(buildActionOptions(effectiveOptions));
|
|
4843
|
+
return true;
|
|
4844
|
+
}
|
|
4845
|
+
await page.click(target, buildActionOptions(effectiveOptions));
|
|
4831
4846
|
return true;
|
|
4832
4847
|
}
|
|
4833
|
-
const
|
|
4834
|
-
|
|
4835
|
-
if (
|
|
4836
|
-
|
|
4848
|
+
const { target: resolvedTarget, dispose } = await resolvePatchedTarget(page, target, { throwOnMissing });
|
|
4849
|
+
try {
|
|
4850
|
+
if (!resolvedTarget) {
|
|
4851
|
+
return false;
|
|
4852
|
+
}
|
|
4853
|
+
if (typeof resolvedTarget.click === "function") {
|
|
4854
|
+
await resolvedTarget.click(buildActionOptions(effectiveOptions));
|
|
4855
|
+
return true;
|
|
4856
|
+
}
|
|
4857
|
+
const box = await resolvedTarget.boundingBox?.();
|
|
4858
|
+
if (!box) {
|
|
4859
|
+
if (throwOnMissing) {
|
|
4860
|
+
throw new Error("\u65E0\u6CD5\u83B7\u53D6\u5143\u7D20\u4F4D\u7F6E");
|
|
4861
|
+
}
|
|
4862
|
+
return false;
|
|
4863
|
+
}
|
|
4864
|
+
await page.mouse.click(box.x + box.width / 2, box.y + box.height / 2);
|
|
4865
|
+
return true;
|
|
4866
|
+
} finally {
|
|
4867
|
+
if (typeof dispose === "function") {
|
|
4868
|
+
await dispose();
|
|
4837
4869
|
}
|
|
4838
|
-
return false;
|
|
4839
|
-
}
|
|
4840
|
-
await page.mouse.click(box.x + box.width / 2, box.y + box.height / 2);
|
|
4841
|
-
return true;
|
|
4842
|
-
} finally {
|
|
4843
|
-
if (typeof dispose === "function") {
|
|
4844
|
-
await dispose();
|
|
4845
4870
|
}
|
|
4846
|
-
}
|
|
4871
|
+
});
|
|
4847
4872
|
};
|
|
4848
4873
|
var CloakBrowserHumanize = {
|
|
4849
4874
|
jitterMs(base, jitterPercent = 0.3) {
|
|
@@ -4972,22 +4997,24 @@ var CloakBrowserHumanize = {
|
|
|
4972
4997
|
return await MobileHumanize.humanType(page, selector, text, options);
|
|
4973
4998
|
}
|
|
4974
4999
|
await ensureDesktopHumanized(page);
|
|
4975
|
-
|
|
4976
|
-
|
|
4977
|
-
|
|
4978
|
-
|
|
4979
|
-
|
|
4980
|
-
const { target: resolvedTarget, dispose } = await resolvePatchedTarget(page, selector, { throwOnMissing: true });
|
|
4981
|
-
try {
|
|
4982
|
-
if (!resolvedTarget || typeof resolvedTarget.type !== "function") {
|
|
4983
|
-
throw new Error("\u76EE\u6807\u5143\u7D20\u4E0D\u652F\u6301 type()");
|
|
5000
|
+
await withPointerEventsForceFallback("humanType", options, async (effectiveOptions = {}) => {
|
|
5001
|
+
const actionOptions = buildActionOptions(effectiveOptions);
|
|
5002
|
+
if (typeof selector === "string") {
|
|
5003
|
+
await page.type(selector, text, actionOptions);
|
|
5004
|
+
return;
|
|
4984
5005
|
}
|
|
4985
|
-
await
|
|
4986
|
-
|
|
4987
|
-
|
|
4988
|
-
|
|
5006
|
+
const { target: resolvedTarget, dispose } = await resolvePatchedTarget(page, selector, { throwOnMissing: true });
|
|
5007
|
+
try {
|
|
5008
|
+
if (!resolvedTarget || typeof resolvedTarget.type !== "function") {
|
|
5009
|
+
throw new Error("\u76EE\u6807\u5143\u7D20\u4E0D\u652F\u6301 type()");
|
|
5010
|
+
}
|
|
5011
|
+
await resolvedTarget.type(text, actionOptions);
|
|
5012
|
+
} finally {
|
|
5013
|
+
if (typeof dispose === "function") {
|
|
5014
|
+
await dispose();
|
|
5015
|
+
}
|
|
4989
5016
|
}
|
|
4990
|
-
}
|
|
5017
|
+
});
|
|
4991
5018
|
},
|
|
4992
5019
|
async humanPress(page, targetOrKey, maybeKey, options = {}) {
|
|
4993
5020
|
if (isMobilePage(page)) {
|
|
@@ -5005,36 +5032,38 @@ var CloakBrowserHumanize = {
|
|
|
5005
5032
|
});
|
|
5006
5033
|
return true;
|
|
5007
5034
|
}
|
|
5008
|
-
|
|
5009
|
-
|
|
5010
|
-
|
|
5011
|
-
}
|
|
5012
|
-
const { target: resolvedTarget, dispose } = await resolvePatchedTarget(page, targetOrKey, {
|
|
5013
|
-
throwOnMissing: pressOptions.throwOnMissing !== false
|
|
5014
|
-
});
|
|
5015
|
-
try {
|
|
5016
|
-
if (!resolvedTarget) {
|
|
5017
|
-
return false;
|
|
5018
|
-
}
|
|
5019
|
-
if (typeof resolvedTarget.press === "function") {
|
|
5020
|
-
await resolvedTarget.press(key, buildActionOptions(pressOptions));
|
|
5035
|
+
return await withPointerEventsForceFallback("humanPress", pressOptions, async (effectiveOptions = {}) => {
|
|
5036
|
+
if (typeof targetOrKey === "string") {
|
|
5037
|
+
await page.press(targetOrKey, key, buildActionOptions(effectiveOptions));
|
|
5021
5038
|
return true;
|
|
5022
5039
|
}
|
|
5023
|
-
await
|
|
5024
|
-
|
|
5025
|
-
reactionDelay: pressOptions.focusDelay ?? 180
|
|
5026
|
-
});
|
|
5027
|
-
await jitterSleep(pressOptions.reactionDelay ?? 180, 0.45);
|
|
5028
|
-
await page.keyboard.press(key, {
|
|
5029
|
-
...pressOptions.keyboardOptions || {},
|
|
5030
|
-
delay: jitterMs(pressOptions.holdDelay ?? 45, 0.5)
|
|
5040
|
+
const { target: resolvedTarget, dispose } = await resolvePatchedTarget(page, targetOrKey, {
|
|
5041
|
+
throwOnMissing: effectiveOptions.throwOnMissing !== false
|
|
5031
5042
|
});
|
|
5032
|
-
|
|
5033
|
-
|
|
5034
|
-
|
|
5035
|
-
|
|
5043
|
+
try {
|
|
5044
|
+
if (!resolvedTarget) {
|
|
5045
|
+
return false;
|
|
5046
|
+
}
|
|
5047
|
+
if (typeof resolvedTarget.press === "function") {
|
|
5048
|
+
await resolvedTarget.press(key, buildActionOptions(effectiveOptions));
|
|
5049
|
+
return true;
|
|
5050
|
+
}
|
|
5051
|
+
await doDesktopHumanClick(page, targetOrKey, {
|
|
5052
|
+
...effectiveOptions,
|
|
5053
|
+
reactionDelay: effectiveOptions.focusDelay ?? 180
|
|
5054
|
+
});
|
|
5055
|
+
await jitterSleep(effectiveOptions.reactionDelay ?? 180, 0.45);
|
|
5056
|
+
await page.keyboard.press(key, {
|
|
5057
|
+
...effectiveOptions.keyboardOptions || {},
|
|
5058
|
+
delay: jitterMs(effectiveOptions.holdDelay ?? 45, 0.5)
|
|
5059
|
+
});
|
|
5060
|
+
return true;
|
|
5061
|
+
} finally {
|
|
5062
|
+
if (typeof dispose === "function") {
|
|
5063
|
+
await dispose();
|
|
5064
|
+
}
|
|
5036
5065
|
}
|
|
5037
|
-
}
|
|
5066
|
+
});
|
|
5038
5067
|
},
|
|
5039
5068
|
async humanClear(page, selector) {
|
|
5040
5069
|
if (isMobilePage(page)) {
|