@browserbasehq/stagehand 1.2.0 → 1.3.0
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.d.ts +17 -14
- package/dist/index.js +1176 -332
- package/package.json +2 -3
- package/dist/dom/build/debug.js +0 -128
- package/dist/dom/build/global.d.js +0 -2
- package/dist/dom/build/index.js +0 -623
- package/dist/dom/build/process.js +0 -478
- package/dist/dom/build/utils.js +0 -19
- package/dist/dom/build/xpathUtils.js +0 -478
package/package.json
CHANGED
|
@@ -1,6 +1,6 @@
|
|
|
1
1
|
{
|
|
2
2
|
"name": "@browserbasehq/stagehand",
|
|
3
|
-
"version": "1.
|
|
3
|
+
"version": "1.3.0",
|
|
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",
|
|
@@ -12,8 +12,7 @@
|
|
|
12
12
|
"format": "prettier --write .",
|
|
13
13
|
"cache:clear": "rm -rf .cache",
|
|
14
14
|
"evals": "npm run build-dom-scripts && npx braintrust eval evals/index.eval.ts",
|
|
15
|
-
"build-dom-scripts": "
|
|
16
|
-
"bundle-dom-scripts": "esbuild ./lib/dom/index.ts --bundle --outfile=./lib/dom/bundle.js --platform=browser --target=es2015 --minify",
|
|
15
|
+
"build-dom-scripts": "tsx lib/dom/genDomScripts.ts",
|
|
17
16
|
"build": "npm run build-dom-scripts && tsup lib/index.ts --dts",
|
|
18
17
|
"release": "changeset publish"
|
|
19
18
|
},
|
package/dist/dom/build/debug.js
DELETED
|
@@ -1,128 +0,0 @@
|
|
|
1
|
-
(() => {
|
|
2
|
-
// lib/dom/debug.ts
|
|
3
|
-
async function debugDom() {
|
|
4
|
-
window.chunkNumber = 0;
|
|
5
|
-
const { selectorMap: multiSelectorMap, outputString } = await window.processElements(window.chunkNumber);
|
|
6
|
-
const selectorMap = multiSelectorMapToSelectorMap(multiSelectorMap);
|
|
7
|
-
drawChunk(selectorMap);
|
|
8
|
-
setupChunkNav();
|
|
9
|
-
}
|
|
10
|
-
function multiSelectorMapToSelectorMap(multiSelectorMap) {
|
|
11
|
-
return Object.fromEntries(
|
|
12
|
-
Object.entries(multiSelectorMap).map(([key, selectors]) => [
|
|
13
|
-
Number(key),
|
|
14
|
-
selectors[0]
|
|
15
|
-
])
|
|
16
|
-
);
|
|
17
|
-
}
|
|
18
|
-
function drawChunk(selectorMap) {
|
|
19
|
-
cleanupMarkers();
|
|
20
|
-
Object.entries(selectorMap).forEach(([_index, selector]) => {
|
|
21
|
-
const element = document.evaluate(
|
|
22
|
-
selector,
|
|
23
|
-
document,
|
|
24
|
-
null,
|
|
25
|
-
XPathResult.FIRST_ORDERED_NODE_TYPE,
|
|
26
|
-
null
|
|
27
|
-
).singleNodeValue;
|
|
28
|
-
if (element) {
|
|
29
|
-
let rect;
|
|
30
|
-
if (element.nodeType === Node.ELEMENT_NODE) {
|
|
31
|
-
rect = element.getBoundingClientRect();
|
|
32
|
-
} else {
|
|
33
|
-
const range = document.createRange();
|
|
34
|
-
range.selectNodeContents(element);
|
|
35
|
-
rect = range.getBoundingClientRect();
|
|
36
|
-
}
|
|
37
|
-
const color = "grey";
|
|
38
|
-
const overlay = document.createElement("div");
|
|
39
|
-
overlay.style.position = "absolute";
|
|
40
|
-
overlay.style.left = `${rect.left + window.scrollX}px`;
|
|
41
|
-
overlay.style.top = `${rect.top + window.scrollY}px`;
|
|
42
|
-
overlay.style.padding = "2px";
|
|
43
|
-
overlay.style.width = `${rect.width}px`;
|
|
44
|
-
overlay.style.height = `${rect.height}px`;
|
|
45
|
-
overlay.style.backgroundColor = color;
|
|
46
|
-
overlay.className = "stagehand-marker";
|
|
47
|
-
overlay.style.opacity = "0.3";
|
|
48
|
-
overlay.style.zIndex = "1000000000";
|
|
49
|
-
overlay.style.border = "1px solid";
|
|
50
|
-
overlay.style.pointerEvents = "none";
|
|
51
|
-
document.body.appendChild(overlay);
|
|
52
|
-
}
|
|
53
|
-
});
|
|
54
|
-
}
|
|
55
|
-
async function cleanupDebug() {
|
|
56
|
-
cleanupMarkers();
|
|
57
|
-
cleanupNav();
|
|
58
|
-
}
|
|
59
|
-
function cleanupMarkers() {
|
|
60
|
-
const markers = document.querySelectorAll(".stagehand-marker");
|
|
61
|
-
markers.forEach((marker) => {
|
|
62
|
-
marker.remove();
|
|
63
|
-
});
|
|
64
|
-
}
|
|
65
|
-
function cleanupNav() {
|
|
66
|
-
const stagehandNavElements = document.querySelectorAll(".stagehand-nav");
|
|
67
|
-
stagehandNavElements.forEach((element) => {
|
|
68
|
-
element.remove();
|
|
69
|
-
});
|
|
70
|
-
}
|
|
71
|
-
function setupChunkNav() {
|
|
72
|
-
const viewportHeight = window.innerHeight;
|
|
73
|
-
const documentHeight = document.documentElement.scrollHeight;
|
|
74
|
-
const totalChunks = Math.ceil(documentHeight / viewportHeight);
|
|
75
|
-
if (window.chunkNumber > 0) {
|
|
76
|
-
const prevChunkButton = document.createElement("button");
|
|
77
|
-
prevChunkButton.className = "stagehand-nav";
|
|
78
|
-
prevChunkButton.textContent = "Previous";
|
|
79
|
-
prevChunkButton.style.marginLeft = "50px";
|
|
80
|
-
prevChunkButton.style.position = "fixed";
|
|
81
|
-
prevChunkButton.style.bottom = "10px";
|
|
82
|
-
prevChunkButton.style.left = "50%";
|
|
83
|
-
prevChunkButton.style.transform = "translateX(-50%)";
|
|
84
|
-
prevChunkButton.style.zIndex = "1000000000";
|
|
85
|
-
prevChunkButton.onclick = async () => {
|
|
86
|
-
cleanupMarkers();
|
|
87
|
-
cleanupNav();
|
|
88
|
-
window.chunkNumber -= 1;
|
|
89
|
-
window.scrollTo(0, window.chunkNumber * window.innerHeight);
|
|
90
|
-
await window.waitForDomSettle();
|
|
91
|
-
const { selectorMap: multiSelectorMap } = await window.processElements(
|
|
92
|
-
window.chunkNumber
|
|
93
|
-
);
|
|
94
|
-
const selectorMap = multiSelectorMapToSelectorMap(multiSelectorMap);
|
|
95
|
-
drawChunk(selectorMap);
|
|
96
|
-
setupChunkNav();
|
|
97
|
-
};
|
|
98
|
-
document.body.appendChild(prevChunkButton);
|
|
99
|
-
}
|
|
100
|
-
if (totalChunks > window.chunkNumber) {
|
|
101
|
-
const nextChunkButton = document.createElement("button");
|
|
102
|
-
nextChunkButton.className = "stagehand-nav";
|
|
103
|
-
nextChunkButton.textContent = "Next";
|
|
104
|
-
nextChunkButton.style.marginRight = "50px";
|
|
105
|
-
nextChunkButton.style.position = "fixed";
|
|
106
|
-
nextChunkButton.style.bottom = "10px";
|
|
107
|
-
nextChunkButton.style.right = "50%";
|
|
108
|
-
nextChunkButton.style.transform = "translateX(50%)";
|
|
109
|
-
nextChunkButton.style.zIndex = "1000000000";
|
|
110
|
-
nextChunkButton.onclick = async () => {
|
|
111
|
-
cleanupMarkers();
|
|
112
|
-
cleanupNav();
|
|
113
|
-
window.chunkNumber += 1;
|
|
114
|
-
window.scrollTo(0, window.chunkNumber * window.innerHeight);
|
|
115
|
-
await window.waitForDomSettle();
|
|
116
|
-
const { selectorMap: multiSelectorMap } = await window.processElements(
|
|
117
|
-
window.chunkNumber
|
|
118
|
-
);
|
|
119
|
-
const selectorMap = multiSelectorMapToSelectorMap(multiSelectorMap);
|
|
120
|
-
drawChunk(selectorMap);
|
|
121
|
-
setupChunkNav();
|
|
122
|
-
};
|
|
123
|
-
document.body.appendChild(nextChunkButton);
|
|
124
|
-
}
|
|
125
|
-
}
|
|
126
|
-
window.debugDom = debugDom;
|
|
127
|
-
window.cleanupDebug = cleanupDebug;
|
|
128
|
-
})();
|