@browserbasehq/stagehand 3.0.7-alpha-934f492ec587bef81f0ce75b45a35b44ab545712 → 3.0.7-alpha-0d2b398cd40b32a9ecaf28ede70853036b7c91bd

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 CHANGED
@@ -817,6 +817,9 @@ declare class AgentAbortError extends StagehandError {
817
817
  readonly reason: string;
818
818
  constructor(reason?: string);
819
819
  }
820
+ declare class StagehandClosedError extends StagehandError {
821
+ constructor();
822
+ }
820
823
 
821
824
  declare class AISdkClient extends LLMClient {
822
825
  type: "aisdk";
@@ -1530,63 +1533,32 @@ declare class Page {
1530
1533
  * on the top-level page target's session. Coordinates are relative to the
1531
1534
  * viewport origin (top-left). Does not scroll.
1532
1535
  */
1533
- click(x: number, y: number, options: {
1534
- button?: "left" | "right" | "middle";
1535
- clickCount?: number;
1536
- returnXpath: true;
1537
- }): Promise<string>;
1538
1536
  click(x: number, y: number, options?: {
1539
1537
  button?: "left" | "right" | "middle";
1540
1538
  clickCount?: number;
1541
- returnXpath?: false;
1542
- }): Promise<void>;
1543
- click(x: number, y: number, options: {
1544
- button?: "left" | "right" | "middle";
1545
- clickCount?: number;
1546
- returnXpath: boolean;
1547
- }): Promise<void | string>;
1539
+ returnXpath?: boolean;
1540
+ }): Promise<string>;
1548
1541
  /**
1549
1542
  * Hover at absolute page coordinates (CSS pixels).
1550
1543
  * Dispatches mouseMoved via CDP Input domain on the top-level page target's
1551
1544
  * session.
1552
1545
  */
1553
- hover(x: number, y: number, options: {
1554
- returnXpath: true;
1555
- }): Promise<string>;
1556
1546
  hover(x: number, y: number, options?: {
1557
- returnXpath?: false;
1558
- }): Promise<void>;
1559
- scroll(x: number, y: number, deltaX: number, deltaY: number, options: {
1560
- returnXpath: true;
1547
+ returnXpath?: boolean;
1561
1548
  }): Promise<string>;
1562
1549
  scroll(x: number, y: number, deltaX: number, deltaY: number, options?: {
1563
- returnXpath?: false;
1564
- }): Promise<void>;
1565
- scroll(x: number, y: number, deltaX: number, deltaY: number, options: {
1566
- returnXpath: boolean;
1567
- }): Promise<void | string>;
1550
+ returnXpath?: boolean;
1551
+ }): Promise<string>;
1568
1552
  /**
1569
1553
  * Drag from (fromX, fromY) to (toX, toY) using mouse events.
1570
1554
  * Sends mouseMoved → mousePressed → mouseMoved (steps) → mouseReleased.
1571
1555
  */
