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
@@ -0,0 +1,55 @@
1
+ import { type ZodTypeAny } from 'zod';
2
+ import type { Page } from '../../browser/types.js';
3
+ export type ActionHandler = (...args: any[]) => Promise<unknown> | unknown;
4
+ type BrowserSession = unknown;
5
+ type BaseChatModel = unknown;
6
+ type FileSystem = unknown;
7
+ export declare class RegisteredAction {
8
+ readonly name: string;
9
+ readonly description: string;
10
+ readonly handler: ActionHandler;
11
+ readonly paramSchema: ZodTypeAny;
12
+ readonly domains: string[] | null;
13
+ readonly pageFilter: ((page: Page) => boolean) | null;
14
+ constructor(name: string, description: string, handler: ActionHandler, paramSchema: ZodTypeAny, domains?: string[] | null, pageFilter?: ((page: Page) => boolean) | null);
15
+ promptDescription(): string;
16
+ }
17
+ export declare class ActionModel {
18
+ constructor(initialData?: Record<string, any>);
19
+ private data;
20
+ toJSON(): Record<string, any>;
21
+ model_dump(options?: {
22
+ exclude_none?: boolean;
23
+ }): any;
24
+ model_dump_json(options?: {
25
+ exclude_none?: boolean;
26
+ }): string;
27
+ get_index(): number | null;
28
+ set_index(index: number): void;
29
+ }
30
+ export declare class ActionRegistry {
31
+ private actions;
32
+ register(action: RegisteredAction): void;
33
+ get(name: string): RegisteredAction | null;
34
+ getAll(): RegisteredAction[];
35
+ get actionsMap(): Map<string, RegisteredAction>;
36
+ get actionEntries(): RegisteredAction[];
37
+ private _matchDomains;
38
+ private _matchPageFilter;
39
+ getAvailableActions(page?: Page | null, includeActions?: string[] | null): RegisteredAction[];
40
+ get_prompt_description(page?: Page | null): string;
41
+ }
42
+ export declare class SpecialActionParameters {
43
+ context: any | null;
44
+ browser_session: BrowserSession | null;
45
+ browser: BrowserSession | null;
46
+ browser_context: BrowserSession | null;
47
+ page: Page | null;
48
+ page_extraction_llm: BaseChatModel | null;
49
+ file_system: FileSystem | null;
50
+ available_file_paths: string[] | null;
51
+ signal: AbortSignal | null;
52
+ has_sensitive_data: boolean;
53
+ static get_browser_requiring_params(): Set<string>;
54
+ }
55
+ export {};
@@ -0,0 +1,174 @@
1
+ import { z } from 'zod';
2
+ import { match_url_with_domain_pattern } from '../../utils.js';
3
+ const getPageUrl = (page) => {
4
+ if (!page) {
5
+ return '';
6
+ }
7
+ const candidate = page.url;
8
+ if (typeof candidate === 'function') {
9
+ try {
10
+ return candidate.call(page);
11
+ }
12
+ catch {
13
+ return '';
14
+ }
15
+ }
16
+ return candidate ?? '';
17
+ };
18
+ export class RegisteredAction {
19
+ name;
20
+ description;
21
+ handler;
22
+ paramSchema;
23
+ domains;
24
+ pageFilter;
25
+ constructor(name, description, handler, paramSchema, domains = null, pageFilter = null) {
26
+ this.name = name;
27
+ this.description = description;
28
+ this.handler = handler;
29
+ this.paramSchema = paramSchema;
30
+ this.domains = domains;
31
+ this.pageFilter = pageFilter;
32
+ }
33
+ promptDescription() {
34
+ const skipKeys = new Set(['title']);
35
+ let description = `${this.description}: \n`;
36
+ description += `{${this.name}: `;
37
+ const schemaShape = (this.paramSchema instanceof z.ZodObject && this.paramSchema.shape) ||
38
+ ('shape' in this.paramSchema ? this.paramSchema.shape : null);
39
+ if (schemaShape) {
40
+ const props = Object.fromEntries(Object.entries(schemaShape).map(([key, value]) => {
41
+ const entries = value instanceof z.ZodType ? value._def : value;
42
+ const cleanEntries = Object.fromEntries(Object.entries(entries).filter(([propKey]) => !skipKeys.has(propKey)));
43
+ return [key, cleanEntries];
44
+ }));
45
+ description += JSON.stringify(props);
46
+ }
47
+ else {
48
+ description += '{}';
49
+ }
50
+ description += '}';
51
+ return description;
52
+ }
53
+ }
54
+ export class ActionModel {
55
+ constructor(initialData = {}) {
56
+ this.data = initialData;
57
+ }
58
+ data;
59
+ toJSON() {
60
+ return this.data;
61
+ }
62
+ model_dump(options) {
63
+ const clone = JSON.parse(JSON.stringify(this.data));
64
+ if (options?.exclude_none) {
65
+ for (const [key, value] of Object.entries(clone)) {
66
+ if (value === null || value === undefined) {
67
+ delete clone[key];
68
+ }
69
+ }
70
+ }
71
+ return clone;
72
+ }
73
+ model_dump_json(options) {
74
+ return JSON.stringify(this.model_dump(options));
75
+ }
76
+ get_index() {
77
+ for (const value of Object.values(this.data)) {
78
+ if (value && typeof value === 'object' && 'index' in value) {
79
+ return value.index ?? null;
80
+ }
81
+ }
82
+ return null;
83
+ }
84
+ set_index(index) {
85
+ const [actionName] = Object.keys(this.data);
86
+ if (!actionName) {
87
+ return;
88
+ }
89
+ const params = this.data[actionName];
90
+ if (params && typeof params === 'object' && 'index' in params) {
91
+ params.index = index;
92
+ }
93
+ }
94
+ }
95
+ export class ActionRegistry {
96
+ actions = new Map();
97
+ register(action) {
98
+ this.actions.set(action.name, action);
99
+ }
100
+ get(name) {
101
+ return this.actions.get(name) ?? null;
102
+ }
103
+ getAll() {
104
+ return Array.from(this.actions.values());
105
+ }
106
+ get actionsMap() {
107
+ return new Map(this.actions);
108
+ }
109
+ get actionEntries() {
110
+ return Array.from(this.actions.values());
111
+ }
112
+ _matchDomains(domains, pageUrl) {
113
+ if (!domains || domains.length === 0) {
114
+ return true;
115
+ }
116
+ if (!pageUrl) {
117
+ return false;
118
+ }
119
+ return domains.some((pattern) => {
120
+ try {
121
+ return match_url_with_domain_pattern(pageUrl, pattern);
122
+ }
123
+ catch {
124
+ return false;
125
+ }
126
+ });
127
+ }
128
+ _matchPageFilter(pageFilter, page) {
129
+ if (!pageFilter) {
130
+ return true;
131
+ }
132
+ try {
133
+ return pageFilter(page);
134
+ }
135
+ catch {
136
+ return false;
137
+ }
138
+ }
139
+ getAvailableActions(page, includeActions) {
140
+ const include = includeActions ? new Set(includeActions) : null;
141
+ return this.actionEntries.filter((action) => {
142
+ if (include && !include.has(action.name)) {
143
+ return false;
144
+ }
145
+ if (!page) {
146
+ return !action.pageFilter && !action.domains;
147
+ }
148
+ const pageUrl = getPageUrl(page);
149
+ const domainAllowed = this._matchDomains(action.domains, pageUrl);
150
+ const pageAllowed = this._matchPageFilter(action.pageFilter, page);
151
+ return domainAllowed && pageAllowed;
152
+ });
153
+ }
154
+ get_prompt_description(page) {
155
+ return this.getAvailableActions(page)
156
+ .map((action) => action.promptDescription())
157
+ .join('\n');
158
+ }
159
+ }
160
+ export class SpecialActionParameters {
161
+ context = null;
162
+ browser_session = null;
163
+ browser = null;
164
+ browser_context = null;
165
+ page = null;
166
+ page_extraction_llm = null;
167
+ file_system = null;
168
+ available_file_paths = null;
169
+ signal = null;
170
+ has_sensitive_data = false;
171
+ static get_browser_requiring_params() {
172
+ return new Set(['browser_session', 'browser', 'browser_context', 'page']);
173
+ }
174
+ }
@@ -0,0 +1,49 @@
1
+ import { z } from 'zod';
2
+ import { ActionResult } from '../agent/views.js';
3
+ import { FileSystem } from '../filesystem/file-system.js';
4
+ import { Registry } from './registry/service.js';
5
+ type BrowserSession = any;
6
+ type BaseChatModel = {
7
+ ainvoke: (messages: any[], output_format?: undefined, options?: {
8
+ signal?: AbortSignal;
9
+ }) => Promise<{
10
+ completion: string;
11
+ }>;
12
+ };
13
+ export interface ControllerOptions<Context = unknown> {
14
+ exclude_actions?: string[];
15
+ output_model?: z.ZodTypeAny | null;
16
+ display_files_in_done_text?: boolean;
17
+ context?: Context;
18
+ }
19
+ export interface ActParams<Context = unknown> {
20
+ browser_session: BrowserSession;
21
+ page_extraction_llm?: BaseChatModel | null;
22
+ sensitive_data?: Record<string, string | Record<string, string>> | null;
23
+ available_file_paths?: string[] | null;
24
+ file_system?: FileSystem | null;
25
+ context?: Context | null;
26
+ signal?: AbortSignal | null;
27
+ }
28
+ export declare class Controller<Context = unknown> {
29
+ registry: Registry<Context>;
30
+ private displayFilesInDoneText;
31
+ private logger;
32
+ constructor(options?: ControllerOptions<Context>);
33
+ private registerDefaultActions;
34
+ private registerNavigationActions;
35
+ private registerElementActions;
36
+ private registerTabActions;
37
+ private registerContentActions;
38
+ private registerScrollActions;
39
+ private registerFileSystemActions;
40
+ private registerKeyboardActions;
41
+ private registerDropdownActions;
42
+ private registerSheetsActions;
43
+ private gotoSheetsRange;
44
+ private registerDoneAction;
45
+ use_structured_output_action(outputModel: z.ZodTypeAny): void;
46
+ action(description: string, options?: {}): <Params = any>(handler: import("./index.js").RegistryActionHandler<Params, Context>) => import("./index.js").RegistryActionHandler<Params, Context>;
47
+ act(action: Record<string, unknown>, { browser_session, page_extraction_llm, sensitive_data, available_file_paths, file_system, context, signal, }: ActParams<Context>): Promise<ActionResult>;
48
+ }
49
+ export {};