browser-use 0.0.1 → 0.1.0

This diff represents the content of publicly available package versions that have been released to one of the supported registries. The information contained in this diff is provided for informational purposes only and reflects changes between package versions as they appear in their respective public registries.
Files changed (200) hide show
  1. package/LICENSE +21 -0
  2. package/README.md +761 -0
  3. package/dist/agent/cloud-events.d.ts +264 -0
  4. package/dist/agent/cloud-events.js +318 -0
  5. package/dist/agent/gif.d.ts +15 -0
  6. package/dist/agent/gif.js +215 -0
  7. package/dist/agent/index.d.ts +8 -0
  8. package/dist/agent/index.js +8 -0
  9. package/dist/agent/message-manager/service.d.ts +30 -0
  10. package/dist/agent/message-manager/service.js +208 -0
  11. package/dist/agent/message-manager/utils.d.ts +2 -0
  12. package/dist/agent/message-manager/utils.js +41 -0
  13. package/dist/agent/message-manager/views.d.ts +26 -0
  14. package/dist/agent/message-manager/views.js +73 -0
  15. package/dist/agent/prompts.d.ts +52 -0
  16. package/dist/agent/prompts.js +259 -0
  17. package/dist/agent/service.d.ts +290 -0
  18. package/dist/agent/service.js +2200 -0
  19. package/dist/agent/views.d.ts +741 -0
  20. package/dist/agent/views.js +537 -0
  21. package/dist/browser/browser.d.ts +7 -0
  22. package/dist/browser/browser.js +5 -0
  23. package/dist/browser/context.d.ts +8 -0
  24. package/dist/browser/context.js +4 -0
  25. package/dist/browser/dvd-screensaver.d.ts +101 -0
  26. package/dist/browser/dvd-screensaver.js +270 -0
  27. package/dist/browser/extensions.d.ts +63 -0
  28. package/dist/browser/extensions.js +359 -0
  29. package/dist/browser/index.d.ts +10 -0
  30. package/dist/browser/index.js +9 -0
  31. package/dist/browser/playwright-manager.d.ts +47 -0
  32. package/dist/browser/playwright-manager.js +146 -0
  33. package/dist/browser/profile.d.ts +196 -0
  34. package/dist/browser/profile.js +815 -0
  35. package/dist/browser/session.d.ts +505 -0
  36. package/dist/browser/session.js +3409 -0
  37. package/dist/browser/types.d.ts +1184 -0
  38. package/dist/browser/types.js +1 -0
  39. package/dist/browser/utils.d.ts +1 -0
  40. package/dist/browser/utils.js +19 -0
  41. package/dist/browser/views.d.ts +78 -0
  42. package/dist/browser/views.js +72 -0
  43. package/dist/cli.d.ts +2 -0
  44. package/dist/cli.js +44 -0
  45. package/dist/config.d.ts +108 -0
  46. package/dist/config.js +430 -0
  47. package/dist/controller/index.d.ts +3 -0
  48. package/dist/controller/index.js +3 -0
  49. package/dist/controller/registry/index.d.ts +2 -0
  50. package/dist/controller/registry/index.js +2 -0
  51. package/dist/controller/registry/service.d.ts +45 -0
  52. package/dist/controller/registry/service.js +184 -0
  53. package/dist/controller/registry/views.d.ts +55 -0
  54. package/dist/controller/registry/views.js +174 -0
  55. package/dist/controller/service.d.ts +49 -0
  56. package/dist/controller/service.js +1176 -0
  57. package/dist/controller/views.d.ts +241 -0
  58. package/dist/controller/views.js +88 -0
  59. package/dist/dom/clickable-element-processor/service.d.ts +11 -0
  60. package/dist/dom/clickable-element-processor/service.js +60 -0
  61. package/dist/dom/dom_tree/index.js +1400 -0
  62. package/dist/dom/history-tree-processor/service.d.ts +14 -0
  63. package/dist/dom/history-tree-processor/service.js +75 -0
  64. package/dist/dom/history-tree-processor/view.d.ts +54 -0
  65. package/dist/dom/history-tree-processor/view.js +56 -0
  66. package/dist/dom/playground/extraction.d.ts +19 -0
  67. package/dist/dom/playground/extraction.js +187 -0
  68. package/dist/dom/playground/process-dom.d.ts +1 -0
  69. package/dist/dom/playground/process-dom.js +5 -0
  70. package/dist/dom/playground/test-accessibility.d.ts +44 -0
  71. package/dist/dom/playground/test-accessibility.js +111 -0
  72. package/dist/dom/service.d.ts +19 -0
  73. package/dist/dom/service.js +227 -0
  74. package/dist/dom/utils.d.ts +1 -0
  75. package/dist/dom/utils.js +6 -0
  76. package/dist/dom/views.d.ts +61 -0
  77. package/dist/dom/views.js +247 -0
  78. package/dist/event-bus.d.ts +11 -0
  79. package/dist/event-bus.js +19 -0
  80. package/dist/exceptions.d.ts +10 -0
  81. package/dist/exceptions.js +22 -0
  82. package/dist/filesystem/file-system.d.ts +68 -0
  83. package/dist/filesystem/file-system.js +412 -0
  84. package/dist/filesystem/index.d.ts +1 -0
  85. package/dist/filesystem/index.js +1 -0
  86. package/dist/index.d.ts +31 -0
  87. package/dist/index.js +33 -0
  88. package/dist/integrations/gmail/actions.d.ts +12 -0
  89. package/dist/integrations/gmail/actions.js +113 -0
  90. package/dist/integrations/gmail/index.d.ts +2 -0
  91. package/dist/integrations/gmail/index.js +2 -0
  92. package/dist/integrations/gmail/service.d.ts +61 -0
  93. package/dist/integrations/gmail/service.js +260 -0
  94. package/dist/llm/anthropic/chat.d.ts +28 -0
  95. package/dist/llm/anthropic/chat.js +126 -0
  96. package/dist/llm/anthropic/index.d.ts +2 -0
  97. package/dist/llm/anthropic/index.js +2 -0
  98. package/dist/llm/anthropic/serializer.d.ts +68 -0
  99. package/dist/llm/anthropic/serializer.js +285 -0
  100. package/dist/llm/aws/chat-anthropic.d.ts +61 -0
  101. package/dist/llm/aws/chat-anthropic.js +176 -0
  102. package/dist/llm/aws/chat-bedrock.d.ts +15 -0
  103. package/dist/llm/aws/chat-bedrock.js +80 -0
  104. package/dist/llm/aws/index.d.ts +3 -0
  105. package/dist/llm/aws/index.js +3 -0
  106. package/dist/llm/aws/serializer.d.ts +5 -0
  107. package/dist/llm/aws/serializer.js +68 -0
  108. package/dist/llm/azure/chat.d.ts +15 -0
  109. package/dist/llm/azure/chat.js +83 -0
  110. package/dist/llm/azure/index.d.ts +1 -0
  111. package/dist/llm/azure/index.js +1 -0
  112. package/dist/llm/base.d.ts +16 -0
  113. package/dist/llm/base.js +1 -0
  114. package/dist/llm/deepseek/chat.d.ts +15 -0
  115. package/dist/llm/deepseek/chat.js +51 -0
  116. package/dist/llm/deepseek/index.d.ts +2 -0
  117. package/dist/llm/deepseek/index.js +2 -0
  118. package/dist/llm/deepseek/serializer.d.ts +6 -0
  119. package/dist/llm/deepseek/serializer.js +57 -0
  120. package/dist/llm/exceptions.d.ts +10 -0
  121. package/dist/llm/exceptions.js +18 -0
  122. package/dist/llm/google/chat.d.ts +20 -0
  123. package/dist/llm/google/chat.js +144 -0
  124. package/dist/llm/google/index.d.ts +2 -0
  125. package/dist/llm/google/index.js +2 -0
  126. package/dist/llm/google/serializer.d.ts +6 -0
  127. package/dist/llm/google/serializer.js +64 -0
  128. package/dist/llm/groq/chat.d.ts +15 -0
  129. package/dist/llm/groq/chat.js +52 -0
  130. package/dist/llm/groq/index.d.ts +3 -0
  131. package/dist/llm/groq/index.js +3 -0
  132. package/dist/llm/groq/parser.d.ts +32 -0
  133. package/dist/llm/groq/parser.js +189 -0
  134. package/dist/llm/groq/serializer.d.ts +6 -0
  135. package/dist/llm/groq/serializer.js +56 -0
  136. package/dist/llm/messages.d.ts +77 -0
  137. package/dist/llm/messages.js +157 -0
  138. package/dist/llm/ollama/chat.d.ts +15 -0
  139. package/dist/llm/ollama/chat.js +77 -0
  140. package/dist/llm/ollama/index.d.ts +2 -0
  141. package/dist/llm/ollama/index.js +2 -0
  142. package/dist/llm/ollama/serializer.d.ts +6 -0
  143. package/dist/llm/ollama/serializer.js +53 -0
  144. package/dist/llm/openai/chat.d.ts +38 -0
  145. package/dist/llm/openai/chat.js +174 -0
  146. package/dist/llm/openai/index.d.ts +3 -0
  147. package/dist/llm/openai/index.js +3 -0
  148. package/dist/llm/openai/like.d.ts +17 -0
  149. package/dist/llm/openai/like.js +19 -0
  150. package/dist/llm/openai/serializer.d.ts +6 -0
  151. package/dist/llm/openai/serializer.js +57 -0
  152. package/dist/llm/openrouter/chat.d.ts +15 -0
  153. package/dist/llm/openrouter/chat.js +74 -0
  154. package/dist/llm/openrouter/index.d.ts +2 -0
  155. package/dist/llm/openrouter/index.js +2 -0
  156. package/dist/llm/openrouter/serializer.d.ts +3 -0
  157. package/dist/llm/openrouter/serializer.js +3 -0
  158. package/dist/llm/schema.d.ts +6 -0
  159. package/dist/llm/schema.js +77 -0
  160. package/dist/llm/views.d.ts +15 -0
  161. package/dist/llm/views.js +12 -0
  162. package/dist/logging-config.d.ts +25 -0
  163. package/dist/logging-config.js +89 -0
  164. package/dist/mcp/client.d.ts +142 -0
  165. package/dist/mcp/client.js +638 -0
  166. package/dist/mcp/controller.d.ts +6 -0
  167. package/dist/mcp/controller.js +38 -0
  168. package/dist/mcp/index.d.ts +3 -0
  169. package/dist/mcp/index.js +3 -0
  170. package/dist/mcp/server.d.ts +134 -0
  171. package/dist/mcp/server.js +759 -0
  172. package/dist/observability-decorators.d.ts +158 -0
  173. package/dist/observability-decorators.js +286 -0
  174. package/dist/observability.d.ts +23 -0
  175. package/dist/observability.js +58 -0
  176. package/dist/screenshots/index.d.ts +1 -0
  177. package/dist/screenshots/index.js +1 -0
  178. package/dist/screenshots/service.d.ts +6 -0
  179. package/dist/screenshots/service.js +28 -0
  180. package/dist/sync/auth.d.ts +27 -0
  181. package/dist/sync/auth.js +205 -0
  182. package/dist/sync/index.d.ts +2 -0
  183. package/dist/sync/index.js +2 -0
  184. package/dist/sync/service.d.ts +21 -0
  185. package/dist/sync/service.js +146 -0
  186. package/dist/telemetry/index.d.ts +2 -0
  187. package/dist/telemetry/index.js +2 -0
  188. package/dist/telemetry/service.d.ts +12 -0
  189. package/dist/telemetry/service.js +85 -0
  190. package/dist/telemetry/views.d.ts +112 -0
  191. package/dist/telemetry/views.js +112 -0
  192. package/dist/tokens/index.d.ts +2 -0
  193. package/dist/tokens/index.js +2 -0
  194. package/dist/tokens/service.d.ts +35 -0
  195. package/dist/tokens/service.js +423 -0
  196. package/dist/tokens/views.d.ts +58 -0
  197. package/dist/tokens/views.js +1 -0
  198. package/dist/utils.d.ts +128 -0
  199. package/dist/utils.js +529 -0
  200. package/package.json +94 -5
