browserclaw 0.3.2 → 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/README.md +19 -14
- package/dist/index.cjs +8 -5
- package/dist/index.cjs.map +1 -1
- package/dist/index.d.cts +2 -0
- package/dist/index.d.ts +2 -0
- package/dist/index.js +8 -5
- package/dist/index.js.map +1 -1
- package/package.json +1 -1
package/dist/index.d.cts
CHANGED
|
@@ -151,6 +151,8 @@ interface SnapshotOptions {
|
|
|
151
151
|
* - `'role'` — uses Playwright's `ariaSnapshot()` + `getByRole()` resolution
|
|
152
152
|
*/
|
|
153
153
|
mode?: 'role' | 'aria';
|
|
154
|
+
/** Timeout in milliseconds for the snapshot operation (role mode only, default: 5000) */
|
|
155
|
+
timeoutMs?: number;
|
|
154
156
|
/**
|
|
155
157
|
* How refs are stored for role-mode snapshots.
|
|
156
158
|
* - `'role'` (default) — refs resolved via `getByRole()`
|
package/dist/index.d.ts
CHANGED
|
@@ -151,6 +151,8 @@ interface SnapshotOptions {
|
|
|
151
151
|
* - `'role'` — uses Playwright's `ariaSnapshot()` + `getByRole()` resolution
|
|
152
152
|
*/
|
|
153
153
|
mode?: 'role' | 'aria';
|
|
154
|
+
/** Timeout in milliseconds for the snapshot operation (role mode only, default: 5000) */
|
|
155
|
+
timeoutMs?: number;
|
|
154
156
|
/**
|
|
155
157
|
* How refs are stored for role-mode snapshots.
|
|
156
158
|
* - `'role'` (default) — refs resolved via `getByRole()`
|
package/dist/index.js
CHANGED
|
@@ -742,12 +742,13 @@ async function getPageForTargetId(opts) {
|
|
|
742
742
|
const found = await findPageByTargetId(browser, opts.targetId, opts.cdpUrl);
|
|
743
743
|
if (!found) {
|
|
744
744
|
if (pages.length === 1) return first;
|
|
745
|
-
throw new Error(`Tab not found (targetId: ${opts.targetId}).
|
|
745
|
+
throw new Error(`Tab not found (targetId: ${opts.targetId}). Call browser.tabs() to list open tabs.`);
|
|
746
746
|
}
|
|
747
747
|
return found;
|
|
748
748
|
}
|
|
749
749
|
function refLocator(page, ref) {
|
|
750
750
|
const normalized = ref.startsWith("@") ? ref.slice(1) : ref.startsWith("ref=") ? ref.slice(4) : ref;
|
|
751
|
+
if (!normalized.trim()) throw new Error("ref is required");
|
|
751
752
|
if (/^e\d+$/.test(normalized)) {
|
|
752
753
|
const state = pageStates.get(page);
|
|
753
754
|
if (state?.roleRefsMode === "aria") {
|
|
@@ -1096,7 +1097,7 @@ async function snapshotRole(opts) {
|
|
|
1096
1097
|
const frameSelector = opts.frameSelector?.trim() || "";
|
|
1097
1098
|
const selector = opts.selector?.trim() || "";
|
|
1098
1099
|
const locator = frameSelector ? selector ? page.frameLocator(frameSelector).locator(selector) : page.frameLocator(frameSelector).locator(":root") : selector ? page.locator(selector) : page.locator(":root");
|
|
1099
|
-
const ariaSnapshot = await locator.ariaSnapshot({ timeout:
|
|
1100
|
+
const ariaSnapshot = await locator.ariaSnapshot({ timeout: normalizeTimeoutMs(opts.timeoutMs, 5e3) });
|
|
1100
1101
|
const built = buildRoleSnapshotFromAriaSnapshot(String(ariaSnapshot ?? ""), opts.options);
|
|
1101
1102
|
storeRoleRefsForTarget({
|
|
1102
1103
|
page,
|
|
@@ -1825,7 +1826,7 @@ async function setGeolocationViaPlaywright(opts) {
|
|
|
1825
1826
|
return;
|
|
1826
1827
|
}
|
|
1827
1828
|
if (opts.latitude === void 0 || opts.longitude === void 0) {
|
|
1828
|
-
throw new Error("latitude and longitude are required
|
|
1829
|
+
throw new Error("latitude and longitude are required (or set clear=true)");
|
|
1829
1830
|
}
|
|
1830
1831
|
await context.grantPermissions(["geolocation"], opts.origin ? { origin: opts.origin } : void 0);
|
|
1831
1832
|
await context.setGeolocation({
|
|
@@ -1972,8 +1973,9 @@ async function responseBodyViaPlaywright(opts) {
|
|
|
1972
1973
|
const response = await page.waitForResponse(opts.url, { timeout });
|
|
1973
1974
|
let body = await response.text();
|
|
1974
1975
|
let truncated = false;
|
|
1975
|
-
|
|
1976
|
-
|
|
1976
|
+
const maxChars = typeof opts.maxChars === "number" && Number.isFinite(opts.maxChars) ? Math.max(1, Math.min(5e6, Math.floor(opts.maxChars))) : void 0;
|
|
1977
|
+
if (maxChars !== void 0 && body.length > maxChars) {
|
|
1978
|
+
body = body.slice(0, maxChars);
|
|
1977
1979
|
truncated = true;
|
|
1978
1980
|
}
|
|
1979
1981
|
const headers = {};
|
|
@@ -2144,6 +2146,7 @@ var CrawlPage = class {
|
|
|
2144
2146
|
selector: opts.selector,
|
|
2145
2147
|
frameSelector: opts.frameSelector,
|
|
2146
2148
|
refsMode: opts.refsMode,
|
|
2149
|
+
timeoutMs: opts.timeoutMs,
|
|
2147
2150
|
options: {
|
|
2148
2151
|
interactive: opts.interactive,
|
|
2149
2152
|
compact: opts.compact,
|