doubao-browser-agent
v1.5.0
Published
NPM package for interacting with Doubao web version via Playwright
Maintainers
Readme
doubao-browser-agent
NPM package for interacting with Doubao (豆包) web version via Playwright.
Features
- Automated browser interaction with Doubao web version
- Automatic Chrome profile management for login persistence
- Retry mechanism for network failures
- CLI and Node.js API support
- TypeScript support with full type definitions
Prerequisites
- Chrome browser installed on your system
- Logged into Doubao (https://www.doubao.com/chat/) in your Chrome browser at least once
The package uses your Chrome profile to maintain login state, so you need to login manually first.
Installation
npm install doubao-browser-agentNode.js API Usage
import { DoubaoAgent } from 'doubao-browser-agent';
// Create agent instance
const agent = new DoubaoAgent({
timeout: 120000, // Timeout in milliseconds (default: 120000)
retryCount: 3, // Retry count (default: 3)
});
// Send a question and get answer
try {
const answer = await agent.ask('What is TypeScript?');
console.log('Answer:', answer);
} catch (error) {
console.error('Error:', error.message);
}
// Check login status
const status = agent.status();
console.log('Logged in:', status.loggedIn);
console.log('Profile path:', status.profilePath);
// Clear saved profile (if needed)
await agent.reset();CLI Usage
# Send a question
doubao-agent ask "What is TypeScript?"
# With options
doubao-agent ask "Explain Promise" --timeout 60000 --retry 5
# Check login status
doubao-agent status
# Clear saved profile
doubao-agent reset
# Show help
doubao-agent --helpAPI Documentation
DoubaoAgent
Main class for interacting with Doubao.
Constructor
new DoubaoAgent(options?: DoubaoAgentOptions)Options:
timeout?: number- Timeout in milliseconds (default: 120000)retryCount?: number- Number of retry attempts (default: 3)profileDir?: string- Custom directory for storing Chrome profile copychromePath?: string- Custom Chrome executable path
Methods
ask(question: string): Promise<string>
Send a question to Doubao and return the answer.
status(): { loggedIn: boolean; profilePath: string }
Check the login status (whether profile exists).
reset(): Promise<void>
Clear the saved profile copy.
Error Types
The package throws DoubaoAgentError with the following error types:
| Type | Description |
|------|-------------|
| BROWSER_LAUNCH | Failed to launch Chrome browser |
| PROFILE_COPY | Failed to copy Chrome profile |
| TIMEOUT | Timeout while waiting for response |
| NETWORK | Network or connection error |
import { DoubaoAgentError } from 'doubao-browser-agent';
try {
const answer = await agent.ask('Hello');
} catch (error) {
if (error instanceof DoubaoAgentError) {
console.log('Error type:', error.type);
console.log('Error message:', error.message);
}
}How It Works
- On first run, the package copies your Chrome profile to a temporary directory
- Launches Chrome in headless mode with the copied profile
- Navigates to Doubao chat page
- Sends your question and waits for response
- Extracts the response and closes the browser
Supported Platforms
- Windows (Chrome paths:
C:/Program Files/Google/Chrome/Application/chrome.exe) - macOS (Chrome paths:
/Applications/Google Chrome.app/Contents/MacOS/Google Chrome) - Linux (Chrome paths:
/usr/bin/google-chrome,/usr/bin/chrome)
License
MIT
