Skip to content

Commit 7b0b996

Browse files
sameelarifseanmcguire12kamath
authored
test env input (#619)
* test env input * add disablePino parameter * changeset * Update .changeset/true-moles-hear.md Co-authored-by: Anirudh Kamath <[email protected]> * Update types/stagehand.ts Co-authored-by: Anirudh Kamath <[email protected]> * update slack link in error message --------- Co-authored-by: Sean McGuire <[email protected]> Co-authored-by: Sean McGuire <[email protected]> Co-authored-by: Anirudh Kamath <[email protected]>
1 parent affa564 commit 7b0b996

File tree

4 files changed

+25
-10
lines changed

4 files changed

+25
-10
lines changed

.changeset/true-moles-hear.md

Lines changed: 5 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,5 @@
1+
---
2+
"@browserbasehq/stagehand": minor
3+
---
4+
5+
add disablePino flag to stagehand constructor params

lib/index.ts

Lines changed: 15 additions & 9 deletions
Original file line numberDiff line numberDiff line change
@@ -54,14 +54,15 @@ const DEFAULT_MODEL_NAME = "gpt-4o";
5454
// Initialize the global logger
5555
let globalLogger: StagehandLogger;
5656

57-
const defaultLogger = async (logLine: LogLine) => {
57+
const defaultLogger = async (logLine: LogLine, disablePino?: boolean) => {
5858
if (!globalLogger) {
59-
// Create a global logger with Pino enabled for the default logger
60-
// but disable it in test environments
61-
globalLogger = new StagehandLogger({
62-
pretty: true,
63-
// Let StagehandLogger auto-detect test environment and disable Pino if needed
64-
});
59+
globalLogger = new StagehandLogger(
60+
{
61+
pretty: true,
62+
usePino: !disablePino,
63+
},
64+
undefined,
65+
);
6566
}
6667
globalLogger.log(logLine);
6768
};
@@ -417,6 +418,7 @@ export class Stagehand {
417418
public readonly actTimeoutMs: number;
418419
public readonly logInferenceToFile?: boolean;
419420
private stagehandLogger: StagehandLogger;
421+
private disablePino: boolean;
420422

421423
protected setActivePage(page: StagehandPage): void {
422424
this.stagehandPage = page;
@@ -507,17 +509,20 @@ export class Stagehand {
507509
waitForCaptchaSolves = false,
508510
logInferenceToFile = false,
509511
selfHeal = false,
512+
disablePino,
510513
}: ConstructorParams = {
511514
env: "BROWSERBASE",
512515
},
513516
) {
514-
this.externalLogger = logger || defaultLogger;
517+
this.externalLogger =
518+
logger || ((logLine: LogLine) => defaultLogger(logLine, disablePino));
515519

516520
// Initialize the Stagehand logger
517521
this.stagehandLogger = new StagehandLogger(
518522
{
519523
pretty: true,
520-
usePino: !logger, // Only use Pino if no custom logger is provided
524+
// use pino if pino is enabled, and there is no custom logger
525+
usePino: !logger && !disablePino,
521526
},
522527
this.externalLogger,
523528
);
@@ -580,6 +585,7 @@ export class Stagehand {
580585
}
581586
this.logInferenceToFile = logInferenceToFile;
582587
this.selfHeal = selfHeal;
588+
this.disablePino = disablePino;
583589
}
584590

585591
private registerSignalHandlers() {

types/stagehand.ts

Lines changed: 4 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -92,6 +92,10 @@ export interface ConstructorParams {
9292
*/
9393
logInferenceToFile?: boolean;
9494
selfHeal?: boolean;
95+
/**
96+
* Disable Pino (helpful for Next.js or test environments)
97+
*/
98+
disablePino?: boolean;
9599
}
96100

97101
export interface InitResult {

types/stagehandErrors.ts

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -8,7 +8,7 @@ export class StagehandError extends Error {
88
export class StagehandDefaultError extends StagehandError {
99
constructor() {
1010
super(
11-
`\nHey! We're sorry you ran into an error. \nIf you need help, please open a Github issue or send us a Slack message: https://stagehand-dev.slack.com\n`,
11+
`\nHey! We're sorry you ran into an error. \nIf you need help, please open a Github issue or send us a Slack message: https://stagehand-dev.slack\n`,
1212
);
1313
}
1414
}

0 commit comments

Comments
 (0)