@browserbasehq/stagehand 3.0.7-alpha-e822f5a8898df9eb48ca32c321025f0c74b638f0 → 3.0.7-alpha-a890f16fa3a752f308f858e5ab9c9a0faf6b3b34
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.js +115 -10
- package/package.json +1 -1
package/dist/index.js
CHANGED
|
@@ -179,7 +179,7 @@ var __forAwait = (obj, it, method) => (it = obj[__knownSymbol("asyncIterator")])
|
|
|
179
179
|
var STAGEHAND_VERSION;
|
|
180
180
|
var init_version = __esm({
|
|
181
181
|
"lib/version.ts"() {
|
|
182
|
-
STAGEHAND_VERSION = "3.0.7-alpha-
|
|
182
|
+
STAGEHAND_VERSION = "3.0.7-alpha-a890f16fa3a752f308f858e5ab9c9a0faf6b3b34";
|
|
183
183
|
}
|
|
184
184
|
});
|
|
185
185
|
|
|
@@ -988,6 +988,115 @@ function absoluteXPathForBackendNode(session, backendNodeId) {
|
|
|
988
988
|
}
|
|
989
989
|
});
|
|
990
990
|
}
|
|
991
|
+
function isCborStackError(message) {
|
|
992
|
+
return message.includes("CBOR: stack limit exceeded");
|
|
993
|
+
}
|
|
994
|
+
function shouldExpandNode(node) {
|
|
995
|
+
var _a4, _b, _c;
|
|
996
|
+
const declaredChildren = (_a4 = node.childNodeCount) != null ? _a4 : 0;
|
|
997
|
+
const realizedChildren = (_c = (_b = node.children) == null ? void 0 : _b.length) != null ? _c : 0;
|
|
998
|
+
return declaredChildren > realizedChildren;
|
|
999
|
+
}
|
|
1000
|
+
function mergeDomNodes(target, source) {
|
|
1001
|
+
var _a4, _b, _c, _d2;
|
|
1002
|
+
target.childNodeCount = (_a4 = source.childNodeCount) != null ? _a4 : target.childNodeCount;
|
|
1003
|
+
target.children = (_b = source.children) != null ? _b : target.children;
|
|
1004
|
+
target.shadowRoots = (_c = source.shadowRoots) != null ? _c : target.shadowRoots;
|
|
1005
|
+
target.contentDocument = (_d2 = source.contentDocument) != null ? _d2 : target.contentDocument;
|
|
1006
|
+
}
|
|
1007
|
+
function collectDomTraversalTargets(node) {
|
|
1008
|
+
const targets = [];
|
|
1009
|
+
if (node.children) targets.push(...node.children);
|
|
1010
|
+
if (node.shadowRoots) targets.push(...node.shadowRoots);
|
|
1011
|
+
if (node.contentDocument) targets.push(node.contentDocument);
|
|
1012
|
+
return targets;
|
|
1013
|
+
}
|
|
1014
|
+
function hydrateDomTree(session, root, pierce) {
|
|
1015
|
+
return __async(this, null, function* () {
|
|
1016
|
+
var _a4, _b;
|
|
1017
|
+
const stack = [root];
|
|
1018
|
+
const expandedNodeIds = /* @__PURE__ */ new Set();
|
|
1019
|
+
const expandedBackendIds = /* @__PURE__ */ new Set();
|
|
1020
|
+
while (stack.length) {
|
|
1021
|
+
const node = stack.pop();
|
|
1022
|
+
const nodeId = typeof node.nodeId === "number" && node.nodeId > 0 ? node.nodeId : void 0;
|
|
1023
|
+
const backendId = typeof node.backendNodeId === "number" && node.backendNodeId > 0 ? node.backendNodeId : void 0;
|
|
1024
|
+
const seenByNode = nodeId ? expandedNodeIds.has(nodeId) : false;
|
|
1025
|
+
const seenByBackend = !nodeId && backendId ? expandedBackendIds.has(backendId) : false;
|
|
1026
|
+
if (seenByNode || seenByBackend) continue;
|
|
1027
|
+
if (nodeId) expandedNodeIds.add(nodeId);
|
|
1028
|
+
else if (backendId) expandedBackendIds.add(backendId);
|
|
1029
|
+
const needsExpansion = shouldExpandNode(node);
|
|
1030
|
+
if (needsExpansion && (nodeId || backendId)) {
|
|
1031
|
+
const describeParamsBase = nodeId ? { nodeId } : { backendNodeId: backendId };
|
|
1032
|
+
let expanded = false;
|
|
1033
|
+
for (const depth of DESCRIBE_DEPTH_ATTEMPTS) {
|
|
1034
|
+
try {
|
|
1035
|
+
const described = yield session.send(
|
|
1036
|
+
"DOM.describeNode",
|
|
1037
|
+
__spreadProps(__spreadValues({}, describeParamsBase), {
|
|
1038
|
+
depth,
|
|
1039
|
+
pierce
|
|
1040
|
+
})
|
|
1041
|
+
);
|
|
1042
|
+
mergeDomNodes(node, described.node);
|
|
1043
|
+
if (!nodeId && described.node.nodeId && described.node.nodeId > 0) {
|
|
1044
|
+
node.nodeId = described.node.nodeId;
|
|
1045
|
+
expandedNodeIds.add(described.node.nodeId);
|
|
1046
|
+
}
|
|
1047
|
+
expanded = true;
|
|
1048
|
+
break;
|
|
1049
|
+
} catch (err) {
|
|
1050
|
+
const message = err instanceof Error ? err.message : String(err);
|
|
1051
|
+
if (isCborStackError(message)) {
|
|
1052
|
+
continue;
|
|
1053
|
+
}
|
|
1054
|
+
const identifier = (_a4 = nodeId != null ? nodeId : backendId) != null ? _a4 : "unknown";
|
|
1055
|
+
throw new StagehandDomProcessError(
|
|
1056
|
+
`Failed to expand DOM node ${identifier}: ${String(err)}`
|
|
1057
|
+
);
|
|
1058
|
+
}
|
|
1059
|
+
}
|
|
1060
|
+
if (!expanded) {
|
|
1061
|
+
const identifier = (_b = nodeId != null ? nodeId : backendId) != null ? _b : "unknown";
|
|
1062
|
+
throw new StagehandDomProcessError(
|
|
1063
|
+
`Unable to expand DOM node ${identifier} after describeNode depth retries`
|
|
1064
|
+
);
|
|
1065
|
+
}
|
|
1066
|
+
}
|
|
1067
|
+
for (const child of collectDomTraversalTargets(node)) {
|
|
1068
|
+
stack.push(child);
|
|
1069
|
+
}
|
|
1070
|
+
}
|
|
1071
|
+
});
|
|
1072
|
+
}
|
|
1073
|
+
function getDomTreeWithFallback(session, pierce) {
|
|
1074
|
+
return __async(this, null, function* () {
|
|
1075
|
+
let lastCborMessage = "";
|
|
1076
|
+
for (const depth of DOM_DEPTH_ATTEMPTS) {
|
|
1077
|
+
try {
|
|
1078
|
+
const { root } = yield session.send(
|
|
1079
|
+
"DOM.getDocument",
|
|
1080
|
+
{ depth, pierce }
|
|
1081
|
+
);
|
|
1082
|
+
if (depth !== -1) {
|
|
1083
|
+
yield hydrateDomTree(session, root, pierce);
|
|
1084
|
+
}
|
|
1085
|
+
return root;
|
|
1086
|
+
} catch (err) {
|
|
1087
|
+
const message = err instanceof Error ? err.message : String(err);
|
|
1088
|
+
if (isCborStackError(message)) {
|
|
1089
|
+
lastCborMessage = message;
|
|
1090
|
+
continue;
|
|
1091
|
+
}
|
|
1092
|
+
throw err;
|
|
1093
|
+
}
|
|
1094
|
+
}
|
|
1095
|
+
throw new StagehandDomProcessError(
|
|
1096
|
+
lastCborMessage ? `CDP DOM.getDocument failed after adaptive depth retries: ${lastCborMessage}` : "CDP DOM.getDocument failed after adaptive depth retries."
|
|
1097
|
+
);
|
|
1098
|
+
});
|
|
1099
|
+
}
|
|
991
1100
|
function captureHybridSnapshot(page, options) {
|
|
992
1101
|
return __async(this, null, function* () {
|
|
993
1102
|
var _a4, _b, _c, _d2, _e, _f, _g, _h, _i, _j, _k, _l;
|
|
@@ -1106,10 +1215,7 @@ function captureHybridSnapshot(page, options) {
|
|
|
1106
1215
|
var _a5, _b2;
|
|
1107
1216
|
yield session.send("DOM.enable").catch(() => {
|
|
1108
1217
|
});
|
|
1109
|
-
const
|
|
1110
|
-
"DOM.getDocument",
|
|
1111
|
-
{ depth: -1, pierce: pierce2 }
|
|
1112
|
-
);
|
|
1218
|
+
const root = yield getDomTreeWithFallback(session, pierce2);
|
|
1113
1219
|
const absByBe = /* @__PURE__ */ new Map();
|
|
1114
1220
|
const tagByBe = /* @__PURE__ */ new Map();
|
|
1115
1221
|
const scrollByBe = /* @__PURE__ */ new Map();
|
|
@@ -1466,10 +1572,7 @@ function domMapsForSession(session, frameId, pierce, encode = (fid, be) => `${fi
|
|
|
1466
1572
|
var _a4, _b;
|
|
1467
1573
|
yield session.send("DOM.enable").catch(() => {
|
|
1468
1574
|
});
|
|
1469
|
-
const
|
|
1470
|
-
"DOM.getDocument",
|
|
1471
|
-
{ depth: -1, pierce }
|
|
1472
|
-
);
|
|
1575
|
+
const root = yield getDomTreeWithFallback(session, pierce);
|
|
1473
1576
|
let startNode = root;
|
|
1474
1577
|
if (attemptOwnerLookup) {
|
|
1475
1578
|
try {
|
|
@@ -1966,12 +2069,14 @@ function parentSession(page, parentByFrame, frameId) {
|
|
|
1966
2069
|
}
|
|
1967
2070
|
return page.getSessionForFrame(parentId);
|
|
1968
2071
|
}
|
|
1969
|
-
var IFRAME_STEP_RE;
|
|
2072
|
+
var DOM_DEPTH_ATTEMPTS, DESCRIBE_DEPTH_ATTEMPTS, IFRAME_STEP_RE;
|
|
1970
2073
|
var init_snapshot = __esm({
|
|
1971
2074
|
"lib/v3/understudy/a11y/snapshot.ts"() {
|
|
1972
2075
|
init_executionContextRegistry();
|
|
1973
2076
|
init_logger();
|
|
1974
2077
|
init_sdkErrors();
|
|
2078
|
+
DOM_DEPTH_ATTEMPTS = [-1, 256, 128, 64, 32, 16, 8, 4, 2, 1];
|
|
2079
|
+
DESCRIBE_DEPTH_ATTEMPTS = [-1, 64, 32, 16, 8, 4, 2, 1];
|
|
1975
2080
|
IFRAME_STEP_RE = /^iframe(?:\[\d+])?$/i;
|
|
1976
2081
|
}
|
|
1977
2082
|
});
|
package/package.json
CHANGED
|
@@ -1,6 +1,6 @@
|
|
|
1
1
|
{
|
|
2
2
|
"name": "@browserbasehq/stagehand",
|
|
3
|
-
"version": "3.0.7-alpha-
|
|
3
|
+
"version": "3.0.7-alpha-a890f16fa3a752f308f858e5ab9c9a0faf6b3b34",
|
|
4
4
|
"description": "An AI web browsing framework focused on simplicity and extensibility.",
|
|
5
5
|
"main": "./dist/index.js",
|
|
6
6
|
"module": "./dist/index.js",
|