Skip to content

Commit 5c6f14b

Browse files
authored
Throw custom error if context is referenced without initialization (#353)
* Throw error if context is referenced without initialization. Also remove act/extract handlers from lib/index * changeset
1 parent c1cf345 commit 5c6f14b

File tree

2 files changed

+10
-7
lines changed

2 files changed

+10
-7
lines changed

Diff for: .changeset/fast-dodos-yawn.md

+5
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,5 @@
1+
---
2+
"@browserbasehq/stagehand": patch
3+
---
4+
5+
Throw custom error if context is referenced without initialization, remove act/extract handler from index

Diff for: lib/index.ts

+5-7
Original file line numberDiff line numberDiff line change
@@ -24,8 +24,6 @@ import {
2424
ObserveResult,
2525
} from "../types/stagehand";
2626
import { scriptContent } from "./dom/build/scriptContent";
27-
import { StagehandExtractHandler } from "./handlers/extractHandler";
28-
import { StagehandObserveHandler } from "./handlers/observeHandler";
2927
import { LLMClient } from "./llm/LLMClient";
3028
import { LLMProvider } from "./llm/LLMProvider";
3129
import { logLineToString } from "./utils";
@@ -320,7 +318,6 @@ export class Stagehand {
320318
public llmProvider: LLMProvider;
321319
public enableCaching: boolean;
322320

323-
private internalLogger: (logLine: LogLine) => void;
324321
private apiKey: string | undefined;
325322
private projectId: string | undefined;
326323
// We want external logger to accept async functions
@@ -330,9 +327,6 @@ export class Stagehand {
330327
private contextPath?: string;
331328
private llmClient: LLMClient;
332329

333-
private extractHandler?: StagehandExtractHandler;
334-
private observeHandler?: StagehandObserveHandler;
335-
336330
constructor(
337331
{
338332
env,
@@ -354,7 +348,6 @@ export class Stagehand {
354348
},
355349
) {
356350
this.externalLogger = logger || defaultLogger;
357-
this.internalLogger = this.log.bind(this);
358351
this.enableCaching =
359352
enableCaching ??
360353
(process.env.ENABLE_CACHING && process.env.ENABLE_CACHING === "true");
@@ -400,6 +393,11 @@ export class Stagehand {
400393
}
401394

402395
public get context(): BrowserContext {
396+
if (!this.stagehandContext) {
397+
throw new Error(
398+
"Stagehand not initialized. Make sure to await stagehand.init() first.",
399+
);
400+
}
403401
return this.stagehandContext.context;
404402
}
405403

0 commit comments

Comments
 (0)