@browserbasehq/stagehand 1.1.0 → 1.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.
package/README.md CHANGED
@@ -137,7 +137,7 @@ This constructor is used to create an instance of Stagehand.
137
137
  - `1`: SDK-level logging
138
138
  - `2`: LLM-client level logging (most granular)
139
139
  - `debugDom`: a `boolean` that draws bounding boxes around elements presented to the LLM during automation.
140
- - `domSettleTimeoutMs`: an `integer` that specifies the timeout in milliseconds for waiting for the DOM to settle. Defaults to 30000 (30 seconds).
140
+ - `domSettleTimeoutMs`: an `integer` that specifies the timeout in milliseconds for waiting for the DOM to settle. It can be overriden in individual function calls if needed. Defaults to 30000 (30 seconds).
141
141
  - `enableCaching`: a `boolean` that enables caching of LLM responses. When set to `true`, the LLM requests will be cached on disk and reused for identical requests. Defaults to `false`.
142
142
 
143
143
  - **Returns:**
@@ -179,6 +179,7 @@ This constructor is used to create an instance of Stagehand.
179
179
  - `action`: a `string` describing the action to perform, e.g., `"search for 'x'"`.
180
180
  - `modelName`: (optional) an `AvailableModel` string to specify the model to use.
181
181
  - `useVision`: (optional) a `boolean` or `"fallback"` to determine if vision-based processing should be used. Defaults to `"fallback"`.
182
+ - `domSettleTimeoutMs`: (optional) an `integer` that specifies the timeout in milliseconds for waiting for the DOM to settle. If not set, defaults to the timeout value specified during initialization.
182
183
 
183
184
  - **Returns:**
184
185
 
@@ -201,6 +202,7 @@ This constructor is used to create an instance of Stagehand.
201
202
  - `instruction`: a `string` providing instructions for extraction.
202
203
  - `schema`: a `z.AnyZodObject` defining the structure of the data to extract.
203
204
  - `modelName`: (optional) an `AvailableModel` string to specify the model to use.
205
+ - `domSettleTimeoutMs`: (optional) an `integer` that specifies the timeout in milliseconds for waiting for the DOM to settle. If not set, defaults to the timeout value specified during initialization.
204
206
 
205
207
  - **Returns:**
206
208
 
@@ -229,6 +231,7 @@ If you are looking for a specific element, you can also pass in an instruction t
229
231
 
230
232
  - `instruction`: a `string` providing instructions for the observation.
231
233
  - `useVision`: (optional) a `boolean` or `"fallback"` to determine if vision-based processing should be used. Defaults to `"fallback"`.
234
+ - `domSettleTimeoutMs`: (optional) an `integer` that specifies the timeout in milliseconds for waiting for the DOM to settle. If not set, defaults to the timeout value specified during initialization.
232
235
 
233
236
  - **Returns:**
234
237
 
