browserclaw 0.9.3 → 0.9.4

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
@@ -48,9 +48,9 @@ var __toESM = (mod, isNodeMode, target) => (target = mod != null ? __create(__ge
48
48
  mod
49
49
  ));
50
50
 
51
- // ../../../node_modules/ipaddr.js/lib/ipaddr.js
51
+ // node_modules/ipaddr.js/lib/ipaddr.js
52
52
  var require_ipaddr = __commonJS({
53
- "../../../node_modules/ipaddr.js/lib/ipaddr.js"(exports$1, module) {
53
+ "node_modules/ipaddr.js/lib/ipaddr.js"(exports$1, module) {
54
54
  (function(root) {
55
55
  const ipv4Part = "(0?\\d+|0x[a-f0-9]+)";
56
56
  const ipv4Regexes = {
@@ -1388,6 +1388,7 @@ async function launchChrome(opts = {}) {
1388
1388
  const spawnChrome = () => {
1389
1389
  const args = [
1390
1390
  `--remote-debugging-port=${String(cdpPort)}`,
1391
+ "--remote-debugging-address=127.0.0.1",
1391
1392
  `--user-data-dir=${userDataDir}`,
1392
1393
  "--no-first-run",
1393
1394
  "--no-default-browser-check",
@@ -3078,6 +3079,25 @@ async function mouseClickViaPlaywright(opts) {
3078
3079
  delay: opts.delayMs
3079
3080
  });
3080
3081
  }
3082
+ var MAX_HOLD_MS = 3e4;
3083
+ async function pressAndHoldViaCdp(opts) {
3084
+ const holdMs = resolveBoundedDelayMs(opts.holdMs ?? 1e3, "holdMs", MAX_HOLD_MS);
3085
+ const page = await getPageForTargetId({ cdpUrl: opts.cdpUrl, targetId: opts.targetId });
3086
+ ensurePageState(page);
3087
+ const pos = { x: opts.x, y: opts.y };
3088
+ const btn = { button: "left", clickCount: 1 };
3089
+ await withPageScopedCdpClient({
3090
+ cdpUrl: opts.cdpUrl,
3091
+ page,
3092
+ targetId: opts.targetId,
3093
+ fn: async (send) => {
3094
+ await send("Input.dispatchMouseEvent", { type: "mouseMoved", ...pos });
3095
+ await send("Input.dispatchMouseEvent", { type: "mousePressed", ...pos, ...btn });
3096
+ await new Promise((r) => setTimeout(r, holdMs));
3097
+ await send("Input.dispatchMouseEvent", { type: "mouseReleased", ...pos, ...btn });
3098
+ }
3099
+ });
3100
+ }
3081
3101
  async function clickByTextViaPlaywright(opts) {
3082
3102
  const page = await getRestoredPageForTarget(opts);
3083
3103
  const timeout = resolveInteractionTimeoutMs(opts.timeoutMs);
@@ -3448,7 +3468,12 @@ async function closePageViaPlaywright(opts) {
3448
3468
  await page.close();
3449
3469
  }
3450
3470
  async function closePageByTargetIdViaPlaywright(opts) {
3451
- await (await resolvePageByTargetIdOrThrow(opts)).close();
3471
+ try {
3472
+ await (await resolvePageByTargetIdOrThrow(opts)).close();
3473
+ } catch (err) {
3474
+ if (err instanceof BrowserTabNotFoundError) return;
3475
+ throw err;
3476
+ }
3452
3477
  }
3453
3478
  async function focusPageByTargetIdViaPlaywright(opts) {
3454
3479
  const page = await resolvePageByTargetIdOrThrow(opts);
@@ -4926,6 +4951,31 @@ var CrawlPage = class {
4926
4951
  delayMs: opts?.delayMs
4927
4952
  });
4928
4953
  }
4954
+ /**
4955
+ * Press and hold at page coordinates using raw CDP events.
4956
+ *
4957
+ * Bypasses Playwright's automation layer by dispatching CDP
4958
+ * `Input.dispatchMouseEvent` directly — useful for anti-bot challenges
4959
+ * that detect automated clicks.
4960
+ *
4961
+ * @param x - X coordinate in CSS pixels
4962
+ * @param y - Y coordinate in CSS pixels
4963
+ * @param opts - Options (holdMs: hold duration, default 1000, max 30000)
4964
+ *
4965
+ * @example
4966
+ * ```ts
4967
+ * await page.pressAndHold(400, 300, { holdMs: 5000 });
4968
+ * ```
4969
+ */
4970
+ async pressAndHold(x, y, opts) {
4971
+ return pressAndHoldViaCdp({
4972
+ cdpUrl: this.cdpUrl,
4973
+ targetId: this.targetId,
4974
+ x,
4975
+ y,
4976
+ holdMs: opts?.holdMs
4977
+ });
4978
+ }
4929
4979
  /**
4930
4980
  * Click an element by its visible text content (no snapshot/ref needed).
4931
4981
  *
@@ -6087,6 +6137,7 @@ exports.isChromeCdpReady = isChromeCdpReady;
6087
6137
  exports.isChromeReachable = isChromeReachable;
6088
6138
  exports.normalizeCdpHttpBaseForJsonEndpoints = normalizeCdpHttpBaseForJsonEndpoints;
6089
6139
  exports.parseRoleRef = parseRoleRef;
6140
+ exports.pressAndHoldViaCdp = pressAndHoldViaCdp;
6090
6141
  exports.requireRef = requireRef;
6091
6142
  exports.requireRefOrSelector = requireRefOrSelector;
6092
6143
  exports.requiresInspectableBrowserNavigationRedirects = requiresInspectableBrowserNavigationRedirects;