@@ -195,7 +195,7 @@ async function getBrowser(
195195
196196 const context = browser . contexts ( ) [ 0 ] ;
197197
198- return { browser, context, debugUrl, sessionUrl } ;
198+ return { browser, context, debugUrl, sessionUrl, sessionId } ;
199199 } else {
200200 logger ( {
201201 category : "init" ,
@@ -307,6 +307,8 @@ export class Stagehand {
307307 private llmClient : LLMClient ;
308308 public page : Page ;
309309 public context : BrowserContext ;
310+ public browserbaseSessionID ?: string ;
311+
310312 private env : "LOCAL" | "BROWSERBASE" ;
311313 private apiKey : string | undefined ;
312314 private projectId : string | undefined ;
@@ -377,23 +379,25 @@ export class Stagehand {
377379 "Passing parameters to init() is deprecated and will be removed in the next major version. Use constructor options instead." ,
378380 ) ;
379381 }
380- const { context, debugUrl, sessionUrl, contextPath } = await getBrowser (
381- this . apiKey ,
382- this . projectId ,
383- this . env ,
384- this . headless ,
385- this . logger ,
386- this . browserbaseSessionCreateParams ,
387- this . browserbaseResumeSessionID ,
388- ) . catch ( ( e ) => {
389- console . error ( "Error in init:" , e ) ;
390- const br : BrowserResult = {
391- context : undefined ,
392- debugUrl : undefined ,
393- sessionUrl : undefined ,
394- } ;
395- return br ;
396- } ) ;
382+ const { context, debugUrl, sessionUrl, contextPath, sessionId } =
383+ await getBrowser (
384+ this . apiKey ,
385+ this . projectId ,
386+ this . env ,
387+ this . headless ,
388+ this . logger ,
389+ this . browserbaseSessionCreateParams ,
390+ this . browserbaseResumeSessionID ,
391+ ) . catch ( ( e ) => {
392+ console . error ( "Error in init:" , e ) ;
393+ const br : BrowserResult = {
394+ context : undefined ,
395+ debugUrl : undefined ,
396+ sessionUrl : undefined ,
397+ sessionId : undefined ,
398+ } ;
399+ return br ;
400+ } ) ;
397401 this . contextPath = contextPath ;
398402 this . context = context ;
399403 this . page = context . pages ( ) [ 0 ] ;
@@ -455,8 +459,9 @@ export class Stagehand {
455459 verbose : this . verbose ,
456460 llmClient : this . llmClient ,
457461 } ) ;
462+ this . browserbaseSessionID = sessionId ;
458463
459- return { debugUrl, sessionUrl } ;
464+ return { debugUrl, sessionUrl, sessionId } ;
460465 }
461466
462467 /** @deprecated initFromPage is deprecated and will be removed in the next major version. */
0 commit comments