Skip to content

Commit 743f633

Browse files
authored
fix: throw error if BROWSERBASE env is set without API key (fixes #592) (#642)
1 parent c87733f commit 743f633

File tree

1 file changed

+12
-7
lines changed

1 file changed

+12
-7
lines changed

lib/index.ts

Lines changed: 12 additions & 7 deletions
Original file line numberDiff line numberDiff line change
@@ -78,14 +78,11 @@ async function getBrowser(
7878
): Promise<BrowserResult> {
7979
if (env === "BROWSERBASE") {
8080
if (!apiKey) {
81-
logger({
82-
category: "init",
83-
message:
84-
"BROWSERBASE_API_KEY is required to use BROWSERBASE env. Defaulting to LOCAL.",
85-
level: 0,
86-
});
87-
env = "LOCAL";
81+
throw new Error(
82+
'BROWSERBASE_API_KEY is required to use the BROWSERBASE environment. Please set it in your .env or pass it in.'
83+
);
8884
}
85+
8986
if (!projectId) {
9087
logger({
9188
category: "init",
@@ -536,6 +533,14 @@ export class Stagehand {
536533
this.intEnv = env;
537534
this.apiKey = apiKey ?? process.env.BROWSERBASE_API_KEY;
538535
this.projectId = projectId ?? process.env.BROWSERBASE_PROJECT_ID;
536+
537+
if (this.intEnv === "BROWSERBASE" && !this.apiKey) {
538+
throw new Error(
539+
'Stagehand is set to use "BROWSERBASE" but no BROWSERBASE_API_KEY was found. Please set it in your .env or pass it explicitly.'
540+
);
541+
}
542+
543+
539544
this.verbose = verbose ?? 0;
540545
// Update logger verbosity level
541546
this.stagehandLogger.setVerbosity(this.verbose);

0 commit comments

Comments
 (0)