browserclaw 0.2.9 → 0.3.0

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
@@ -1413,7 +1413,7 @@ async function assertBrowserNavigationAllowed(opts) {
1413
1413
  const hostname = parsed.hostname.toLowerCase();
1414
1414
  if (allowedHostnames.some((h) => h.toLowerCase() === hostname)) return;
1415
1415
  }
1416
- if (await isInternalUrlResolved(opts.url)) {
1416
+ if (await isInternalUrlResolved(opts.url, opts.lookupFn)) {
1417
1417
  throw new InvalidBrowserNavigationUrlError(
1418
1418
  `Navigation to internal/loopback address blocked: "${opts.url}". Use ssrfPolicy: { allowPrivateNetwork: true } if this is intentional.`
1419
1419
  );
@@ -1541,7 +1541,7 @@ function isInternalUrl(url) {
1541
1541
  }
1542
1542
  return false;
1543
1543
  }
1544
- async function isInternalUrlResolved(url) {
1544
+ async function isInternalUrlResolved(url, lookupFn = promises.lookup) {
1545
1545
  if (isInternalUrl(url)) return true;
1546
1546
  let parsed;
1547
1547
  try {
@@ -1550,7 +1550,7 @@ async function isInternalUrlResolved(url) {
1550
1550
  return true;
1551
1551
  }
1552
1552
  try {
1553
- const { address } = await promises.lookup(parsed.hostname);
1553
+ const { address } = await lookupFn(parsed.hostname);
1554
1554
  if (isInternalIP(address)) return true;
1555
1555
  } catch {
1556
1556
  return true;
@@ -1708,6 +1708,7 @@ async function evaluateViaPlaywright(opts) {
1708
1708
  const page = await getPageForTargetId({ cdpUrl: opts.cdpUrl, targetId: opts.targetId });
1709
1709
  ensurePageState(page);
1710
1710
  restoreRoleRefsForTarget({ cdpUrl: opts.cdpUrl, targetId: opts.targetId, page });
1711
+ const timeout = opts.timeoutMs != null ? opts.timeoutMs : void 0;
1711
1712
  if (opts.ref) {
1712
1713
  const locator = refLocator(page, opts.ref);
1713
1714
  return await locator.evaluate(
@@ -1720,10 +1721,11 @@ async function evaluateViaPlaywright(opts) {
1720
1721
  throw new Error("Invalid evaluate function: " + (err instanceof Error ? err.message : String(err)));
1721
1722
  }
1722
1723
  },
1723
- fnText
1724
+ fnText,
1725
+ { timeout }
1724
1726
  );
1725
1727
  }
1726
- return await page.evaluate(
1728
+ const evalPromise = page.evaluate(
1727
1729
  // eslint-disable-next-line no-eval
1728
1730
  (fnBody) => {
1729
1731
  try {
@@ -1735,6 +1737,13 @@ async function evaluateViaPlaywright(opts) {
1735
1737
  },
1736
1738
  fnText
1737
1739
  );
1740
+ if (!opts.signal) return evalPromise;
1741
+ return Promise.race([
1742
+ evalPromise,
1743
+ new Promise((_, reject) => {
1744
+ opts.signal.addEventListener("abort", () => reject(new Error("Evaluate aborted")), { once: true });
1745
+ })
1746
+ ]);
1738
1747
  }
1739
1748
 
1740
1749
  // src/actions/download.ts
@@ -2513,7 +2522,9 @@ var CrawlPage = class {
2513
2522
  cdpUrl: this.cdpUrl,
2514
2523
  targetId: this.targetId,
2515
2524
  fn,
2516
- ref: opts?.ref
2525
+ ref: opts?.ref,
2526
+ timeoutMs: opts?.timeoutMs,
2527
+ signal: opts?.signal
2517
2528
  });
2518
2529
  }
2519
2530
  /**
@@ -3109,6 +3120,7 @@ var BrowserClaw = class _BrowserClaw {
3109
3120
  exports.BrowserClaw = BrowserClaw;
3110
3121
  exports.CrawlPage = CrawlPage;
3111
3122
  exports.InvalidBrowserNavigationUrlError = InvalidBrowserNavigationUrlError;
3123
+ exports.assertBrowserNavigationAllowed = assertBrowserNavigationAllowed;
3112
3124
  exports.withBrowserNavigationPolicy = withBrowserNavigationPolicy;
3113
3125
  //# sourceMappingURL=index.cjs.map
3114
3126
  //# sourceMappingURL=index.cjs.map