browserclaw 0.1.0 → 0.1.1
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.
Potentially problematic release.
This version of browserclaw might be problematic. Click here for more details.
- package/dist/index.cjs +20 -20
- package/dist/index.cjs.map +1 -1
- package/dist/index.js +20 -20
- package/dist/index.js.map +1 -1
- package/package.json +1 -1
package/dist/index.js
CHANGED
|
@@ -603,13 +603,13 @@ function storeRoleRefsForTarget(opts) {
|
|
|
603
603
|
function restoreRoleRefsForTarget(opts) {
|
|
604
604
|
const targetId = opts.targetId?.trim() || "";
|
|
605
605
|
if (!targetId) return;
|
|
606
|
-
const
|
|
607
|
-
if (!
|
|
606
|
+
const entry = roleRefsByTarget.get(roleRefsKey(opts.cdpUrl, targetId));
|
|
607
|
+
if (!entry) return;
|
|
608
608
|
const state = ensurePageState(opts.page);
|
|
609
609
|
if (state.roleRefs) return;
|
|
610
|
-
state.roleRefs =
|
|
611
|
-
state.roleRefsFrameSelector =
|
|
612
|
-
state.roleRefsMode =
|
|
610
|
+
state.roleRefs = entry.refs;
|
|
611
|
+
state.roleRefsFrameSelector = entry.frameSelector;
|
|
612
|
+
state.roleRefsMode = entry.mode;
|
|
613
613
|
}
|
|
614
614
|
async function connectBrowser(cdpUrl) {
|
|
615
615
|
const normalized = normalizeCdpUrl(cdpUrl);
|
|
@@ -726,8 +726,8 @@ function toAIFriendlyError(error, selector) {
|
|
|
726
726
|
}
|
|
727
727
|
return error instanceof Error ? error : new Error(message);
|
|
728
728
|
}
|
|
729
|
-
function normalizeTimeoutMs(timeoutMs, fallback) {
|
|
730
|
-
return Math.max(500, Math.min(
|
|
729
|
+
function normalizeTimeoutMs(timeoutMs, fallback, maxMs = 12e4) {
|
|
730
|
+
return Math.max(500, Math.min(maxMs, timeoutMs ?? fallback));
|
|
731
731
|
}
|
|
732
732
|
|
|
733
733
|
// src/snapshot/ref-map.ts
|
|
@@ -987,7 +987,7 @@ async function snapshotAi(opts) {
|
|
|
987
987
|
throw new Error("Playwright _snapshotForAI is not available. Upgrade playwright-core to >= 1.50.");
|
|
988
988
|
}
|
|
989
989
|
const result = await maybe._snapshotForAI({
|
|
990
|
-
timeout:
|
|
990
|
+
timeout: normalizeTimeoutMs(opts.timeoutMs, 5e3, 6e4),
|
|
991
991
|
track: "response"
|
|
992
992
|
});
|
|
993
993
|
let snapshot = String(result?.full ?? "");
|
|
@@ -1101,7 +1101,7 @@ async function clickViaPlaywright(opts) {
|
|
|
1101
1101
|
ensurePageState(page);
|
|
1102
1102
|
restoreRoleRefsForTarget({ cdpUrl: opts.cdpUrl, targetId: opts.targetId, page });
|
|
1103
1103
|
const locator = refLocator(page, opts.ref);
|
|
1104
|
-
const timeout =
|
|
1104
|
+
const timeout = normalizeTimeoutMs(opts.timeoutMs, 8e3, 6e4);
|
|
1105
1105
|
try {
|
|
1106
1106
|
if (opts.doubleClick) {
|
|
1107
1107
|
await locator.dblclick({ timeout, button: opts.button, modifiers: opts.modifiers });
|
|
@@ -1118,7 +1118,7 @@ async function hoverViaPlaywright(opts) {
|
|
|
1118
1118
|
restoreRoleRefsForTarget({ cdpUrl: opts.cdpUrl, targetId: opts.targetId, page });
|
|
1119
1119
|
try {
|
|
1120
1120
|
await refLocator(page, opts.ref).hover({
|
|
1121
|
-
timeout:
|
|
1121
|
+
timeout: normalizeTimeoutMs(opts.timeoutMs, 8e3, 6e4)
|
|
1122
1122
|
});
|
|
1123
1123
|
} catch (err) {
|
|
1124
1124
|
throw toAIFriendlyError(err, opts.ref);
|
|
@@ -1130,7 +1130,7 @@ async function typeViaPlaywright(opts) {
|
|
|
1130
1130
|
ensurePageState(page);
|
|
1131
1131
|
restoreRoleRefsForTarget({ cdpUrl: opts.cdpUrl, targetId: opts.targetId, page });
|
|
1132
1132
|
const locator = refLocator(page, opts.ref);
|
|
1133
|
-
const timeout =
|
|
1133
|
+
const timeout = normalizeTimeoutMs(opts.timeoutMs, 8e3, 6e4);
|
|
1134
1134
|
try {
|
|
1135
1135
|
if (opts.slowly) {
|
|
1136
1136
|
await locator.click({ timeout });
|
|
@@ -1150,7 +1150,7 @@ async function selectOptionViaPlaywright(opts) {
|
|
|
1150
1150
|
restoreRoleRefsForTarget({ cdpUrl: opts.cdpUrl, targetId: opts.targetId, page });
|
|
1151
1151
|
try {
|
|
1152
1152
|
await refLocator(page, opts.ref).selectOption(opts.values, {
|
|
1153
|
-
timeout:
|
|
1153
|
+
timeout: normalizeTimeoutMs(opts.timeoutMs, 8e3, 6e4)
|
|
1154
1154
|
});
|
|
1155
1155
|
} catch (err) {
|
|
1156
1156
|
throw toAIFriendlyError(err, opts.ref);
|
|
@@ -1162,7 +1162,7 @@ async function dragViaPlaywright(opts) {
|
|
|
1162
1162
|
restoreRoleRefsForTarget({ cdpUrl: opts.cdpUrl, targetId: opts.targetId, page });
|
|
1163
1163
|
try {
|
|
1164
1164
|
await refLocator(page, opts.startRef).dragTo(refLocator(page, opts.endRef), {
|
|
1165
|
-
timeout:
|
|
1165
|
+
timeout: normalizeTimeoutMs(opts.timeoutMs, 8e3, 6e4)
|
|
1166
1166
|
});
|
|
1167
1167
|
} catch (err) {
|
|
1168
1168
|
throw toAIFriendlyError(err, `${opts.startRef} -> ${opts.endRef}`);
|
|
@@ -1172,12 +1172,12 @@ async function fillFormViaPlaywright(opts) {
|
|
|
1172
1172
|
const page = await getPageForTargetId({ cdpUrl: opts.cdpUrl, targetId: opts.targetId });
|
|
1173
1173
|
ensurePageState(page);
|
|
1174
1174
|
restoreRoleRefsForTarget({ cdpUrl: opts.cdpUrl, targetId: opts.targetId, page });
|
|
1175
|
-
const timeout =
|
|
1175
|
+
const timeout = normalizeTimeoutMs(opts.timeoutMs, 8e3, 6e4);
|
|
1176
1176
|
for (const field of opts.fields) {
|
|
1177
1177
|
const ref = field.ref.trim();
|
|
1178
1178
|
const type = field.type.trim();
|
|
1179
1179
|
const rawValue = field.value;
|
|
1180
|
-
const value =
|
|
1180
|
+
const value = rawValue == null ? "" : String(rawValue);
|
|
1181
1181
|
if (!ref || !type) continue;
|
|
1182
1182
|
const locator = refLocator(page, ref);
|
|
1183
1183
|
if (type === "checkbox" || type === "radio") {
|
|
@@ -1565,12 +1565,12 @@ var CrawlPage = class {
|
|
|
1565
1565
|
return snapshotRole({
|
|
1566
1566
|
cdpUrl: this.cdpUrl,
|
|
1567
1567
|
targetId: this.targetId,
|
|
1568
|
-
selector: opts
|
|
1569
|
-
frameSelector: opts
|
|
1568
|
+
selector: opts.selector,
|
|
1569
|
+
frameSelector: opts.frameSelector,
|
|
1570
1570
|
options: {
|
|
1571
|
-
interactive: opts
|
|
1572
|
-
compact: opts
|
|
1573
|
-
maxDepth: opts
|
|
1571
|
+
interactive: opts.interactive,
|
|
1572
|
+
compact: opts.compact,
|
|
1573
|
+
maxDepth: opts.maxDepth
|
|
1574
1574
|
}
|
|
1575
1575
|
});
|
|
1576
1576
|
}
|