Skip to content

Commit 178f5f0

Browse files
yash1744miguelg719
andauthored
Added support for automatic redirect to google.com in Agents (#640)
* Support for Automatic Redirect to google.com using CUA it now automatically redirects to google.com if page is pointing to empty url or "about:blank", which saves tokens by avoiding sending empty screenshots. * changeset * Update .changeset/rude-peas-stay.md Co-authored-by: Miguel <[email protected]> --------- Co-authored-by: Miguel <[email protected]>
1 parent b19ca34 commit 178f5f0

File tree

2 files changed

+16
-0
lines changed

2 files changed

+16
-0
lines changed

Diff for: .changeset/rude-peas-stay.md

+5
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,5 @@
1+
---
2+
"@browserbasehq/stagehand": patch
3+
---
4+
5+
Added support for stagehand agents to automatically redirect to https://google.com when the page URL is empty or set to about:blank, preventing empty screenshots and saving tokens.

Diff for: lib/handlers/agentHandler.ts

+11
Original file line numberDiff line numberDiff line change
@@ -126,6 +126,17 @@ export class StagehandAgentHandler {
126126
? { instruction: optionsOrInstruction }
127127
: optionsOrInstruction;
128128

129+
//Redirect to Google if the URL is empty or about:blank
130+
const currentUrl = this.stagehandPage.page.url();
131+
if (!currentUrl || currentUrl === "about:blank") {
132+
this.logger({
133+
category: "agent",
134+
message: `Page URL is empty or about:blank. Redirecting to www.google.com...`,
135+
level: 0,
136+
});
137+
await this.stagehandPage.page.goto("https://www.google.com");
138+
}
139+
129140
this.logger({
130141
category: "agent",
131142
message: `Executing agent task: ${options.instruction}`,

0 commit comments

Comments
 (0)