@browserbasehq/stagehand 1.1.2 → 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/package.json CHANGED
@@ -1,6 +1,6 @@
1
1
  {
2
2
  "name": "@browserbasehq/stagehand",
3
- "version": "1.1.2",
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": "mkdir -p ./lib/dom/build && mkdir -p ./dist/dom/build && esbuild ./lib/dom/*.ts --bundle --outdir=./dist/dom/build",
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
  },
@@ -1,115 +0,0 @@
1
- (() => {
2
- // lib/dom/debug.ts
3
- async function debugDom() {
4
- window.chunkNumber = 0;
5
- const { selectorMap, outputString } = await window.processElements(
6
- window.chunkNumber
7
- );
8
- drawChunk(selectorMap);
9
- setupChunkNav();
10
- }
11
- function drawChunk(selectorMap) {
12
- cleanupMarkers();
13
- Object.entries(selectorMap).forEach(([_index, selector]) => {
14
- const element = document.evaluate(
15
- selector,
16
- document,
17
- null,
18
- XPathResult.FIRST_ORDERED_NODE_TYPE,
19
- null
20
- ).singleNodeValue;
21
- if (element) {
22
- let rect;
23
- if (element.nodeType === Node.ELEMENT_NODE) {
24
- rect = element.getBoundingClientRect();
25
- } else {
26
- const range = document.createRange();
27
- range.selectNodeContents(element);
28
- rect = range.getBoundingClientRect();
29
- }
30
- const color = "grey";
31
- const overlay = document.createElement("div");
32
- overlay.style.position = "absolute";
33
- overlay.style.left = `${rect.left + window.scrollX}px`;
34
- overlay.style.top = `${rect.top + window.scrollY}px`;
35
- overlay.style.padding = "2px";
36
- overlay.style.width = `${rect.width}px`;
37
- overlay.style.height = `${rect.height}px`;
38
- overlay.style.backgroundColor = color;
39
- overlay.className = "stagehand-marker";
40
- overlay.style.opacity = "0.3";
41
- overlay.style.zIndex = "1000000000";
42
- overlay.style.border = "1px solid";
43
- overlay.style.pointerEvents = "none";
44
- document.body.appendChild(overlay);
45
- }
46
- });
47
- }
48
- async function cleanupDebug() {
49
- cleanupMarkers();
50
- cleanupNav();
51
- }
52
- function cleanupMarkers() {
53
- const markers = document.querySelectorAll(".stagehand-marker");
54
- markers.forEach((marker) => {
55
- marker.remove();
56
- });
57
- }
58
- function cleanupNav() {
59
- const stagehandNavElements = document.querySelectorAll(".stagehand-nav");
60
- stagehandNavElements.forEach((element) => {
61
- element.remove();
62
- });
63
- }
64
- function setupChunkNav() {
65
- const viewportHeight = window.innerHeight;
66
- const documentHeight = document.documentElement.scrollHeight;
67
- const totalChunks = Math.ceil(documentHeight / viewportHeight);
68
- if (window.chunkNumber > 0) {
69
- const prevChunkButton = document.createElement("button");
70
- prevChunkButton.className = "stagehand-nav";
71
- prevChunkButton.textContent = "Previous";
72
- prevChunkButton.style.marginLeft = "50px";
73
- prevChunkButton.style.position = "fixed";
74
- prevChunkButton.style.bottom = "10px";
75
- prevChunkButton.style.left = "50%";
76
- prevChunkButton.style.transform = "translateX(-50%)";
77
- prevChunkButton.style.zIndex = "1000000000";
78
- prevChunkButton.onclick = async () => {
79
- cleanupMarkers();
80
- cleanupNav();
81
- window.chunkNumber -= 1;
82
- window.scrollTo(0, window.chunkNumber * window.innerHeight);
83
- await window.waitForDomSettle();
84
- const { selectorMap } = await processElements(window.chunkNumber);
85
- drawChunk(selectorMap);
86
- setupChunkNav();
87
- };
88
- document.body.appendChild(prevChunkButton);
89
- }
90
- if (totalChunks > window.chunkNumber) {
91
- const nextChunkButton = document.createElement("button");
92
- nextChunkButton.className = "stagehand-nav";
93
- nextChunkButton.textContent = "Next";
94
- nextChunkButton.style.marginRight = "50px";
95
- nextChunkButton.style.position = "fixed";
96
- nextChunkButton.style.bottom = "10px";
97
- nextChunkButton.style.right = "50%";
98
- nextChunkButton.style.transform = "translateX(50%)";
99
- nextChunkButton.style.zIndex = "1000000000";
100
- nextChunkButton.onclick = async () => {
101
- cleanupMarkers();
102
- cleanupNav();
103
- window.chunkNumber += 1;
104
- window.scrollTo(0, window.chunkNumber * window.innerHeight);
105
- await window.waitForDomSettle();
106
- const { selectorMap } = await processElements(window.chunkNumber);
107
- drawChunk(selectorMap);
108
- setupChunkNav();
109
- };
110
- document.body.appendChild(nextChunkButton);
111
- }
112
- }
113
- window.debugDom = debugDom;
114
- window.cleanupDebug = cleanupDebug;
115
- })();
@@ -1,2 +0,0 @@
1
- (() => {
2
- })();