1572
- dragAndDrop(fromX: number, fromY: number, toX: number, toY: number, options: {
1573
- button?: "left" | "right" | "middle";
1574
- steps?: number;
1575
- delay?: number;
1576
- returnXpath: true;
1577
- }): Promise<[string, string]>;
1578
1556
  dragAndDrop(fromX: number, fromY: number, toX: number, toY: number, options?: {
1579
1557
  button?: "left" | "right" | "middle";
1580
1558
  steps?: number;
1581
1559
  delay?: number;
1582
- returnXpath?: false;
1583
- }): Promise<void>;
1584
- dragAndDrop(fromX: number, fromY: number, toX: number, toY: number, options: {
1585
- button?: "left" | "right" | "middle";
1586
- steps?: number;
1587
- delay?: number;
1588
- returnXpath: boolean;
1589
- }): Promise<void | [string, string]>;
1560
+ returnXpath?: boolean;
1561
+ }): Promise<[string, string]>;
1590
1562
  /**
1591
1563
  * Type a string by dispatching keyDown/keyUp events per character.
1592
1564
  * Focus must already be on the desired element. Uses CDP Input.dispatchKeyEvent
@@ -2474,4 +2446,4 @@ declare class V3Evaluator {
2474
2446
  private _evaluateWithMultipleScreenshots;
2475
2447
  }
2476
2448
 
2477
- export { type AISDKCustomProvider, type AISDKProvider, AISdkClient, AVAILABLE_CUA_MODELS, type ActOptions, type ActResult, ActTimeoutError, type Action, type ActionExecutionResult, AgentAbortError, type AgentAction, type AgentCallbacks, type AgentConfig, type AgentContext, type AgentExecuteCallbacks, type AgentExecuteOptions, type AgentExecuteOptionsBase, type AgentExecutionOptions, type AgentHandlerOptions, type AgentInstance, type AgentModelConfig, AgentProvider, type AgentProviderType, type AgentResult, AgentScreenshotProviderError, type AgentState, type AgentStreamCallbacks, type AgentStreamExecuteOptions, type AgentStreamResult, type AgentType, AnnotatedScreenshotText, type AnthropicClientOptions, type AnthropicContentBlock, type AnthropicJsonSchemaObject, type AnthropicMessage, type AnthropicTextBlock, type AnthropicToolResult, type AnyPage, type AvailableCuaModel, type AvailableModel, BrowserbaseSessionNotFoundError, CaptchaTimeoutError, type ChatCompletionOptions, type ChatMessage, type ChatMessageContent, type ChatMessageImageContent, type ChatMessageTextContent, type ClientOptions, type ComputerCallItem, ConnectionTimeoutError, type ConsoleListener, ConsoleMessage, ContentFrameNotFoundError, type CreateChatCompletionOptions, CreateChatCompletionResponseError, CuaModelRequiredError, ElementNotVisibleError, ExperimentalApiConflictError, ExperimentalNotConfiguredError, type ExtractOptions, type ExtractResult, ExtractTimeoutError, type FunctionCallItem, type GoogleServiceAccountCredentials, type GoogleVertexProviderSettings, HandlerNotInitializedError, type HistoryEntry, type InferStagehandSchema, InvalidAISDKModelFormatError, type JsonSchema, type JsonSchemaDocument, type JsonSchemaProperty, LLMClient, type LLMParsedResponse, type LLMResponse, LLMResponseError, type LLMTool, type LLMUsage, LOG_LEVEL_NAMES, type LoadState, type LocalBrowserLaunchOptions, type LogLevel, type LogLine, type Logger, MCPConnectionError, MissingEnvironmentVariableError, MissingLLMConfigurationError, type ModelConfiguration, type ModelProvider, type NonStreamingAgentInstance, type ObserveOptions, ObserveTimeoutError, type OpenAIClientOptions, Page, PageNotFoundError, Response$1 as Response, ResponseBodyError, type ResponseInputItem, type ResponseItem, ResponseParseError, V3 as Stagehand, StagehandAPIError, StagehandAPIUnauthorizedError, StagehandClickError, StagehandDefaultError, StagehandDomProcessError, StagehandElementNotFoundError, StagehandEnvironmentError, StagehandError, StagehandEvalError, StagehandHttpError, StagehandIframeError, StagehandInitError, StagehandInvalidArgumentError, type StagehandMetrics, StagehandMissingArgumentError, StagehandNotInitializedError, StagehandResponseBodyError, StagehandResponseParseError, StagehandServerError, StagehandShadowRootMissingError, StagehandShadowSegmentEmptyError, StagehandShadowSegmentNotFoundError, type StagehandZodObject, type StagehandZodSchema, type StreamingAgentInstance, StreamingCallbacksInNonStreamingModeError, TimeoutError, type ToolUseItem, UnsupportedAISDKModelProviderError, UnsupportedModelError, UnsupportedModelProviderError, V3, type V3Env, V3Evaluator, V3FunctionName, type V3Options, XPathResolutionError, ZodSchemaValidationError, connectToMCPServer, defaultExtractSchema, getZodType, injectUrls, isRunningInBun, isZod3Schema, isZod4Schema, jsonSchemaToZod, loadApiKeyFromEnv, modelToAgentProviderMap, pageTextSchema, providerEnvVarMap, toGeminiSchema, toJsonSchema, transformSchema, trimTrailingTextNode, validateZodSchema };
2449
+ export { type AISDKCustomProvider, type AISDKProvider, AISdkClient, AVAILABLE_CUA_MODELS, type ActOptions, type ActResult, ActTimeoutError, type Action, type ActionExecutionResult, AgentAbortError, type AgentAction, type AgentCallbacks, type AgentConfig, type AgentContext, type AgentExecuteCallbacks, type AgentExecuteOptions, type AgentExecuteOptionsBase, type AgentExecutionOptions, type AgentHandlerOptions, type AgentInstance, type AgentModelConfig, AgentProvider, type AgentProviderType, type AgentResult, AgentScreenshotProviderError, type AgentState, type AgentStreamCallbacks, type AgentStreamExecuteOptions, type AgentStreamResult, type AgentType, AnnotatedScreenshotText, type AnthropicClientOptions, type AnthropicContentBlock, type AnthropicJsonSchemaObject, type AnthropicMessage, type AnthropicTextBlock, type AnthropicToolResult, type AnyPage, type AvailableCuaModel, type AvailableModel, BrowserbaseSessionNotFoundError, CaptchaTimeoutError, type ChatCompletionOptions, type ChatMessage, type ChatMessageContent, type ChatMessageImageContent, type ChatMessageTextContent, type ClientOptions, type ComputerCallItem, ConnectionTimeoutError, type ConsoleListener, ConsoleMessage, ContentFrameNotFoundError, type CreateChatCompletionOptions, CreateChatCompletionResponseError, CuaModelRequiredError, ElementNotVisibleError, ExperimentalApiConflictError, ExperimentalNotConfiguredError, type ExtractOptions, type ExtractResult, ExtractTimeoutError, type FunctionCallItem, type GoogleServiceAccountCredentials, type GoogleVertexProviderSettings, HandlerNotInitializedError, type HistoryEntry, type InferStagehandSchema, InvalidAISDKModelFormatError, type JsonSchema, type JsonSchemaDocument, type JsonSchemaProperty, LLMClient, type LLMParsedResponse, type LLMResponse, LLMResponseError, type LLMTool, type LLMUsage, LOG_LEVEL_NAMES, type LoadState, type LocalBrowserLaunchOptions, type LogLevel, type LogLine, type Logger, MCPConnectionError, MissingEnvironmentVariableError, MissingLLMConfigurationError, type ModelConfiguration, type ModelProvider, type NonStreamingAgentInstance, type ObserveOptions, ObserveTimeoutError, type OpenAIClientOptions, Page, PageNotFoundError, Response$1 as Response, ResponseBodyError, type ResponseInputItem, type ResponseItem, ResponseParseError, V3 as Stagehand, StagehandAPIError, StagehandAPIUnauthorizedError, StagehandClickError, StagehandClosedError, StagehandDefaultError, StagehandDomProcessError, StagehandElementNotFoundError, StagehandEnvironmentError, StagehandError, StagehandEvalError, StagehandHttpError, StagehandIframeError, StagehandInitError, StagehandInvalidArgumentError, type StagehandMetrics, StagehandMissingArgumentError, StagehandNotInitializedError, StagehandResponseBodyError, StagehandResponseParseError, StagehandServerError, StagehandShadowRootMissingError, StagehandShadowSegmentEmptyError, StagehandShadowSegmentNotFoundError, type StagehandZodObject, type StagehandZodSchema, type StreamingAgentInstance, StreamingCallbacksInNonStreamingModeError, TimeoutError, type ToolUseItem, UnsupportedAISDKModelProviderError, UnsupportedModelError, UnsupportedModelProviderError, V3, type V3Env, V3Evaluator, V3FunctionName, type V3Options, XPathResolutionError, ZodSchemaValidationError, connectToMCPServer, defaultExtractSchema, getZodType, injectUrls, isRunningInBun, isZod3Schema, isZod4Schema, jsonSchemaToZod, loadApiKeyFromEnv, modelToAgentProviderMap, pageTextSchema, providerEnvVarMap, toGeminiSchema, toJsonSchema, transformSchema, trimTrailingTextNode, validateZodSchema };
package/dist/index.js CHANGED
@@ -179,12 +179,12 @@ 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-934f492ec587bef81f0ce75b45a35b44ab545712";
182
+ STAGEHAND_VERSION = "3.0.7-alpha-0d2b398cd40b32a9ecaf28ede70853036b7c91bd";
183
183
  }
184
184
  });
185
185
 
186
186
  // lib/v3/types/public/sdkErrors.ts
187
- var StagehandError, StagehandDefaultError, StagehandEnvironmentError, MissingEnvironmentVariableError, UnsupportedModelError, UnsupportedModelProviderError, UnsupportedAISDKModelProviderError, InvalidAISDKModelFormatError, StagehandNotInitializedError, BrowserbaseSessionNotFoundError, CaptchaTimeoutError, MissingLLMConfigurationError, HandlerNotInitializedError, StagehandInvalidArgumentError, StagehandElementNotFoundError, AgentScreenshotProviderError, StagehandMissingArgumentError, CreateChatCompletionResponseError, StagehandEvalError, StagehandDomProcessError, StagehandClickError, LLMResponseError, StagehandIframeError, ContentFrameNotFoundError, XPathResolutionError, ExperimentalApiConflictError, ExperimentalNotConfiguredError, CuaModelRequiredError, ZodSchemaValidationError, StagehandInitError, MCPConnectionError, StagehandShadowRootMissingError, StagehandShadowSegmentEmptyError, StagehandShadowSegmentNotFoundError, ElementNotVisibleError, ResponseBodyError, ResponseParseError, TimeoutError, ActTimeoutError, ExtractTimeoutError, ObserveTimeoutError, PageNotFoundError, ConnectionTimeoutError, StreamingCallbacksInNonStreamingModeError, AgentAbortError;
187
+ var StagehandError, StagehandDefaultError, StagehandEnvironmentError, MissingEnvironmentVariableError, UnsupportedModelError, UnsupportedModelProviderError, UnsupportedAISDKModelProviderError, InvalidAISDKModelFormatError, StagehandNotInitializedError, BrowserbaseSessionNotFoundError, CaptchaTimeoutError, MissingLLMConfigurationError, HandlerNotInitializedError, StagehandInvalidArgumentError, StagehandElementNotFoundError, AgentScreenshotProviderError, StagehandMissingArgumentError, CreateChatCompletionResponseError, StagehandEvalError, StagehandDomProcessError, StagehandClickError, LLMResponseError, StagehandIframeError, ContentFrameNotFoundError, XPathResolutionError, ExperimentalApiConflictError, ExperimentalNotConfiguredError, CuaModelRequiredError, ZodSchemaValidationError, StagehandInitError, MCPConnectionError, StagehandShadowRootMissingError, StagehandShadowSegmentEmptyError, StagehandShadowSegmentNotFoundError, ElementNotVisibleError, ResponseBodyError, ResponseParseError, TimeoutError, ActTimeoutError, ExtractTimeoutError, ObserveTimeoutError, PageNotFoundError, ConnectionTimeoutError, StreamingCallbacksInNonStreamingModeError, AgentAbortError, StagehandClosedError;
188
188
  var init_sdkErrors = __esm({
189
189
  "lib/v3/types/public/sdkErrors.ts"() {
190
190
  init_version();
@@ -477,6 +477,11 @@ ${JSON.stringify(issues, null, 2)}`);
477
477
  this.reason = reason || "aborted";
478
478
  }
479
479
  };
480
+ StagehandClosedError = class extends StagehandError {
481
+ constructor() {
482
+ super("Stagehand session was closed");
483
+ }
484
+ };
480
485
  }
481
486
  });
482
487
 
@@ -26242,7 +26247,7 @@ var init_page = __esm({
26242
26247
  clickCount: i2
26243
26248
  });
26244
26249
  }
26245
- if (options == null ? void 0 : options.returnXpath) return xpathResult != null ? xpathResult : "";
26250
+ return xpathResult != null ? xpathResult : "";
26246
26251
  });
26247
26252
  }
26248
26253
  hover(x2, y, options) {
@@ -26287,7 +26292,7 @@ var init_page = __esm({
26287
26292
  y,
26288
26293
  button: "none"
26289
26294
  });
26290
- if (options == null ? void 0 : options.returnXpath) return xpathResult != null ? xpathResult : "";
26295
+ return xpathResult != null ? xpathResult : "";
26291
26296
  });
26292
26297
  }
26293
26298
  scroll(x2, y, deltaX, deltaY, options) {
@@ -26315,7 +26320,7 @@ var init_page = __esm({
26315
26320
  deltaX,
26316
26321
  deltaY
26317
26322
  });
26318
- if (options == null ? void 0 : options.returnXpath) return xpathResult != null ? xpathResult : "";
26323
+ return xpathResult != null ? xpathResult : "";
26319
26324
  });
26320
26325
  }
26321
26326
  dragAndDrop(fromX, fromY, toX, toY, options) {
@@ -26389,7 +26394,7 @@ var init_page = __esm({
26389
26394
  buttons: buttonMask(button),
26390
26395
  clickCount: 1
26391
26396
  });
26392
- if (options == null ? void 0 : options.returnXpath) return [fromXpath != null ? fromXpath : "", toXpath != null ? toXpath : ""];
26397
+ return [fromXpath != null ? fromXpath : "", toXpath != null ? toXpath : ""];
26393
26398
  });
26394
26399
  }
26395
26400
  type(text, options) {
@@ -26869,6 +26874,7 @@ __export(v3_exports, {
26869
26874
  StagehandAPIError: () => StagehandAPIError,
26870
26875
  StagehandAPIUnauthorizedError: () => StagehandAPIUnauthorizedError,
26871
26876
  StagehandClickError: () => StagehandClickError,
26877
+ StagehandClosedError: () => StagehandClosedError,
26872
26878
  StagehandDefaultError: () => StagehandDefaultError,
26873
26879
  StagehandDomProcessError: () => StagehandDomProcessError,
26874
26880
  StagehandElementNotFoundError: () => StagehandElementNotFoundError,
@@ -31924,6 +31930,9 @@ var AnthropicCUAClient = class extends AgentClient {
31924
31930
  });
31925
31931
  yield this.actionHandler(action);
31926
31932
  } catch (error) {
31933
+ if (error instanceof StagehandClosedError) {
31934
+ throw error;
31935
+ }
31927
31936
  const errorMessage = error instanceof Error ? error.message : String(error);
31928
31937
  logger({
31929
31938
  category: "agent",
@@ -32763,6 +32772,9 @@ var OpenAICUAClient = class extends AgentClient {
32763
32772
  }
32764
32773
  nextInputItems.push(outputItem);
32765
32774
  } catch (error) {
32775
+ if (error instanceof StagehandClosedError) {
32776
+ throw error;
32777
+ }
32766
32778
  const errorMessage = error instanceof Error ? error.message : String(error);
32767
32779
  logger({
32768
32780
  category: "agent",
@@ -32790,6 +32802,9 @@ var OpenAICUAClient = class extends AgentClient {
32790
32802
  }
32791
32803
  nextInputItems.push(errorOutputItem);
32792
32804
  } catch (screenshotError) {
32805
+ if (screenshotError instanceof StagehandClosedError) {
32806
+ throw screenshotError;
32807
+ }
32793
32808
  logger({
32794
32809
  category: "agent",
32795
32810
  message: `Error capturing screenshot: ${String(screenshotError)}`,
@@ -32845,6 +32860,9 @@ var OpenAICUAClient = class extends AgentClient {
32845
32860
  };
32846
32861
  nextInputItems.push(outputItem);
32847
32862
  } catch (error) {
32863
+ if (error instanceof StagehandClosedError) {
32864
+ throw error;
32865
+ }
32848
32866
  const errorMessage = error instanceof Error ? error.message : String(error);
32849
32867
  logger({
32850
32868
  category: "agent",
@@ -33396,6 +33414,9 @@ var GoogleCUAClient = class extends AgentClient {
33396
33414
  yield new Promise((resolve3) => setTimeout(resolve3, delay2));
33397
33415
  }
33398
33416
  } catch (actionError) {
33417
+ if (actionError instanceof StagehandClosedError) {
33418
+ throw actionError;
33419
+ }
33399
33420
  logger({
33400
33421
  category: "agent",
33401
33422
  message: `Error executing action ${action.type}: ${actionError}`,
@@ -34522,6 +34543,7 @@ var AgentProvider = class _AgentProvider {
34522
34543
 
34523
34544
  // lib/v3/handlers/v3CuaAgentHandler.ts
34524
34545
  init_flowLogger();
34546
+ init_sdkErrors();
34525
34547
  var V3CuaAgentHandler = class {
34526
34548
  constructor(v3, logger, options, tools) {
34527
34549
  this.v3 = v3;
@@ -34538,14 +34560,25 @@ var V3CuaAgentHandler = class {
34538
34560
  this.setupAgentClient();
34539
34561
  this.agent = client;
34540
34562
  }
34563
+ /**
34564
+ * Ensures the V3 context is still available (not closed).
34565
+ * Throws StagehandClosedError if stagehand.close() was called.
34566
+ */
34567
+ ensureNotClosed() {
34568
+ if (!this.v3.context) {
34569
+ throw new StagehandClosedError();
34570
+ }
34571
+ }
34541
34572
  setupAgentClient() {
34542
34573
  this.agentClient.setScreenshotProvider(() => __async(this, null, function* () {
34574
+ this.ensureNotClosed();
34543
34575
  const page = yield this.v3.context.awaitActivePage();
34544
34576
  const base64 = yield page.screenshot({ fullPage: false });
34545
34577
  return base64.toString("base64");
34546
34578
  }));
34547
34579
  this.agentClient.setActionHandler((action) => __async(this, null, function* () {
34548
34580
  var _a4, _b, _c;
34581
+ this.ensureNotClosed();
34549
34582
  action.pageUrl = (yield this.v3.context.awaitActivePage()).url();
34550
34583
  const defaultDelay = 500;
34551
34584
  const waitBetween = ((_a4 = this.options.clientOptions) == null ? void 0 : _a4.waitBetweenActions) || defaultDelay;
@@ -66078,6 +66111,7 @@ I'm providing ${screenshots.length} screenshots showing the progression of the t
66078
66111
  StagehandAPIError,
66079
66112
  StagehandAPIUnauthorizedError,
66080
66113
  StagehandClickError,
66114
+ StagehandClosedError,
66081
66115
  StagehandDefaultError,
66082
66116
  StagehandDomProcessError,
66083
66117
  StagehandElementNotFoundError,
package/package.json CHANGED
@@ -1,6 +1,6 @@
1
1
  {
2
2
  "name": "@browserbasehq/stagehand",
3
- "version": "3.0.7-alpha-934f492ec587bef81f0ce75b45a35b44ab545712",
3
+ "version": "3.0.7-alpha-0d2b398cd40b32a9ecaf28ede70853036b7c91bd",
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",