browserclaw 0.9.6 → 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 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
- (_, reject) => setTimeout(() => reject(new Error("newCDPSession timed out after 10s")), CDP_SESSION_TIMEOUT_MS)
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,30 +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 pos = { x: opts.x, y: opts.y };
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", ...pos });
3101
- await send("Input.dispatchTouchEvent", {
3102
- type: "touchStart",
3103
- touchPoints: [{ x: pos.x, y: pos.y, id: 1 }]
3104
- });
3105
- await send("Input.dispatchMouseEvent", { type: "mousePressed", ...pos, ...btn });
3106
- await new Promise((r) => setTimeout(r, holdMs));
3107
- await send("Input.dispatchMouseEvent", { type: "mouseReleased", ...pos, ...btn });
3108
- await send("Input.dispatchTouchEvent", {
3109
- type: "touchEnd",
3110
- touchPoints: [{ x: pos.x, y: pos.y, id: 1 }]
3111
- });
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 });
3112
3104
  }
3113
3105
  });
3114
3106
  }
@@ -4974,11 +4966,11 @@ var CrawlPage = class {
4974
4966
  *
4975
4967
  * @param x - X coordinate in CSS pixels
4976
4968
  * @param y - Y coordinate in CSS pixels
4977
- * @param opts - Options (holdMs: hold duration, default 1000, max 30000)
4969
+ * @param opts - Options (delay: ms before press, holdMs: hold duration)
4978
4970
  *
4979
4971
  * @example
4980
4972
  * ```ts
4981
- * await page.pressAndHold(400, 300, { holdMs: 5000 });
4973
+ * await page.pressAndHold(400, 300, { delay: 150, holdMs: 5000 });
4982
4974
  * ```
4983
4975
  */
4984
4976
  async pressAndHold(x, y, opts) {
@@ -4987,6 +4979,7 @@ var CrawlPage = class {
4987
4979
  targetId: this.targetId,
4988
4980
  x,
4989
4981
  y,
4982
+ delay: opts?.delay,
4990
4983
  holdMs: opts?.holdMs
4991
4984
  });
4992
4985
  }