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.d.cts CHANGED
@@ -726,14 +726,15 @@ declare class CrawlPage {
726
726
  *
727
727
  * @param x - X coordinate in CSS pixels
728
728
  * @param y - Y coordinate in CSS pixels
729
- * @param opts - Options (holdMs: hold duration, default 1000, max 30000)
729
+ * @param opts - Options (delay: ms before press, holdMs: hold duration)
730
730
  *
731
731
  * @example
732
732
  * ```ts
733
- * await page.pressAndHold(400, 300, { holdMs: 5000 });
733
+ * await page.pressAndHold(400, 300, { delay: 150, holdMs: 5000 });
734
734
  * ```
735
735
  */
736
736
  pressAndHold(x: number, y: number, opts?: {
737
+ delay?: number;
737
738
  holdMs?: number;
738
739
  }): Promise<void>;
739
740
  /**
@@ -1741,6 +1742,7 @@ declare function pressAndHoldViaCdp(opts: {
1741
1742
  targetId?: string;
1742
1743
  x: number;
1743
1744
  y: number;
1745
+ delay?: number;
1744
1746
  holdMs?: number;
1745
1747
  }): Promise<void>;
1746
1748
 
package/dist/index.d.ts CHANGED
@@ -726,14 +726,15 @@ declare class CrawlPage {
726
726
  *
727
727
  * @param x - X coordinate in CSS pixels
728
728
  * @param y - Y coordinate in CSS pixels
729
- * @param opts - Options (holdMs: hold duration, default 1000, max 30000)
729
+ * @param opts - Options (delay: ms before press, holdMs: hold duration)
730
730
  *
731
731
  * @example
732
732
  * ```ts
733
- * await page.pressAndHold(400, 300, { holdMs: 5000 });
733
+ * await page.pressAndHold(400, 300, { delay: 150, holdMs: 5000 });
734
734
  * ```
735
735
  */
736
736
  pressAndHold(x: number, y: number, opts?: {
737
+ delay?: number;
737
738
  holdMs?: number;
738
739
  }): Promise<void>;
739
740
  /**
@@ -1741,6 +1742,7 @@ declare function pressAndHoldViaCdp(opts: {
1741
1742
  targetId?: string;
1742
1743
  x: number;
1743
1744
  y: number;
1745
+ delay?: number;
1744
1746
  holdMs?: number;
1745
1747
  }): Promise<void>;
1746
1748
 
package/dist/index.js CHANGED
@@ -1719,9 +1719,11 @@ async function withPlaywrightPageCdpSession(page, fn) {
1719
1719
  const CDP_SESSION_TIMEOUT_MS = 1e4;
1720
1720
  const session = await Promise.race([
1721
1721
  page.context().newCDPSession(page),
1722
- new Promise(
1723
- (_, reject) => setTimeout(() => reject(new Error("newCDPSession timed out after 10s")), CDP_SESSION_TIMEOUT_MS)
1724
- )
1722
+ new Promise((_, reject) => {
1723
+ setTimeout(() => {
1724
+ reject(new Error("newCDPSession timed out after 10s"));
1725
+ }, CDP_SESSION_TIMEOUT_MS);
1726
+ })
1725
1727
  ]);
1726
1728
  try {
1727
1729
  return await fn(session);
@@ -3074,30 +3076,20 @@ async function mouseClickViaPlaywright(opts) {
3074
3076
  delay: opts.delayMs
3075
3077
  });
3076
3078
  }
3077
- var MAX_HOLD_MS = 3e4;
3078
3079
  async function pressAndHoldViaCdp(opts) {
3079
- const holdMs = resolveBoundedDelayMs(opts.holdMs ?? 1e3, "holdMs", MAX_HOLD_MS);
3080
3080
  const page = await getPageForTargetId({ cdpUrl: opts.cdpUrl, targetId: opts.targetId });
3081
3081
  ensurePageState(page);
3082
- const pos = { x: opts.x, y: opts.y };
3083
- const btn = { button: "left", clickCount: 1 };
3082
+ const { x, y } = opts;
3084
3083
  await withPageScopedCdpClient({
3085
3084
  cdpUrl: opts.cdpUrl,
3086
3085
  page,
3087
3086
  targetId: opts.targetId,
3088
3087
  fn: async (send) => {
3089
- await send("Input.dispatchMouseEvent", { type: "mouseMoved", ...pos });
3090
- await send("Input.dispatchTouchEvent", {
3091
- type: "touchStart",
3092
- touchPoints: [{ x: pos.x, y: pos.y, id: 1 }]
3093
- });
3094
- await send("Input.dispatchMouseEvent", { type: "mousePressed", ...pos, ...btn });
3095
- await new Promise((r) => setTimeout(r, holdMs));
3096
- await send("Input.dispatchMouseEvent", { type: "mouseReleased", ...pos, ...btn });
3097
- await send("Input.dispatchTouchEvent", {
3098
- type: "touchEnd",
3099
- touchPoints: [{ x: pos.x, y: pos.y, id: 1 }]
3100
- });
3088
+ await send("Input.dispatchMouseEvent", { type: "mouseMoved", x, y, button: "none" });
3089
+ if (opts.delay !== void 0 && opts.delay !== 0) await new Promise((r) => setTimeout(r, opts.delay));
3090
+ await send("Input.dispatchMouseEvent", { type: "mousePressed", x, y, button: "left", clickCount: 1 });
3091
+ if (opts.holdMs !== void 0 && opts.holdMs !== 0) await new Promise((r) => setTimeout(r, opts.holdMs));
3092
+ await send("Input.dispatchMouseEvent", { type: "mouseReleased", x, y, button: "left", clickCount: 1 });
3101
3093
  }
3102
3094
  });
3103
3095
  }
@@ -4963,11 +4955,11 @@ var CrawlPage = class {
4963
4955
  *
4964
4956
  * @param x - X coordinate in CSS pixels
4965
4957
  * @param y - Y coordinate in CSS pixels
4966
- * @param opts - Options (holdMs: hold duration, default 1000, max 30000)
4958
+ * @param opts - Options (delay: ms before press, holdMs: hold duration)
4967
4959
  *
4968
4960
  * @example
4969
4961
  * ```ts
4970
- * await page.pressAndHold(400, 300, { holdMs: 5000 });
4962
+ * await page.pressAndHold(400, 300, { delay: 150, holdMs: 5000 });
4971
4963
  * ```
4972
4964
  */
4973
4965
  async pressAndHold(x, y, opts) {
@@ -4976,6 +4968,7 @@ var CrawlPage = class {
4976
4968
  targetId: this.targetId,
4977
4969
  x,
4978
4970
  y,
4971
+ delay: opts?.delay,
4979
4972
  holdMs: opts?.holdMs
4980
4973
  });
4981
4974
  }