-
Notifications
You must be signed in to change notification settings - Fork 3.7k
feat: add browser automation tool via agent-browser CLI #318
New issue
Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.
By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.
Already on GitHub? Sign in to your account
base: main
Are you sure you want to change the base?
Changes from all commits
File filter
Filter by extension
Conversations
Jump to
Diff view
Diff view
There are no files selected for viewing
| Original file line number | Diff line number | Diff line change | ||||||||||
|---|---|---|---|---|---|---|---|---|---|---|---|---|
| @@ -0,0 +1,229 @@ | ||||||||||||
| package tools | ||||||||||||
|
|
||||||||||||
| import ( | ||||||||||||
| "bytes" | ||||||||||||
| "context" | ||||||||||||
| "fmt" | ||||||||||||
| "os/exec" | ||||||||||||
| "strings" | ||||||||||||
| "time" | ||||||||||||
| ) | ||||||||||||
|
|
||||||||||||
| // BrowserToolOptions configures the BrowserTool. | ||||||||||||
| type BrowserToolOptions struct { | ||||||||||||
| Session string // Session name for isolation | ||||||||||||
| Headless bool // Run in headless mode (default true) | ||||||||||||
| Timeout int // Command timeout in seconds (default 30) | ||||||||||||
| CDPPort int // Chrome DevTools Protocol port (default 9222) | ||||||||||||
| } | ||||||||||||
|
|
||||||||||||
| // BrowserTool wraps the agent-browser CLI for headless browser automation. | ||||||||||||
| // It delegates all browser complexity to the external `agent-browser` binary. | ||||||||||||
| type BrowserTool struct { | ||||||||||||
| session string | ||||||||||||
| headless bool | ||||||||||||
| timeout time.Duration | ||||||||||||
| cdpPort int | ||||||||||||
| } | ||||||||||||
|
|
||||||||||||
| // NewBrowserTool creates a new BrowserTool with the given options. | ||||||||||||
| func NewBrowserTool(opts BrowserToolOptions) *BrowserTool { | ||||||||||||
| timeout := 30 | ||||||||||||
| if opts.Timeout > 0 { | ||||||||||||
| timeout = opts.Timeout | ||||||||||||
| } | ||||||||||||
| cdpPort := 9222 | ||||||||||||
| if opts.CDPPort > 0 { | ||||||||||||
| cdpPort = opts.CDPPort | ||||||||||||
| } | ||||||||||||
| return &BrowserTool{ | ||||||||||||
| session: opts.Session, | ||||||||||||
| headless: opts.Headless, | ||||||||||||
| timeout: time.Duration(timeout) * time.Second, | ||||||||||||
| cdpPort: cdpPort, | ||||||||||||
| } | ||||||||||||
| } | ||||||||||||
|
|
||||||||||||
| func (t *BrowserTool) Name() string { | ||||||||||||
| return "browser" | ||||||||||||
| } | ||||||||||||
|
|
||||||||||||
| func (t *BrowserTool) Description() string { | ||||||||||||
| return `Automate a headless browser via agent-browser CLI. Pass the subcommand as 'command'. | ||||||||||||
|
||||||||||||
| return `Automate a headless browser via agent-browser CLI. Pass the subcommand as 'command'. | |
| return `Automate a browser (headless by default) via the agent-browser CLI. Pass the subcommand as 'command'. |
Copilot
AI
Feb 16, 2026
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
Execute() only validates that the raw command string is non-empty, but buildArgs/splitCommand can still return an empty subcommand (e.g., command set to "" or just quotes). In that case this will invoke agent-browser with only global flags, which is likely to fail with a confusing error. Consider validating that the parsed cmdArgs has at least 1 token and returning a clear ErrorResult if not.
| cmdArgs := t.buildArgs(command) | |
| cmdArgs := t.buildArgs(command) | |
| if len(cmdArgs) == 0 { | |
| return ErrorResult("parsed command is empty; provide an agent-browser subcommand (e.g. 'open https://example.com')") | |
| } |
Copilot
AI
Feb 16, 2026
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
splitCommand currently drops empty quoted arguments. For example, fill @e3 "" will produce no argument for the empty string because the final append is gated on current.Len() > 0. This breaks commands where an empty string is a valid parameter; consider tracking whether an argument was quoted so empty quoted args are preserved, and add a unit test for this case.
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
BrowserToolOptions says Headless has a default of true, but NewBrowserTool currently uses the bool zero-value (false) when opts.Headless isn’t explicitly set, which makes the tool run in headed mode by default (because buildArgs adds --headed when !t.headless). Either implement an explicit default-to-headless behavior (e.g., tri-state/pointer bool) or update the option comment/tests/docs so the default behavior is unambiguous and consistent.