@@ -886,12 +886,6 @@ export class V3 {
886886
887887 if ( this . opts . env === "BROWSERBASE" ) {
888888 const { apiKey, projectId } = this . requireBrowserbaseCreds ( ) ;
889- if ( ! apiKey || ! projectId ) {
890- throw new MissingEnvironmentVariableError (
891- "BROWSERBASE_API_KEY and BROWSERBASE_PROJECT_ID" ,
892- "Browserbase environment" ,
893- ) ;
894- }
895889 this . logger ( {
896890 category : "init" ,
897891 message : "Starting browserbase session" ,
@@ -912,18 +906,25 @@ export class V3 {
912906 logger : this . logger ,
913907 serverCache : this . opts . serverCache ,
914908 } ) ;
909+ const {
910+ projectId : overrideProjectId ,
911+ browserSettings,
912+ userMetadata,
913+ ...restSessionParams
914+ } = effectiveSessionParams ;
915+ const resolvedProjectId = overrideProjectId ?? projectId ;
915916 const createSessionPayload = {
916- projectId : effectiveSessionParams . projectId ?? projectId ,
917- ...effectiveSessionParams ,
917+ ... ( resolvedProjectId ? { projectId : resolvedProjectId } : { } ) ,
918+ ...restSessionParams ,
918919 browserSettings : {
919- ...( effectiveSessionParams . browserSettings ?? { } ) ,
920- viewport : effectiveSessionParams . browserSettings ?. viewport ?? {
920+ ...( browserSettings ?? { } ) ,
921+ viewport : browserSettings ?. viewport ?? {
921922 width : 1288 ,
922923 height : 711 ,
923924 } ,
924925 } ,
925926 userMetadata : {
926- ...( effectiveSessionParams . userMetadata ?? { } ) ,
927+ ...( userMetadata ?? { } ) ,
927928 stagehand : "true" ,
928929 } ,
929930 } ;
@@ -1474,7 +1475,10 @@ export class V3 {
14741475 }
14751476
14761477 /** Guard: ensure Browserbase credentials exist in options. */
1477- private requireBrowserbaseCreds ( ) : { apiKey : string ; projectId : string } {
1478+ private requireBrowserbaseCreds ( ) : {
1479+ apiKey : string ;
1480+ projectId ?: string ;
1481+ } {
14781482 let { apiKey, projectId } = this . opts ;
14791483
14801484 // Fall back to environment variables if not explicitly provided
@@ -1484,19 +1488,16 @@ export class V3 {
14841488 projectId =
14851489 process . env . BROWSERBASE_PROJECT_ID ?? process . env . BB_PROJECT_ID ;
14861490
1487- if ( ! apiKey || ! projectId ) {
1488- const missing : string [ ] = [ ] ;
1489- if ( ! apiKey ) missing . push ( "BROWSERBASE_API_KEY" ) ;
1490- if ( ! projectId ) missing . push ( "BROWSERBASE_PROJECT_ID" ) ;
1491+ if ( ! apiKey ) {
14911492 throw new MissingEnvironmentVariableError (
1492- missing . join ( ", " ) ,
1493+ "BROWSERBASE_API_KEY" ,
14931494 "Browserbase" ,
14941495 ) ;
14951496 }
14961497
14971498 // Cache resolved values back into opts for consistency
14981499 this . opts . apiKey = apiKey ;
1499- this . opts . projectId = projectId ;
1500+ if ( projectId ) this . opts . projectId = projectId ;
15001501
15011502 // Informational log
15021503 this . logger ( {
0 commit comments