diff --git a/.changeset/wicked-rockets-beg.md b/.changeset/wicked-rockets-beg.md new file mode 100644 index 000000000..4aa39f686 --- /dev/null +++ b/.changeset/wicked-rockets-beg.md @@ -0,0 +1,5 @@ +--- +"@browserbasehq/stagehand": minor +--- + +Add sessionId to public params diff --git a/README.md b/README.md index fefb5ce44..f1f847c63 100644 --- a/README.md +++ b/README.md @@ -198,6 +198,7 @@ This constructor is used to create an instance of Stagehand. - A `Promise` that resolves to an object containing: - `debugUrl`: a `string` representing the URL for live debugging. This is only available when using a Browserbase browser. - `sessionUrl`: a `string` representing the session URL. This is only available when using a Browserbase browser. + - `sessionId`: a `string` representing the session ID. This is only available when using a Browserbase browser. - **Example:** ```javascript diff --git a/lib/index.ts b/lib/index.ts index 3540b3208..224c24360 100644 --- a/lib/index.ts +++ b/lib/index.ts @@ -195,7 +195,7 @@ async function getBrowser( const context = browser.contexts()[0]; - return { browser, context, debugUrl, sessionUrl }; + return { browser, context, debugUrl, sessionUrl, sessionId }; } else { logger({ category: "init", @@ -307,6 +307,8 @@ export class Stagehand { private llmClient: LLMClient; public page: Page; public context: BrowserContext; + public browserbaseSessionID?: string; + private env: "LOCAL" | "BROWSERBASE"; private apiKey: string | undefined; private projectId: string | undefined; @@ -377,23 +379,25 @@ export class Stagehand { "Passing parameters to init() is deprecated and will be removed in the next major version. Use constructor options instead.", ); } - const { context, debugUrl, sessionUrl, contextPath } = await getBrowser( - this.apiKey, - this.projectId, - this.env, - this.headless, - this.logger, - this.browserbaseSessionCreateParams, - this.browserbaseResumeSessionID, - ).catch((e) => { - console.error("Error in init:", e); - const br: BrowserResult = { - context: undefined, - debugUrl: undefined, - sessionUrl: undefined, - }; - return br; - }); + const { context, debugUrl, sessionUrl, contextPath, sessionId } = + await getBrowser( + this.apiKey, + this.projectId, + this.env, + this.headless, + this.logger, + this.browserbaseSessionCreateParams, + this.browserbaseResumeSessionID, + ).catch((e) => { + console.error("Error in init:", e); + const br: BrowserResult = { + context: undefined, + debugUrl: undefined, + sessionUrl: undefined, + sessionId: undefined, + }; + return br; + }); this.contextPath = contextPath; this.context = context; this.page = context.pages()[0]; @@ -455,8 +459,9 @@ export class Stagehand { verbose: this.verbose, llmClient: this.llmClient, }); + this.browserbaseSessionID = sessionId; - return { debugUrl, sessionUrl }; + return { debugUrl, sessionUrl, sessionId }; } /** @deprecated initFromPage is deprecated and will be removed in the next major version. */ diff --git a/types/browser.ts b/types/browser.ts index 940b5189f..9796fa60f 100644 --- a/types/browser.ts +++ b/types/browser.ts @@ -6,4 +6,5 @@ export interface BrowserResult { debugUrl?: string; sessionUrl?: string; contextPath?: string; + sessionId?: string; } diff --git a/types/stagehand.ts b/types/stagehand.ts index 422c42e79..583965733 100644 --- a/types/stagehand.ts +++ b/types/stagehand.ts @@ -22,11 +22,6 @@ export interface ConstructorParams { modelClientOptions?: ClientOptions; } -export interface InitResult { - debugUrl: string; - sessionUrl: string; -} - export interface InitOptions { /** @deprecated Pass this into the Stagehand constructor instead. This will be removed in the next major version. */ modelName?: AvailableModel; @@ -39,6 +34,7 @@ export interface InitOptions { export interface InitResult { debugUrl: string; sessionUrl: string; + sessionId: string; } export interface InitFromPageOptions {