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.cjs
CHANGED
|
@@ -612,13 +612,13 @@ function storeRoleRefsForTarget(opts) {
|
|
|
612
612
|
function restoreRoleRefsForTarget(opts) {
|
|
613
613
|
const targetId = opts.targetId?.trim() || "";
|
|
614
614
|
if (!targetId) return;
|
|
615
|
-
const
|
|
616
|
-
if (!
|
|
615
|
+
const entry = roleRefsByTarget.get(roleRefsKey(opts.cdpUrl, targetId));
|
|
616
|
+
if (!entry) return;
|
|
617
617
|
const state = ensurePageState(opts.page);
|
|
618
618
|
if (state.roleRefs) return;
|
|
619
|
-
state.roleRefs =
|
|
620
|
-
state.roleRefsFrameSelector =
|
|
621
|
-
state.roleRefsMode =
|
|
619
|
+
state.roleRefs = entry.refs;
|
|
620
|
+
state.roleRefsFrameSelector = entry.frameSelector;
|
|
621
|
+
state.roleRefsMode = entry.mode;
|
|
622
622
|
}
|
|
623
623
|
async function connectBrowser(cdpUrl) {
|
|
624
624
|
const normalized = normalizeCdpUrl(cdpUrl);
|
|
@@ -735,8 +735,8 @@ function toAIFriendlyError(error, selector) {
|
|
|
735
735
|
}
|
|
736
736
|
return error instanceof Error ? error : new Error(message);
|
|
737
737
|
}
|
|
738
|
-
function normalizeTimeoutMs(timeoutMs, fallback) {
|
|
739
|
-
return Math.max(500, Math.min(
|
|
738
|
+
function normalizeTimeoutMs(timeoutMs, fallback, maxMs = 12e4) {
|
|
739
|
+
return Math.max(500, Math.min(maxMs, timeoutMs ?? fallback));
|
|
740
740
|
}
|
|
741
741
|
|
|
742
742
|
// src/snapshot/ref-map.ts
|
|
@@ -996,7 +996,7 @@ async function snapshotAi(opts) {
|
|
|
996
996
|
throw new Error("Playwright _snapshotForAI is not available. Upgrade playwright-core to >= 1.50.");
|
|
997
997
|
}
|
|
998
998
|
const result = await maybe._snapshotForAI({
|
|
999
|
-
timeout:
|
|
999
|
+
timeout: normalizeTimeoutMs(opts.timeoutMs, 5e3, 6e4),
|
|
1000
1000
|
track: "response"
|
|
1001
1001
|
});
|
|
1002
1002
|
let snapshot = String(result?.full ?? "");
|
|
@@ -1110,7 +1110,7 @@ async function clickViaPlaywright(opts) {
|
|
|
1110
1110
|
ensurePageState(page);
|
|
1111
1111
|
restoreRoleRefsForTarget({ cdpUrl: opts.cdpUrl, targetId: opts.targetId, page });
|
|
1112
1112
|
const locator = refLocator(page, opts.ref);
|
|
1113
|
-
const timeout =
|
|
1113
|
+
const timeout = normalizeTimeoutMs(opts.timeoutMs, 8e3, 6e4);
|
|
1114
1114
|
try {
|
|
1115
1115
|
if (opts.doubleClick) {
|
|
1116
1116
|
await locator.dblclick({ timeout, button: opts.button, modifiers: opts.modifiers });
|
|
@@ -1127,7 +1127,7 @@ async function hoverViaPlaywright(opts) {
|
|
|
1127
1127
|
restoreRoleRefsForTarget({ cdpUrl: opts.cdpUrl, targetId: opts.targetId, page });
|
|
1128
1128
|
try {
|
|
1129
1129
|
await refLocator(page, opts.ref).hover({
|
|
1130
|
-
timeout:
|
|
1130
|
+
timeout: normalizeTimeoutMs(opts.timeoutMs, 8e3, 6e4)
|
|
1131
1131
|
});
|
|
1132
1132
|
} catch (err) {
|
|
1133
1133
|
throw toAIFriendlyError(err, opts.ref);
|
|
@@ -1139,7 +1139,7 @@ async function typeViaPlaywright(opts) {
|
|
|
1139
1139
|
ensurePageState(page);
|
|
1140
1140
|
restoreRoleRefsForTarget({ cdpUrl: opts.cdpUrl, targetId: opts.targetId, page });
|
|
1141
1141
|
const locator = refLocator(page, opts.ref);
|
|
1142
|
-
const timeout =
|
|
1142
|
+
const timeout = normalizeTimeoutMs(opts.timeoutMs, 8e3, 6e4);
|
|
1143
1143
|
try {
|
|
1144
1144
|
if (opts.slowly) {
|
|
1145
1145
|
await locator.click({ timeout });
|
|
@@ -1159,7 +1159,7 @@ async function selectOptionViaPlaywright(opts) {
|
|
|
1159
1159
|
restoreRoleRefsForTarget({ cdpUrl: opts.cdpUrl, targetId: opts.targetId, page });
|
|
1160
1160
|
try {
|
|
1161
1161
|
await refLocator(page, opts.ref).selectOption(opts.values, {
|
|
1162
|
-
timeout:
|
|
1162
|
+
timeout: normalizeTimeoutMs(opts.timeoutMs, 8e3, 6e4)
|
|
1163
1163
|
});
|
|
1164
1164
|
} catch (err) {
|
|
1165
1165
|
throw toAIFriendlyError(err, opts.ref);
|
|
@@ -1171,7 +1171,7 @@ async function dragViaPlaywright(opts) {
|
|
|
1171
1171
|
restoreRoleRefsForTarget({ cdpUrl: opts.cdpUrl, targetId: opts.targetId, page });
|
|
1172
1172
|
try {
|
|
1173
1173
|
await refLocator(page, opts.startRef).dragTo(refLocator(page, opts.endRef), {
|
|
1174
|
-
timeout:
|
|
1174
|
+
timeout: normalizeTimeoutMs(opts.timeoutMs, 8e3, 6e4)
|
|
1175
1175
|
});
|
|
1176
1176
|
} catch (err) {
|
|
1177
1177
|
throw toAIFriendlyError(err, `${opts.startRef} -> ${opts.endRef}`);
|
|
@@ -1181,12 +1181,12 @@ async function fillFormViaPlaywright(opts) {
|
|
|
1181
1181
|
const page = await getPageForTargetId({ cdpUrl: opts.cdpUrl, targetId: opts.targetId });
|
|
1182
1182
|
ensurePageState(page);
|
|
1183
1183
|
restoreRoleRefsForTarget({ cdpUrl: opts.cdpUrl, targetId: opts.targetId, page });
|
|
1184
|
-
const timeout =
|
|
1184
|
+
const timeout = normalizeTimeoutMs(opts.timeoutMs, 8e3, 6e4);
|
|
1185
1185
|
for (const field of opts.fields) {
|
|
1186
1186
|
const ref = field.ref.trim();
|
|
1187
1187
|
const type = field.type.trim();
|
|
1188
1188
|
const rawValue = field.value;
|
|
1189
|
-
const value =
|
|
1189
|
+
const value = rawValue == null ? "" : String(rawValue);
|
|
1190
1190
|
if (!ref || !type) continue;
|
|
1191
1191
|
const locator = refLocator(page, ref);
|
|
1192
1192
|
if (type === "checkbox" || type === "radio") {
|
|
@@ -1574,12 +1574,12 @@ var CrawlPage = class {
|
|
|
1574
1574
|
return snapshotRole({
|
|
1575
1575
|
cdpUrl: this.cdpUrl,
|
|
1576
1576
|
targetId: this.targetId,
|
|
1577
|
-
selector: opts
|
|
1578
|
-
frameSelector: opts
|
|
1577
|
+
selector: opts.selector,
|
|
1578
|
+
frameSelector: opts.frameSelector,
|
|
1579
1579
|
options: {
|
|
1580
|
-
interactive: opts
|
|
1581
|
-
compact: opts
|
|
1582
|
-
maxDepth: opts
|
|
1580
|
+
interactive: opts.interactive,
|
|
1581
|
+
compact: opts.compact,
|
|
1582
|
+
maxDepth: opts.maxDepth
|
|
1583
1583
|
}
|
|
1584
1584
|
});
|
|
1585
1585
|
}
|