package/dist/index.d.ts CHANGED
@@ -115,24 +115,27 @@ declare class Stagehand {
115
115
  private _extract;
116
116
  private _observe;
117
117
  private _act;
118
- act({ action, modelName, useVision, }: {
118
+ act({ action, modelName, useVision, domSettleTimeoutMs, }: {
119
119
  action: string;
120
120
  modelName?: AvailableModel;
121
121
  useVision?: "fallback" | boolean;
122
+ domSettleTimeoutMs?: number;
122
123
  }): Promise<{
123
124
  success: boolean;
124
125
  message: string;
125
126
  action: string;
126
127
  }>;
127
- extract<T extends z.AnyZodObject>({ instruction, schema, modelName, }: {
128
+ extract<T extends z.AnyZodObject>({ instruction, schema, modelName, domSettleTimeoutMs, }: {
128
129
  instruction: string;
129
130
  schema: T;
130
131
  modelName?: AvailableModel;
132
+ domSettleTimeoutMs?: number;
131
133
  }): Promise<z.infer<T>>;
132
134
  observe(options?: {
133
135
  instruction?: string;
134
136
  modelName?: AvailableModel;
135
137
  useVision?: boolean;
138
+ domSettleTimeoutMs?: number;
136
139
  }): Promise<{
137
140
  selector: string;
138
141
  description: string;
package/dist/index.js CHANGED
@@ -1513,7 +1513,7 @@ var Stagehand = class {
1513
1513
  this.verbose = verbose != null ? verbose : 0;
1514
1514
  this.debugDom = debugDom != null ? debugDom : false;
1515
1515
  this.defaultModelName = "gpt-4o";
1516
- this.domSettleTimeoutMs = domSettleTimeoutMs != null ? domSettleTimeoutMs : 6e4;
1516
+ this.domSettleTimeoutMs = domSettleTimeoutMs != null ? domSettleTimeoutMs : 3e4;
1517
1517
  this.headless = headless != null ? headless : false;
1518
1518
  this.browserBaseSessionCreateParams = browserBaseSessionCreateParams;
1519
1519
  this.browserbaseResumeSessionID = browserbaseResumeSessionID;
@@ -1747,14 +1747,15 @@ Trace: ${e.stack}`,
1747
1747
  content = {},
1748
1748
  chunksSeen = [],
1749
1749
  modelName,
1750
- requestId
1750
+ requestId,
1751
+ domSettleTimeoutMs
1751
1752
  }) {
1752
1753
  this.log({
1753
1754
  category: "extraction",
1754
1755
  message: `starting extraction '${instruction}'`,
1755
1756
  level: 1
1756
1757
  });
1757
- yield this._waitForSettledDom();
1758
+ yield this._waitForSettledDom(domSettleTimeoutMs);
1758
1759
  yield this.startDomDebug();
1759
1760
  const { outputString, chunk, chunks } = yield this.page.evaluate(
1760
1761
  (chunksSeen2) => window.processDom(chunksSeen2 != null ? chunksSeen2 : []),
@@ -1802,14 +1803,15 @@ Trace: ${e.stack}`,
1802
1803
  message: `continuing extraction, progress: '${newProgress}'`,
1803
1804
  level: 1
1804
1805
  });
1805
- yield this._waitForSettledDom();
1806
+ yield this._waitForSettledDom(domSettleTimeoutMs);
1806
1807
  return this._extract({
1807
1808
  instruction,
1808
1809
  schema,
1809
1810
  progress: newProgress,
1810
1811
  content: output,
1811
1812
  chunksSeen,
1812
- modelName
1813
+ modelName,
1814
+ domSettleTimeoutMs
1813
1815
  });
1814
1816
  }
1815
1817
  });
@@ -1820,7 +1822,8 @@ Trace: ${e.stack}`,
1820
1822
  useVision,
1821
1823
  fullPage,
1822
1824
  modelName,
1823
- requestId
1825
+ requestId,
1826
+ domSettleTimeoutMs
1824
1827
  }) {
1825
1828
  if (!instruction) {
1826
1829
  instruction = `Find elements that can be used for any future actions in the page. These may be navigation links, related pages, section/subsection links, buttons, or other interactive elements. Be comprehensive: if there are multiple elements that may be relevant for future actions, return all of them.`;
@@ -1831,7 +1834,7 @@ Trace: ${e.stack}`,
1831
1834
  message: `starting observation: ${instruction}`,
1832
1835
  level: 1
1833
1836
  });
1834
- yield this._waitForSettledDom();
1837
+ yield this._waitForSettledDom(domSettleTimeoutMs);
1835
1838
  yield this.startDomDebug();
1836
1839
  let { outputString, selectorMap } = yield this.page.evaluate(
1837
1840
  (fullPage2) => fullPage2 ? window.processAllOfDom() : window.processDom([]),
@@ -1891,7 +1894,8 @@ Trace: ${e.stack}`,
1891
1894
  useVision,
1892
1895
  verifierUseVision,
1893
1896
  retries = 0,
1894
- requestId
1897
+ requestId,
1898
+ domSettleTimeoutMs
1895
1899
  }) {
1896
1900
  var _a;
1897
1901
  const model = modelName != null ? modelName : this.defaultModelName;
@@ -1909,7 +1913,7 @@ Trace: ${e.stack}`,
1909
1913
  message: `Running / Continuing action: ${action} on page: ${this.page.url()}`,
1910
1914
  level: 2
1911
1915
  });
1912
- yield this._waitForSettledDom();
1916
+ yield this._waitForSettledDom(domSettleTimeoutMs);
1913
1917
  yield this.startDomDebug();
1914
1918
  this.log({
1915
1919
  category: "action",
@@ -1975,7 +1979,8 @@ Trace: ${e.stack}`,
1975
1979
  modelName,
1976
1980
  useVision,
1977
1981
  verifierUseVision,
1978
- requestId
1982
+ requestId,
1983
+ domSettleTimeoutMs
1979
1984
  });
1980
1985
  } else if (useVision === "fallback") {
1981
1986
  this.log({
@@ -1991,7 +1996,8 @@ Trace: ${e.stack}`,
1991
1996
  modelName,
1992
1997
  useVision: true,
1993
1998
  verifierUseVision,
1994
- requestId
1999
+ requestId,
2000
+ domSettleTimeoutMs
1995
2001
  });
1996
2002
  } else {
1997
2003
  if (this.enableCaching) {
@@ -2054,7 +2060,8 @@ Trace: ${e.stack}`,
2054
2060
  verifierUseVision,
2055
2061
  retries: retries + 1,
2056
2062
  chunksSeen,
2057
- requestId
2063
+ requestId,
2064
+ domSettleTimeoutMs
2058
2065
  });
2059
2066
  }
2060
2067
  }
@@ -2084,7 +2091,8 @@ Trace: ${e.stack}`,
2084
2091
  verifierUseVision,
2085
2092
  retries: retries + 1,
2086
2093
  chunksSeen,
2087
- requestId
2094
+ requestId,
2095
+ domSettleTimeoutMs
2088
2096
  });
