browserclaw 0.3.3 → 0.3.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
@@ -751,12 +751,13 @@ async function getPageForTargetId(opts) {
751
751
  const found = await findPageByTargetId(browser, opts.targetId, opts.cdpUrl);
752
752
  if (!found) {
753
753
  if (pages.length === 1) return first;
754
- throw new Error("tab not found");
754
+ throw new Error(`Tab not found (targetId: ${opts.targetId}). Call browser.tabs() to list open tabs.`);
755
755
  }
756
756
  return found;
757
757
  }
758
758
  function refLocator(page, ref) {
759
759
  const normalized = ref.startsWith("@") ? ref.slice(1) : ref.startsWith("ref=") ? ref.slice(4) : ref;
760
+ if (!normalized.trim()) throw new Error("ref is required");
760
761
  if (/^e\d+$/.test(normalized)) {
761
762
  const state = pageStates.get(page);
762
763
  if (state?.roleRefsMode === "aria") {
@@ -1105,7 +1106,7 @@ async function snapshotRole(opts) {
1105
1106
  const frameSelector = opts.frameSelector?.trim() || "";
1106
1107
  const selector = opts.selector?.trim() || "";
1107
1108
  const locator = frameSelector ? selector ? page.frameLocator(frameSelector).locator(selector) : page.frameLocator(frameSelector).locator(":root") : selector ? page.locator(selector) : page.locator(":root");
1108
- const ariaSnapshot = await locator.ariaSnapshot({ timeout: 1e4 });
1109
+ const ariaSnapshot = await locator.ariaSnapshot({ timeout: normalizeTimeoutMs(opts.timeoutMs, 5e3) });
1109
1110
  const built = buildRoleSnapshotFromAriaSnapshot(String(ariaSnapshot ?? ""), opts.options);
1110
1111
  storeRoleRefsForTarget({
1111
1112
  page,
@@ -1834,7 +1835,7 @@ async function setGeolocationViaPlaywright(opts) {
1834
1835
  return;
1835
1836
  }
1836
1837
  if (opts.latitude === void 0 || opts.longitude === void 0) {
1837
- throw new Error("latitude and longitude are required when not clearing geolocation.");
1838
+ throw new Error("latitude and longitude are required (or set clear=true)");
1838
1839
  }
1839
1840
  await context.grantPermissions(["geolocation"], opts.origin ? { origin: opts.origin } : void 0);
1840
1841
  await context.setGeolocation({
@@ -1981,8 +1982,9 @@ async function responseBodyViaPlaywright(opts) {
1981
1982
  const response = await page.waitForResponse(opts.url, { timeout });
1982
1983
  let body = await response.text();
1983
1984
  let truncated = false;
1984
- if (opts.maxChars && body.length > opts.maxChars) {
1985
- body = body.slice(0, opts.maxChars);
1985
+ const maxChars = typeof opts.maxChars === "number" && Number.isFinite(opts.maxChars) ? Math.max(1, Math.min(5e6, Math.floor(opts.maxChars))) : void 0;
1986
+ if (maxChars !== void 0 && body.length > maxChars) {
1987
+ body = body.slice(0, maxChars);
1986
1988
  truncated = true;
1987
1989
  }
1988
1990
  const headers = {};
@@ -2153,6 +2155,7 @@ var CrawlPage = class {
2153
2155
  selector: opts.selector,
2154
2156
  frameSelector: opts.frameSelector,
2155
2157
  refsMode: opts.refsMode,
2158
+ timeoutMs: opts.timeoutMs,
2156
2159
  options: {
2157
2160
  interactive: opts.interactive,
2158
2161
  compact: opts.compact,