browserclaw 0.9.5 → 0.9.7
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 +14 -13
- package/dist/index.cjs.map +1 -1
- package/dist/index.d.cts +4 -2
- package/dist/index.d.ts +4 -2
- package/dist/index.js +14 -13
- package/dist/index.js.map +1 -1
- package/package.json +1 -1
package/dist/index.cjs
CHANGED
|
@@ -1730,9 +1730,11 @@ async function withPlaywrightPageCdpSession(page, fn) {
|
|
|
1730
1730
|
const CDP_SESSION_TIMEOUT_MS = 1e4;
|
|
1731
1731
|
const session = await Promise.race([
|
|
1732
1732
|
page.context().newCDPSession(page),
|
|
1733
|
-
new Promise(
|
|
1734
|
-
|
|
1735
|
-
|
|
1733
|
+
new Promise((_, reject) => {
|
|
1734
|
+
setTimeout(() => {
|
|
1735
|
+
reject(new Error("newCDPSession timed out after 10s"));
|
|
1736
|
+
}, CDP_SESSION_TIMEOUT_MS);
|
|
1737
|
+
})
|
|
1736
1738
|
]);
|
|
1737
1739
|
try {
|
|
1738
1740
|
return await fn(session);
|
|
@@ -3085,22 +3087,20 @@ async function mouseClickViaPlaywright(opts) {
|
|
|
3085
3087
|
delay: opts.delayMs
|
|
3086
3088
|
});
|
|
3087
3089
|
}
|
|
3088
|
-
var MAX_HOLD_MS = 3e4;
|
|
3089
3090
|
async function pressAndHoldViaCdp(opts) {
|
|
3090
|
-
const holdMs = resolveBoundedDelayMs(opts.holdMs ?? 1e3, "holdMs", MAX_HOLD_MS);
|
|
3091
3091
|
const page = await getPageForTargetId({ cdpUrl: opts.cdpUrl, targetId: opts.targetId });
|
|
3092
3092
|
ensurePageState(page);
|
|
3093
|
-
const
|
|
3094
|
-
const btn = { button: "left", clickCount: 1 };
|
|
3093
|
+
const { x, y } = opts;
|
|
3095
3094
|
await withPageScopedCdpClient({
|
|
3096
3095
|
cdpUrl: opts.cdpUrl,
|
|
3097
3096
|
page,
|
|
3098
3097
|
targetId: opts.targetId,
|
|
3099
3098
|
fn: async (send) => {
|
|
3100
|
-
await send("Input.dispatchMouseEvent", { type: "mouseMoved",
|
|
3101
|
-
|
|
3102
|
-
await
|
|
3103
|
-
|
|
3099
|
+
await send("Input.dispatchMouseEvent", { type: "mouseMoved", x, y, button: "none" });
|
|
3100
|
+
if (opts.delay !== void 0 && opts.delay !== 0) await new Promise((r) => setTimeout(r, opts.delay));
|
|
3101
|
+
await send("Input.dispatchMouseEvent", { type: "mousePressed", x, y, button: "left", clickCount: 1 });
|
|
3102
|
+
if (opts.holdMs !== void 0 && opts.holdMs !== 0) await new Promise((r) => setTimeout(r, opts.holdMs));
|
|
3103
|
+
await send("Input.dispatchMouseEvent", { type: "mouseReleased", x, y, button: "left", clickCount: 1 });
|
|
3104
3104
|
}
|
|
3105
3105
|
});
|
|
3106
3106
|
}
|
|
@@ -4966,11 +4966,11 @@ var CrawlPage = class {
|
|
|
4966
4966
|
*
|
|
4967
4967
|
* @param x - X coordinate in CSS pixels
|
|
4968
4968
|
* @param y - Y coordinate in CSS pixels
|
|
4969
|
-
* @param opts - Options (
|
|
4969
|
+
* @param opts - Options (delay: ms before press, holdMs: hold duration)
|
|
4970
4970
|
*
|
|
4971
4971
|
* @example
|
|
4972
4972
|
* ```ts
|
|
4973
|
-
* await page.pressAndHold(400, 300, { holdMs: 5000 });
|
|
4973
|
+
* await page.pressAndHold(400, 300, { delay: 150, holdMs: 5000 });
|
|
4974
4974
|
* ```
|
|
4975
4975
|
*/
|
|
4976
4976
|
async pressAndHold(x, y, opts) {
|
|
@@ -4979,6 +4979,7 @@ var CrawlPage = class {
|
|
|
4979
4979
|
targetId: this.targetId,
|
|
4980
4980
|
x,
|
|
4981
4981
|
y,
|
|
4982
|
+
delay: opts?.delay,
|
|
4982
4983
|
holdMs: opts?.holdMs
|
|
4983
4984
|
});
|
|
4984
4985
|
}
|