2089
2097
  }
2090
2098
  }
@@ -2108,7 +2116,8 @@ Trace: ${e.stack}`,
2108
2116
  verifierUseVision,
2109
2117
  retries: retries + 1,
2110
2118
  chunksSeen,
2111
- requestId
2119
+ requestId,
2120
+ domSettleTimeoutMs
2112
2121
  });
2113
2122
  }
2114
2123
  }
@@ -2138,7 +2147,8 @@ Trace: ${e.stack}`,
2138
2147
  verifierUseVision,
2139
2148
  retries: retries + 1,
2140
2149
  chunksSeen,
2141
- requestId
2150
+ requestId,
2151
+ domSettleTimeoutMs
2142
2152
  });
2143
2153
  }
2144
2154
  }
@@ -2168,7 +2178,7 @@ Trace: ${e.stack}`,
2168
2178
  yield newOpenedTab.close();
2169
2179
  yield this.page.goto(newOpenedTab.url());
2170
2180
  yield this.page.waitForLoadState("domcontentloaded");
2171
- yield this._waitForSettledDom();
2181
+ yield this._waitForSettledDom(domSettleTimeoutMs);
2172
2182
  }
2173
2183
  yield Promise.race([
2174
2184
  this.page.waitForLoadState("networkidle"),
@@ -2302,7 +2312,8 @@ Trace: ${e.stack}`,
2302
2312
  chunksSeen,
2303
2313
  useVision,
2304
2314
  verifierUseVision,
2305
- requestId
2315
+ requestId,
2316
+ domSettleTimeoutMs
2306
2317
  });
2307
2318
  } else {
2308
2319
  this.log({
@@ -2333,7 +2344,8 @@ Trace: ${error.stack}`,
2333
2344
  verifierUseVision,
2334
2345
  retries: retries + 1,
2335
2346
  chunksSeen,
2336
- requestId
2347
+ requestId,
2348
+ domSettleTimeoutMs
2337
2349
  });
2338
2350
  }
2339
2351
  yield this._recordAction(action, "");
@@ -2352,7 +2364,8 @@ Trace: ${error.stack}`,
2352
2364
  return __async(this, arguments, function* ({
2353
2365
  action,
2354
2366
  modelName,
2355
- useVision = "fallback"
2367
+ useVision = "fallback",
2368
+ domSettleTimeoutMs
2356
2369
  }) {
2357
2370
  useVision = useVision != null ? useVision : "fallback";
2358
2371
  const requestId = Math.random().toString(36).substring(2);
@@ -2366,7 +2379,8 @@ Trace: ${error.stack}`,
2366
2379
  chunksSeen: [],
2367
2380
  useVision,
2368
2381
  verifierUseVision: useVision !== false,
2369
- requestId
2382
+ requestId,
2383
+ domSettleTimeoutMs
2370
2384
  }).catch((e) => {
2371
2385
  this.logger({
2372
2386
  category: "act",
@@ -2388,7 +2402,8 @@ Trace: ${e.stack}`
2388
2402
  return __async(this, arguments, function* ({
2389
2403
  instruction,
2390
2404
  schema,
2391
- modelName
2405
+ modelName,
2406
+ domSettleTimeoutMs
2392
2407
  }) {
2393
2408
  const requestId = Math.random().toString(36).substring(2);
2394
2409
  this.logger({
@@ -2399,7 +2414,8 @@ Trace: ${e.stack}`
2399
2414
  instruction,
2400
2415
  schema,
2401
2416
  modelName,
2402
- requestId
2417
+ requestId,
2418
+ domSettleTimeoutMs
2403
2419
  }).catch((e) => {
2404
2420
  this.logger({
2405
2421
  category: "extract",
@@ -2426,7 +2442,8 @@ Trace: ${e.stack}`
2426
2442
  modelName: options == null ? void 0 : options.modelName,
2427
2443
  useVision: (_b = options == null ? void 0 : options.useVision) != null ? _b : false,
2428
2444
  fullPage: false,
2429
- requestId
2445
+ requestId,
2446
+ domSettleTimeoutMs: options == null ? void 0 : options.domSettleTimeoutMs
2430
2447
  }).catch((e) => {
2431
2448
  this.logger({
2432
2449
  category: "observe",
package/package.json CHANGED
@@ -1,6 +1,6 @@
1
1
  {
2
2
  "name": "@browserbasehq/stagehand",
3
- "version": "1.1.0",
3
+ "version": "1.1.1",
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",