package/README.md ADDED
@@ -0,0 +1,761 @@
1
+ # browser-use
2
+
3
+ ![Node CI](https://github.com/webllm/browser-use/workflows/Node%20CI/badge.svg)
4
+ [![npm](https://img.shields.io/npm/v/browser-use.svg)](https://www.npmjs.com/package/browser-use)
5
+ ![license](https://img.shields.io/npm/l/browser-use)
6
+
7
+ > 🙏 **A TypeScript port of the amazing [browser-use](https://github.com/browser-use/browser-use) Python library**
8
+ >
9
+ > This project is a faithful TypeScript/JavaScript implementation of the original [browser-use](https://github.com/browser-use/browser-use) Python library, bringing the power of AI-driven browser automation to the Node.js ecosystem. All credit for the innovative design and architecture goes to the original Python project and its creators.
10
+
11
+ A TypeScript-first library for programmatic browser control, designed for building AI-powered web agents with vision capabilities and extensive LLM integrations.
12
+
13
+ ## Why TypeScript?
14
+
15
+ While the original [browser-use Python library](https://github.com/browser-use/browser-use) is excellent and feature-complete, this TypeScript port aims to:
16
+
17
+ - 🌍 Bring browser-use capabilities to the JavaScript/TypeScript ecosystem
18
+ - 🔧 Enable seamless integration with Node.js, Deno, and Bun projects
19
+ - 📦 Provide native TypeScript type definitions for better DX
20
+ - 🤝 Make browser automation accessible to frontend and full-stack developers
21
+
22
+ ### Python vs TypeScript: Which Should You Use?
23
+
24
+ | Feature | Python Version | TypeScript Version |
25
+ | ------------------- | --------------------------------------------------------------------- | ----------------------------------------------------------- |
26
+ | **Recommended for** | Python developers, Data scientists, AI/ML engineers | JavaScript/TypeScript developers, Full-stack engineers |
27
+ | **Ecosystem** | PyPI, pip | npm, yarn, pnpm |
28
+ | **Type Safety** | Optional (with type hints) | Built-in (TypeScript) |
29
+ | **Runtime** | Python 3.x | Node.js, Deno, Bun |
30
+ | **LLM Providers** | 10+ providers | 10+ providers (same) |
31
+ | **Browser Support** | Playwright | Playwright (same) |
32
+ | **Documentation** | ⭐ Original & Complete | Port with TS-specific examples |
33
+ | **Community** | ⭐ Larger & More Established | Growing |
34
+ | **GitHub** | [browser-use/browser-use](https://github.com/browser-use/browser-use) | [webllm/browser-use](https://github.com/webllm/browser-use) |
35
+
36
+ **👉 If you're working in Python, we highly recommend using the [original browser-use library](https://github.com/browser-use/browser-use).** This TypeScript port is specifically for those who need to work within the JavaScript/TypeScript ecosystem.
37
+
38
+ ### Commitment to the Original
39
+
40
+ We are committed to:
41
+
42
+ - ✅ Maintaining feature parity with the Python version whenever possible
43
+ - 🔄 Keeping up with upstream updates and improvements
44
+ - 🐛 Reporting bugs found in this port back to the original project when applicable
45
+ - 📚 Directing users to the original project's documentation for core concepts
46
+ - 🤝 Collaborating with the original authors and respecting their vision
47
+
48
+ This is **not** a fork or competing project—it's a respectful port to serve a different programming language community.
49
+
50
+ ## Features
51
+
52
+ - 🤖 **AI-Powered**: Built specifically for LLM-driven web automation with structured output support
53
+ - 🎯 **Type-Safe**: Full TypeScript support with comprehensive type definitions
54
+ - 🌐 **Multi-Browser**: Support for Chromium, Firefox, and WebKit via Playwright
55
+ - 🔌 **10+ LLM Providers**: OpenAI, Anthropic, Google, AWS, Azure, DeepSeek, Groq, Ollama, OpenRouter, and more
56
+ - 👁️ **Vision Support**: Multimodal capabilities with screenshot analysis
57
+ - 🛡️ **Robust**: Built-in error handling, recovery, graceful shutdown, and retry mechanisms
58
+ - 📊 **Observable**: Comprehensive logging, execution history, and telemetry
59
+ - 🔧 **Extensible**: Custom actions, MCP protocol, and plugin system
60
+ - 📁 **FileSystem**: Built-in file operations with PDF parsing
61
+ - 🔗 **Integrations**: Gmail API, Google Sheets, and MCP servers
62
+
63
+ ## Quick Start
64
+
65
+ ### Installation
66
+
67
+ ```bash
68
+ npm install browser-use
69
+ # or
70
+ yarn add browser-use
71
+ # or
72
+ pnpm add browser-use
73
+ ```
74
+
75
+ Playwright browsers will be installed automatically via postinstall hook.
76
+
77
+ ### Basic Usage with Agent
78
+
79
+ ```typescript
80
+ import { Agent } from 'browser-use';
81
+ import { ChatOpenAI } from 'browser-use/llm/openai';
82
+
83
+ async function main() {
84
+ const llm = new ChatOpenAI({
85
+ model: 'gpt-4',
86
+ apiKey: process.env.OPENAI_API_KEY,
87
+ });
88
+
89
+ const agent = new Agent({
90
+ task: 'Go to google.com and search for "TypeScript browser automation"',
91
+ llm,
92
+ });
93
+
94
+ const history = await agent.run();
95
+
96
+ console.log(`Task completed in ${history.history.length} steps`);
97
+
98
+ // Access the browser session
99
+ const browserSession = agent.browser_session;
100
+ const currentPage = await browserSession.get_current_page();
101
+ console.log('Final URL:', currentPage?.url());
102
+ }
103
+
104
+ main();
105
+ ```
106
+
107
+ ### Using Controller for Custom Actions
108
+
109
+ Use `Controller` to register domain-specific actions, then pass it into `Agent`:
110
+
111
+ ```typescript
112
+ import { Agent, Controller, ActionResult } from 'browser-use';
113
+ import { ChatOpenAI } from 'browser-use/llm/openai';
114
+ import { z } from 'zod';
115
+
116
+ const controller = new Controller();
117
+
118
+ controller.registry.action('Extract product info from the current page', {
119
+ param_model: z.object({
120
+ include_price: z.boolean().default(true),
121
+ include_reviews: z.boolean().default(false),
122
+ }),
123
+ })(async function extract_product_info(params, { page }) {
124
+ const productData = await page.evaluate(() => ({
125
+ title: document.querySelector('h1')?.textContent ?? null,
126
+ price: document.querySelector('.price')?.textContent ?? null,
127
+ }));
128
+
129
+ return new ActionResult({
130
+ extracted_content: JSON.stringify({ ...productData, ...params }),
131
+ include_in_memory: true,
132
+ });
133
+ });
134
+
135
+ const agent = new Agent({
136
+ task: 'Open product page and extract product info',
137
+ llm: new ChatOpenAI({
138
+ model: 'gpt-4o',
139
+ apiKey: process.env.OPENAI_API_KEY,
140
+ }),
141
+ controller,
142
+ });
143
+
144
+ const history = await agent.run(10);
145
+ console.log(history.final_result());
146
+ ```
147
+
148
+ ## Advanced Usage
149
+
150
+ ### Vision/Multimodal Support
151
+
152
+ Enable vision capabilities to let the AI analyze screenshots:
153
+
154
+ ```typescript
155
+ import { Agent } from 'browser-use';
156
+ import { ChatGoogle } from 'browser-use/llm/google';
157
+
158
+ const llm = new ChatGoogle('gemini-2.5-flash');
159
+
160
+ const agent = new Agent({
161
+ task: 'Describe what you see on this page and identify main visual elements',
162
+ llm,
163
+ use_vision: true,
164
+ vision_detail_level: 'high', // 'auto' | 'low' | 'high'
165
+ });
166
+
167
+ const history = await agent.run(5);
168
+ ```
169
+
170
+ ### Custom Actions with Controller Registry
171
+
172
+ Extend the agent's capabilities with custom actions:
173
+
174
+ ```typescript
175
+ import { Controller, ActionResult } from 'browser-use';
176
+ import { z } from 'zod';
177
+
178
+ const controller = new Controller();
179
+
180
+ controller.registry.action('Extract product information', {
181
+ param_model: z.object({
182
+ include_price: z.boolean().default(true),
183
+ include_reviews: z.boolean().default(false),
184
+ }),
185
+ })(async function extract_product_info(params, { page }) {
186
+ const productData = await page.evaluate(() => ({
187
+ title: document.querySelector('h1')?.textContent ?? null,
188
+ price: document.querySelector('.price')?.textContent ?? null,
189
+ }));
190
+
191
+ return new ActionResult({
192
+ extracted_content: JSON.stringify({ ...productData, ...params }),
193
+ include_in_memory: true,
194
+ });
195
+ });
196
+ ```
197
+
198
+ ### FileSystem Operations
199
+
200
+ Built-in file system support with PDF parsing:
201
+
202
+ ```typescript
203
+ import { Agent } from 'browser-use';
204
+ import { ChatOpenAI } from 'browser-use/llm/openai';
205
+
206
+ const agent = new Agent({
207
+ task: 'Download the PDF and extract text from page 1',
208
+ llm: new ChatOpenAI(),
209
+ file_system_path: './agent-workspace',
210
+ });
211
+
212
+ // FileSystem actions are available:
213
+ // - read_file: Read file contents (supports PDF)
214
+ // - write_file: Write content to file
215
+ // - replace_file_str: Replace text in file
216
+ ```
217
+
218
+ ### Browser Profile Configuration
219
+
220
+ Customize browser behavior with profiles:
221
+
222
+ ```typescript
223
+ import { BrowserProfile, BrowserSession } from 'browser-use';
224
+
225
+ const profile = new BrowserProfile({
226
+ window_size: { width: 1920, height: 1080 },
227
+ disable_security: false,
228
+ headless: true,
229
+ chromium_sandbox: true, // Keep enabled by default in production
230
+ args: ['--disable-blink-features=AutomationControlled'],
231
+ wait_for_network_idle_page_load_time: 3, // seconds
232
+ allowed_domains: ['example.com', '*.google.com'],
233
+ cookies_file: './cookies.json',
234
+ downloads_path: './downloads',
235
+ highlight_elements: false, // Visual debugging
236
+ viewport_expansion: 0, // Expand viewport for element detection
237
+ });
238
+
239
+ const browserSession = new BrowserSession({
240
+ browser_profile: profile,
241
+ });
242
+
243
+ await browserSession.start();
244
+ ```
245
+
246
+ If Chromium launch fails with `No usable sandbox` (common in restricted Linux CI),
247
+ `BrowserSession` automatically retries once with `chromium_sandbox: false` and logs
248
+ a warning. For deterministic CI behavior, set `chromium_sandbox: false` explicitly.
249
+
250
+ ### MCP (Model Context Protocol) Integration
251
+
252
+ Connect to MCP servers for extended capabilities:
253
+
254
+ ```typescript
255
+ import { MCPController } from 'browser-use';
256
+
257
+ const mcpController = new MCPController();
258
+
259
+ // Add MCP server
260
+ await mcpController.addServer('my-server', 'npx', [
261
+ '-y',
262
+ '@modelcontextprotocol/server-filesystem',
263
+ '/path/to/data',
264
+ ]);
265
+
266
+ // MCP tools are automatically available to the agent
267
+ const tools = await mcpController.listAllTools();
268
+ console.log('Available MCP tools:', tools);
269
+ ```
270
+
271
+ ### Gmail Integration
272
+
273
+ Built-in Gmail API support:
274
+
275
+ ```typescript
276
+ import { GmailService } from 'browser-use';
277
+
278
+ // Gmail actions are automatically available:
279
+ // - get_recent_emails: Fetch recent emails
280
+ // - send_email: Send email via Gmail API
281
+
282
+ const agent = new Agent({
283
+ task: 'Check my last 5 emails and summarize them',
284
+ llm: new ChatOpenAI(),
285
+ // Gmail credentials loaded from config files (or explicit GmailService options)
286
+ });
287
+ ```
288
+
289
+ ## Configuration
290
+
291
+ ### Environment Variables
292
+
293
+ ```bash
294
+ # LLM Configuration (provider-specific)
295
+ OPENAI_API_KEY=your-openai-key
296
+ ANTHROPIC_API_KEY=your-anthropic-key
297
+ GOOGLE_API_KEY=your-google-key
298
+ AWS_ACCESS_KEY_ID=your-aws-key
299
+ AWS_SECRET_ACCESS_KEY=your-aws-secret
300
+ AZURE_OPENAI_API_KEY=your-azure-key
301
+ AZURE_OPENAI_ENDPOINT=your-azure-endpoint
302
+ GROQ_API_KEY=your-groq-key
303
+ DEEPSEEK_API_KEY=your-deepseek-key
304
+
305
+ # Browser Configuration
306
+ BROWSER_USE_HEADLESS=true
307
+ BROWSER_USE_ALLOWED_DOMAINS=example.com,*.trusted.org
308
+ IN_DOCKER=true
309
+
310
+ # Logging Configuration
311
+ BROWSER_USE_LOGGING_LEVEL=info # debug, info, warning, error
312
+
313
+ # Telemetry (optional)
314
+ ANONYMIZED_TELEMETRY=false
315
+
316
+ # Observability (optional)
317
+ LMNR_API_KEY=your-lmnr-key
318
+ ```
319
+
320
+ ### Agent Configuration
321
+
322
+ ```typescript
323
+ interface AgentOptions {
324
+ // Vision/multimodal
325
+ use_vision?: boolean;
326
+ vision_detail_level?: 'low' | 'high' | 'auto';
327
+
328
+ // Error handling
329
+ max_failures?: number; // default: 3
330
+ retry_delay?: number; // seconds, default: 10
331
+ max_actions_per_step?: number; // default: 10
332
+
333
+ // Persistence / output
334
+ save_conversation_path?: string | null;
335
+ file_system_path?: string | null;
336
+ validate_output?: boolean;
337
+ include_attributes?: string[];
338
+
339
+ // Runtime limits (seconds)
340
+ llm_timeout?: number; // default: 60
341
+ step_timeout?: number; // default: 180
342
+ }
343
+
344
+ // Max step count is configured per run call:
345
+ await agent.run(100);
346
+ ```
347
+
348
+ ## Supported LLM Providers
349
+
350
+ ### OpenAI
351
+
352
+ ```typescript
353
+ import { ChatOpenAI } from 'browser-use/llm/openai';
354
+
355
+ const llm = new ChatOpenAI({
356
+ model: 'gpt-4o', // or 'gpt-4', 'gpt-3.5-turbo'
357
+ apiKey: process.env.OPENAI_API_KEY,
358
+ temperature: 0.1,
359
+ maxTokens: 4096,
360
+ });
361
+ ```
362
+
363
+ ### Anthropic Claude
364
+
365
+ ```typescript
366
+ import { ChatAnthropic } from 'browser-use/llm/anthropic';
367
+
368
+ const llm = new ChatAnthropic({
369
+ model: 'claude-3-5-sonnet-20241022', // or other Claude models
370
+ apiKey: process.env.ANTHROPIC_API_KEY,
371
+ temperature: 0.1,
372
+ });
373
+ ```
374
+
375
+ ### Google Gemini
376
+
377
+ ```typescript
378
+ import { ChatGoogle } from 'browser-use/llm/google';
379
+
380
+ const llm = new ChatGoogle('gemini-2.5-flash');
381
+ // Configure GOOGLE_API_KEY in env. Optional:
382
+ // GOOGLE_API_BASE_URL / GOOGLE_API_VERSION
383
+ ```
384
+
385
+ ### AWS Bedrock
386
+
387
+ ```typescript
388
+ import { ChatAnthropicBedrock } from 'browser-use/llm/aws';
389
+
390
+ const llm = new ChatAnthropicBedrock({
391
+ model: 'anthropic.claude-3-5-sonnet-20241022-v2:0',
392
+ region: 'us-east-1',
393
+ max_tokens: 4096,
394
+ });
395
+ ```
396
+
397
+ ### Azure OpenAI
398
+
399
+ ```typescript
400
+ import { ChatAzure } from 'browser-use/llm/azure';
401
+
402
+ const llm = new ChatAzure('gpt-4o');
403
+ // Configure AZURE_OPENAI_API_KEY, AZURE_OPENAI_ENDPOINT, AZURE_OPENAI_API_VERSION in env.
404
+ ```
405
+
406
+ ### DeepSeek
407
+
408
+ ```typescript
409
+ import { ChatDeepSeek } from 'browser-use/llm/deepseek';
410
+
411
+ const llm = new ChatDeepSeek('deepseek-chat');
412
+ ```
413
+
414
+ ### Groq
415
+
416
+ ```typescript
417
+ import { ChatGroq } from 'browser-use/llm/groq';
418
+
419
+ const llm = new ChatGroq('mixtral-8x7b-32768');
420
+ ```
421
+
422
+ ### Ollama (Local)
423
+
424
+ ```typescript
425
+ import { ChatOllama } from 'browser-use/llm/ollama';
426
+
427
+ const llm = new ChatOllama('llama3.1', 'http://localhost:11434');
428
+ ```
429
+
430
+ ### OpenRouter
431
+
432
+ ```typescript
433
+ import { ChatOpenRouter } from 'browser-use/llm/openrouter';
434
+
435
+ const llm = new ChatOpenRouter('anthropic/claude-3-opus');
436
+ ```
437
+
438
+ ## Available Actions
439
+
440
+ The AI agent can perform these actions:
441
+
442
+ ### Navigation
443
+
444
+ - **search_google** - Search query in Google (web results only)
445
+ - **go_to_url** - Navigate to a specific URL (with optional new tab)
446
+
447
+ ### Element Interaction
448
+
449
+ - **click_element** - Click buttons, links, or clickable elements by index
450
+ - **input_text** - Type text into input fields and textareas by index
451
+
452
+ ### Dropdown/Select
453
+
454
+ - **dropdown_options** - Get available options from a dropdown
455
+ - **select_dropdown** - Select option from dropdown by index
456
+
457
+ ### Scrolling
458
+
459
+ - **scroll** - Scroll page up/down by pixels or direction
460
+ - **scroll_to_text** - Scroll to text content on page
461
+
462
+ ### Tabs
463
+
464
+ - **switch_tab** - Switch to different browser tab by index
465
+ - **close_tab** - Close current or specific tab
466
+
467
+ ### Keyboard
468
+
469
+ - **send_keys** - Send keyboard input (Enter, Tab, Escape, etc.)
470
+
471
+ ### Content Extraction
472
+
473
+ - **extract_structured_data** - Extract specific data using LLM from page markdown
474
+
475
+ ### FileSystem
476
+
477
+ - **read_file** - Read file contents (supports PDF parsing)
478
+ - **write_file** - Write content to file
479
+ - **replace_file_str** - Replace string in file
480
+
481
+ ### Google Sheets
482
+
483
+ - **sheets_range** - Get cell range from Google Sheet
484
+ - **sheets_update** - Update Google Sheet cells
485
+ - **sheets_input** - Input data into Google Sheet
486
+
487
+ ### Gmail
488
+
489
+ - **get_recent_emails** - Fetch recent emails from Gmail
490
+ - **send_email** - Send email via Gmail API
491
+
492
+ ### Completion
493
+
494
+ - **done** - Mark task as completed with optional structured output
495
+
496
+ ## Examples
497
+
498
+ See the `/examples` directory for detailed examples:
499
+
500
+ - `examples/simple-search.ts` - Basic web search automation
501
+ - `examples/search-wikipedia.ts` - Wikipedia navigation with vision
502
+ - `examples/test-vision.ts` - Vision/multimodal capabilities demo
503
+ - `examples/test-filesystem.ts` - File operations and PDF parsing
504
+ - `examples/openapi.ts` - Complex API documentation extraction
505
+
506
+ ### Running Examples
507
+
508
+ ```bash
509
+ # Set your API key
510
+ export OPENAI_API_KEY=your-key
511
+ # or for Google
512
+ export GOOGLE_API_KEY=your-key
513
+
514
+ # Run an example
515
+ npx tsx examples/simple-search.ts
516
+ ```
517
+
518
+ ## Error Handling
519
+
520
+ The library includes comprehensive error handling:
521
+
522
+ ```typescript
523
+ import { Agent, AgentError } from 'browser-use';
524
+
525
+ try {
526
+ const agent = new Agent({ task: 'Your task', llm });
527
+ const history = await agent.run(10); // max 10 steps
528
+
529
+ // Check completion status
530
+ const lastStep = history.history[history.history.length - 1];
531
+ if (lastStep?.result.is_done) {
532
+ console.log('Task completed:', lastStep.result.extracted_content);
533
+ } else {
534
+ console.log('Task incomplete after max steps');
535
+ }
536
+ } catch (error) {
537
+ if (error instanceof AgentError) {
538
+ console.error('Agent error:', error.message);
539
+ console.error('Failed at step:', error.step);
540
+ } else {
541
+ console.error('Unexpected error:', error);
542
+ }
543
+ }
544
+ ```
545
+
546
+ ## Development
547
+
548
+ ### Building from Source
549
+
550
+ ```bash
551
+ git clone https://github.com/webllm/browser-use.git
552
+ cd browser-use
553
+ yarn install # Automatically installs Playwright browsers
554
+ yarn build
555
+ ```
556
+
557
+ ### Running Tests
558
+
559
+ ```bash
560
+ # Run all tests
561
+ yarn test
562
+
563
+ # Run specific test
564
+ yarn test test/integration-advanced.test.ts
565
+
566
+ # Watch mode
567
+ yarn test:watch
568
+ ```
569
+
570
+ ### Code Quality
571
+
572
+ ```bash
573
+ # Lint
574
+ yarn lint
575
+
576
+ # Format
577
+ yarn prettier
578
+
579
+ # Type check
580
+ yarn build
581
+ ```
582
+
583
+ ## Architecture
584
+
585
+ The library follows a modular, layered architecture:
586
+
587
+ ```
588
+ ┌─────────────────────────────────────────┐
589
+ │ Agent (Orchestrator) │
590
+ │ - Task execution & planning │
591
+ │ - LLM message management │
592
+ │ - Step execution loop │
593
+ └─────────┬───────────────────────────────┘
594
+
595
+ ┌─────────▼───────────────────────────────┐
596
+ │ Controller (Actions) │
597
+ │ - Action registry & execution │
598
+ │ - Built-in actions (30+) │
599
+ │ - Custom action support │
600
+ └─────────┬───────────────────────────────┘
601
+
602
+ ┌─────────▼───────────────────────────────┐
603
+ │ BrowserSession (Browser) │
604
+ │ - Playwright integration │
605
+ │ - Tab & page management │
606
+ │ - Navigation & interaction │
607
+ └─────────┬───────────────────────────────┘
608
+
609
+ ┌─────────▼───────────────────────────────┐
610
+ │ DOMService (DOM Analysis) │
611
+ │ - Element extraction │
612
+ │ - Clickable element detection │
613
+ │ - History tree processing │
614
+ └──────────────────────────────────────────┘
615
+
616
+ Supporting Services:
617
+ ┌──────────────────────────────────────────┐
618
+ │ - LLM Clients (10+ providers) │
619
+ │ - FileSystem (with PDF support) │
620
+ │ - Screenshot Service │
621
+ │ - Token Tracking & Cost Calculation │
622
+ │ - Telemetry (PostHog) │
623
+ │ - Observability (LMNR) │
624
+ │ - MCP Protocol Support │
625
+ │ - Gmail/Sheets Integration │
626
+ └──────────────────────────────────────────┘
627
+ ```
628
+
629
+ ### Key Components
630
+
631
+ - **Agent**: High-level orchestrator managing task execution, LLM communication, and step-by-step planning
632
+ - **Controller**: Action registry and executor with 30+ built-in actions and custom action support
633
+ - **BrowserSession**: Browser lifecycle manager built on Playwright with tab management and state tracking
634
+ - **DOMService**: Intelligent DOM analyzer extracting relevant elements for AI consumption
635
+ - **MessageManager**: Manages conversation history with token optimization and context window management
636
+ - **FileSystem**: File operations with PDF parsing and workspace management
637
+ - **ScreenshotService**: Captures and manages screenshots for vision capabilities
638
+ - **Registry**: Type-safe action registration system with Zod schema validation
639
+
640
+ ## Token Usage & Cost Tracking
641
+
642
+ The library automatically tracks token usage and calculates costs:
643
+
644
+ ```typescript
645
+ import { TokenCost } from 'browser-use';
646
+
647
+ const agent = new Agent({ task: 'Your task', llm });
648
+ const history = await agent.run();
649
+
650
+ // Get token statistics
651
+ const stats = history.stats();
652
+ console.log(
653
+ 'Total tokens:',
654
+ stats.total_input_tokens + stats.total_output_tokens
655
+ );
656
+ console.log('Steps:', stats.n_steps);
657
+
658
+ // Calculate cost (if pricing data available)
659
+ const cost = TokenCost.calculate(history);
660
+ console.log('Estimated cost: $', cost.toFixed(4));
661
+ ```
662
+
663
+ ## Screenshot & History Export
664
+
665
+ Generate GIF animations from agent execution history:
666
+
667
+ ```typescript
668
+ import { create_history_gif } from 'browser-use';
669
+
670
+ const history = await agent.run();
671
+
672
+ await create_history_gif('My automation task', history, {
673
+ output_path: 'agent-history.gif',
674
+ duration: 3000, // ms per frame
675
+ show_goals: true,
676
+ show_task: true,
677
+ show_logo: false,
678
+ });
679
+
680
+ console.log('Created agent-history.gif');
681
+ ```
682
+
683
+ ## Observability
684
+
685
+ Built-in observability with LMNR (Laminar) and custom debugging:
686
+
687
+ ```typescript
688
+ import { observe, observe_debug } from 'browser-use';
689
+
690
+ // Automatic tracing (if LMNR_API_KEY set)
691
+ // All agent operations are automatically traced
692
+
693
+ // Custom debug observations
694
+ @observe_debug({ name: 'my_custom_operation' })
695
+ async function myFunction() {
696
+ // Function execution is logged and timed
697
+ }
698
+ ```
699
+
700
+ ## Contributing
701
+
702
+ Contributions are welcome! Please feel free to submit a Pull Request.
703
+
704
+ 1. Fork the repository
705
+ 2. Create your feature branch (`git checkout -b feature/amazing-feature`)
706
+ 3. Commit your changes (`git commit -m 'feat: add amazing feature'`)
707
+ 4. Push to the branch (`git push origin feature/amazing-feature`)
708
+ 5. Open a Pull Request
709
+
710
+ ## Support
711
+
712
+ - 📚 [Documentation](https://github.com/webllm/browser-use)
713
+ - 🐛 [Issue Tracker](https://github.com/webllm/browser-use/issues)
714
+ - 💬 [Discussions](https://github.com/webllm/browser-use/discussions)
715
+
716
+ ## Acknowledgments
717
+
718
+ ### Original Project
719
+
720
+ This TypeScript implementation would not exist without the groundbreaking work of the original **[browser-use](https://github.com/browser-use/browser-use)** Python library:
721
+
722
+ - 🎯 **Original Project**: [browser-use/browser-use](https://github.com/browser-use/browser-use) (Python)
723
+ - 👏 **Created by**: The browser-use team and contributors
724
+ - 💡 **Inspiration**: All architectural decisions, agent design patterns, and innovative approaches come from the original Python implementation
725
+
726
+ We are deeply grateful to the original authors for creating such an elegant and powerful solution for AI-driven browser automation. This TypeScript port aims to faithfully replicate their excellent work for the JavaScript/TypeScript community.
727
+
728
+ ### Key Differences from Python Version
729
+
730
+ While we strive to maintain feature parity with the Python version, there are some differences due to platform constraints:
731
+
732
+ - **Runtime**: Node.js/Deno/Bun instead of Python
733
+ - **Type System**: TypeScript's structural typing vs Python's duck typing
734
+ - **Async Model**: JavaScript Promises vs Python async/await (similar but different)
735
+ - **Ecosystem**: npm packages vs PyPI packages
736
+
737
+ ### Technology Stack
738
+
739
+ This project is built with:
740
+
741
+ - [Playwright](https://playwright.dev/) - Browser automation framework
742
+ - [Zod](https://zod.dev/) - TypeScript-first schema validation
743
+ - [OpenAI](https://openai.com/), [Anthropic](https://anthropic.com/), [Google](https://ai.google.dev/) - LLM providers
744
+ - And many other excellent open-source libraries
745
+
746
+ ### Community
747
+
748
+ - 🌟 **Star the original Python project**: [browser-use/browser-use](https://github.com/browser-use/browser-use)
749
+ - 🌟 **Star this TypeScript port**: [webllm/browser-use](https://github.com/webllm/browser-use)
750
+ - 💬 **Join the community**: Share your use cases and contribute to both projects!
751
+
752
+ ## Related Projects
753
+
754
+ - 🐍 [browser-use (Python)](https://github.com/browser-use/browser-use) - The original and official implementation
755
+ - 🎭 [Playwright](https://playwright.dev/) - The browser automation foundation
756
+ - 🤖 [LangChain](https://www.langchain.com/) - LLM application framework
757
+ - 🦜 [Laminar](https://laminar.run/) - LLM observability platform
758
+
759
+ ## License
760
+
761
+ MIT License - see [LICENSE](LICENSE) for details.