browser-use 0.2.0 → 0.3.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 (259) hide show
  1. package/README.md +295 -686
  2. package/dist/actor/element.d.ts +19 -0
  3. package/dist/actor/element.js +46 -0
  4. package/dist/actor/index.d.ts +4 -0
  5. package/dist/actor/index.js +4 -0
  6. package/dist/actor/mouse.d.ts +19 -0
  7. package/dist/actor/mouse.js +39 -0
  8. package/dist/actor/page.d.ts +29 -0
  9. package/dist/actor/page.js +88 -0
  10. package/dist/actor/utils.d.ts +4 -0
  11. package/dist/actor/utils.js +35 -0
  12. package/dist/agent/cloud-events.d.ts +18 -0
  13. package/dist/agent/cloud-events.js +65 -2
  14. package/dist/agent/gif.d.ts +1 -0
  15. package/dist/agent/gif.js +24 -2
  16. package/dist/agent/judge.d.ts +17 -0
  17. package/dist/agent/judge.js +197 -0
  18. package/dist/agent/message-manager/service.d.ts +12 -4
  19. package/dist/agent/message-manager/service.js +205 -39
  20. package/dist/agent/message-manager/utils.js +0 -1
  21. package/dist/agent/message-manager/views.d.ts +4 -0
  22. package/dist/agent/message-manager/views.js +11 -7
  23. package/dist/agent/prompts.d.ts +24 -3
  24. package/dist/agent/prompts.js +274 -59
  25. package/dist/agent/service.d.ts +99 -41
  26. package/dist/agent/service.js +2266 -472
  27. package/dist/agent/variable-detector.d.ts +12 -0
  28. package/dist/agent/variable-detector.js +211 -0
  29. package/dist/agent/views.d.ts +237 -18
  30. package/dist/agent/views.js +446 -33
  31. package/dist/browser/cloud/cloud.d.ts +20 -0
  32. package/dist/browser/cloud/cloud.js +129 -0
  33. package/dist/browser/cloud/index.d.ts +2 -0
  34. package/dist/browser/cloud/index.js +2 -0
  35. package/dist/browser/cloud/views.d.ts +41 -0
  36. package/dist/browser/cloud/views.js +35 -0
  37. package/dist/browser/events.d.ts +345 -0
  38. package/dist/browser/events.js +566 -0
  39. package/dist/browser/extensions.js +17 -17
  40. package/dist/browser/index.d.ts +4 -0
  41. package/dist/browser/index.js +4 -0
  42. package/dist/browser/profile.d.ts +8 -2
  43. package/dist/browser/profile.js +79 -12
  44. package/dist/browser/session-manager.d.ts +85 -0
  45. package/dist/browser/session-manager.js +208 -0
  46. package/dist/browser/session.d.ts +100 -8
  47. package/dist/browser/session.js +1097 -58
  48. package/dist/browser/types.d.ts +0 -2
  49. package/dist/browser/views.d.ts +39 -0
  50. package/dist/browser/views.js +32 -0
  51. package/dist/browser/watchdogs/aboutblank-watchdog.d.ts +12 -0
  52. package/dist/browser/watchdogs/aboutblank-watchdog.js +131 -0
  53. package/dist/browser/watchdogs/base.d.ts +21 -0
  54. package/dist/browser/watchdogs/base.js +81 -0
  55. package/dist/browser/watchdogs/cdp-session-watchdog.d.ts +14 -0
  56. package/dist/browser/watchdogs/cdp-session-watchdog.js +177 -0
  57. package/dist/browser/watchdogs/crash-watchdog.d.ts +38 -0
  58. package/dist/browser/watchdogs/crash-watchdog.js +296 -0
  59. package/dist/browser/watchdogs/default-action-watchdog.d.ts +49 -0
  60. package/dist/browser/watchdogs/default-action-watchdog.js +212 -0
  61. package/dist/browser/watchdogs/dom-watchdog.d.ts +8 -0
  62. package/dist/browser/watchdogs/dom-watchdog.js +31 -0
  63. package/dist/browser/watchdogs/downloads-watchdog.d.ts +77 -0
  64. package/dist/browser/watchdogs/downloads-watchdog.js +409 -0
  65. package/dist/browser/watchdogs/har-recording-watchdog.d.ts +19 -0
  66. package/dist/browser/watchdogs/har-recording-watchdog.js +317 -0
  67. package/dist/browser/watchdogs/index.d.ts +15 -0
  68. package/dist/browser/watchdogs/index.js +15 -0
  69. package/dist/browser/watchdogs/local-browser-watchdog.d.ts +10 -0
  70. package/dist/browser/watchdogs/local-browser-watchdog.js +32 -0
  71. package/dist/browser/watchdogs/permissions-watchdog.d.ts +8 -0
  72. package/dist/browser/watchdogs/permissions-watchdog.js +73 -0
  73. package/dist/browser/watchdogs/popups-watchdog.d.ts +13 -0
  74. package/dist/browser/watchdogs/popups-watchdog.js +77 -0
  75. package/dist/browser/watchdogs/recording-watchdog.d.ts +27 -0
  76. package/dist/browser/watchdogs/recording-watchdog.js +249 -0
  77. package/dist/browser/watchdogs/screenshot-watchdog.d.ts +6 -0
  78. package/dist/browser/watchdogs/screenshot-watchdog.js +13 -0
  79. package/dist/browser/watchdogs/security-watchdog.d.ts +10 -0
  80. package/dist/browser/watchdogs/security-watchdog.js +84 -0
  81. package/dist/browser/watchdogs/storage-state-watchdog.d.ts +24 -0
  82. package/dist/browser/watchdogs/storage-state-watchdog.js +288 -0
  83. package/dist/cli.d.ts +7 -2
  84. package/dist/cli.js +182 -25
  85. package/dist/code-use/formatting.d.ts +3 -0
  86. package/dist/code-use/formatting.js +18 -0
  87. package/dist/code-use/index.d.ts +6 -0
  88. package/dist/code-use/index.js +6 -0
  89. package/dist/code-use/namespace.d.ts +5 -0
  90. package/dist/code-use/namespace.js +81 -0
  91. package/dist/code-use/notebook-export.d.ts +3 -0
  92. package/dist/code-use/notebook-export.js +56 -0
  93. package/dist/code-use/service.d.ts +24 -0
  94. package/dist/code-use/service.js +104 -0
  95. package/dist/code-use/utils.d.ts +4 -0
  96. package/dist/code-use/utils.js +98 -0
  97. package/dist/code-use/views.d.ts +108 -0
  98. package/dist/code-use/views.js +165 -0
  99. package/dist/config.d.ts +13 -0
  100. package/dist/config.js +69 -3
  101. package/dist/controller/registry/service.d.ts +10 -1
  102. package/dist/controller/registry/service.js +266 -10
  103. package/dist/controller/registry/views.d.ts +4 -1
  104. package/dist/controller/registry/views.js +25 -2
  105. package/dist/controller/service.d.ts +10 -1
  106. package/dist/controller/service.js +1807 -268
  107. package/dist/controller/views.d.ts +78 -155
  108. package/dist/controller/views.js +61 -12
  109. package/dist/dom/history-tree-processor/service.d.ts +5 -0
  110. package/dist/dom/history-tree-processor/service.js +169 -14
  111. package/dist/dom/history-tree-processor/view.d.ts +7 -1
  112. package/dist/dom/history-tree-processor/view.js +10 -1
  113. package/dist/dom/markdown-extractor.d.ts +37 -0
  114. package/dist/dom/markdown-extractor.js +345 -0
  115. package/dist/dom/service.d.ts +3 -1
  116. package/dist/dom/service.js +76 -0
  117. package/dist/dom/views.d.ts +1 -0
  118. package/dist/dom/views.js +45 -0
  119. package/dist/event-bus.d.ts +107 -7
  120. package/dist/event-bus.js +313 -10
  121. package/dist/exceptions.d.ts +0 -3
  122. package/dist/exceptions.js +0 -7
  123. package/dist/filesystem/file-system.d.ts +18 -0
  124. package/dist/filesystem/file-system.js +503 -42
  125. package/dist/index.d.ts +7 -0
  126. package/dist/index.js +6 -0
  127. package/dist/integrations/gmail/actions.d.ts +3 -3
  128. package/dist/integrations/gmail/actions.js +4 -4
  129. package/dist/llm/anthropic/chat.d.ts +18 -1
  130. package/dist/llm/anthropic/chat.js +123 -55
  131. package/dist/llm/anthropic/serializer.d.ts +2 -0
  132. package/dist/llm/anthropic/serializer.js +81 -9
  133. package/dist/llm/aws/chat-anthropic.d.ts +17 -0
  134. package/dist/llm/aws/chat-anthropic.js +126 -26
  135. package/dist/llm/aws/chat-bedrock.d.ts +28 -1
  136. package/dist/llm/aws/chat-bedrock.js +161 -34
  137. package/dist/llm/aws/serializer.d.ts +13 -1
  138. package/dist/llm/aws/serializer.js +56 -17
  139. package/dist/llm/azure/chat.d.ts +53 -2
  140. package/dist/llm/azure/chat.js +366 -54
  141. package/dist/llm/base.d.ts +2 -0
  142. package/dist/llm/browser-use/chat.d.ts +40 -0
  143. package/dist/llm/browser-use/chat.js +305 -0
  144. package/dist/llm/browser-use/index.d.ts +1 -0
  145. package/dist/llm/browser-use/index.js +1 -0
  146. package/dist/llm/cerebras/chat.d.ts +39 -0
  147. package/dist/llm/cerebras/chat.js +178 -0
  148. package/dist/llm/cerebras/index.d.ts +2 -0
  149. package/dist/llm/cerebras/index.js +2 -0
  150. package/dist/llm/cerebras/serializer.d.ts +7 -0
  151. package/dist/llm/cerebras/serializer.js +82 -0
  152. package/dist/llm/deepseek/chat.d.ts +19 -2
  153. package/dist/llm/deepseek/chat.js +138 -25
  154. package/dist/llm/google/chat.d.ts +46 -2
  155. package/dist/llm/google/chat.js +267 -64
  156. package/dist/llm/google/serializer.d.ts +9 -1
  157. package/dist/llm/google/serializer.js +141 -34
  158. package/dist/llm/groq/chat.d.ts +21 -2
  159. package/dist/llm/groq/chat.js +125 -26
  160. package/dist/llm/groq/parser.js +3 -1
  161. package/dist/llm/mistral/chat.d.ts +43 -0
  162. package/dist/llm/mistral/chat.js +154 -0
  163. package/dist/llm/mistral/index.d.ts +2 -0
  164. package/dist/llm/mistral/index.js +2 -0
  165. package/dist/llm/mistral/schema.d.ts +8 -0
  166. package/dist/llm/mistral/schema.js +27 -0
  167. package/dist/llm/models.d.ts +2 -0
  168. package/dist/llm/models.js +317 -0
  169. package/dist/llm/ollama/chat.d.ts +13 -1
  170. package/dist/llm/ollama/chat.js +110 -19
  171. package/dist/llm/ollama/serializer.d.ts +1 -0
  172. package/dist/llm/ollama/serializer.js +34 -12
  173. package/dist/llm/openai/chat.d.ts +16 -0
  174. package/dist/llm/openai/chat.js +94 -44
  175. package/dist/llm/openai/like.d.ts +5 -3
  176. package/dist/llm/openai/like.js +7 -3
  177. package/dist/llm/openai/responses-serializer.d.ts +18 -0
  178. package/dist/llm/openai/responses-serializer.js +72 -0
  179. package/dist/llm/openrouter/chat.d.ts +28 -2
  180. package/dist/llm/openrouter/chat.js +115 -29
  181. package/dist/llm/schema.d.ts +11 -1
  182. package/dist/llm/schema.js +81 -1
  183. package/dist/llm/vercel/chat.d.ts +50 -0
  184. package/dist/llm/vercel/chat.js +276 -0
  185. package/dist/llm/vercel/index.d.ts +1 -0
  186. package/dist/llm/vercel/index.js +1 -0
  187. package/dist/llm/vercel/serializer.d.ts +5 -0
  188. package/dist/llm/vercel/serializer.js +7 -0
  189. package/dist/llm/views.d.ts +2 -1
  190. package/dist/llm/views.js +3 -1
  191. package/dist/logging-config.d.ts +2 -0
  192. package/dist/logging-config.js +82 -29
  193. package/dist/mcp/client.d.ts +10 -5
  194. package/dist/mcp/client.js +14 -9
  195. package/dist/mcp/controller.d.ts +42 -3
  196. package/dist/mcp/controller.js +56 -31
  197. package/dist/mcp/server.d.ts +14 -0
  198. package/dist/mcp/server.js +255 -52
  199. package/dist/observability.js +10 -4
  200. package/dist/sandbox/index.d.ts +2 -0
  201. package/dist/sandbox/index.js +2 -0
  202. package/dist/sandbox/sandbox.d.ts +19 -0
  203. package/dist/sandbox/sandbox.js +140 -0
  204. package/dist/sandbox/views.d.ts +67 -0
  205. package/dist/sandbox/views.js +121 -0
  206. package/dist/skill-cli/index.d.ts +3 -0
  207. package/dist/skill-cli/index.js +3 -0
  208. package/dist/skill-cli/protocol.d.ts +30 -0
  209. package/dist/skill-cli/protocol.js +48 -0
  210. package/dist/skill-cli/server.d.ts +11 -0
  211. package/dist/skill-cli/server.js +85 -0
  212. package/dist/skill-cli/sessions.d.ts +24 -0
  213. package/dist/skill-cli/sessions.js +47 -0
  214. package/dist/skills/index.d.ts +3 -0
  215. package/dist/skills/index.js +3 -0
  216. package/dist/skills/service.d.ts +27 -0
  217. package/dist/skills/service.js +266 -0
  218. package/dist/skills/utils.d.ts +6 -0
  219. package/dist/skills/utils.js +53 -0
  220. package/dist/skills/views.d.ts +40 -0
  221. package/dist/skills/views.js +10 -0
  222. package/dist/sync/auth.js +8 -3
  223. package/dist/sync/service.d.ts +6 -6
  224. package/dist/sync/service.js +54 -89
  225. package/dist/telemetry/views.d.ts +20 -6
  226. package/dist/telemetry/views.js +23 -5
  227. package/dist/tokens/custom-pricing.d.ts +2 -0
  228. package/dist/tokens/custom-pricing.js +22 -0
  229. package/dist/tokens/index.d.ts +2 -0
  230. package/dist/tokens/index.js +2 -0
  231. package/dist/tokens/mappings.d.ts +1 -0
  232. package/dist/tokens/mappings.js +3 -0
  233. package/dist/tokens/service.js +27 -8
  234. package/dist/tools/extraction/index.d.ts +2 -0
  235. package/dist/tools/extraction/index.js +2 -0
  236. package/dist/tools/extraction/schema-utils.d.ts +6 -0
  237. package/dist/tools/extraction/schema-utils.js +237 -0
  238. package/dist/tools/extraction/views.d.ts +7 -0
  239. package/dist/tools/index.d.ts +5 -0
  240. package/dist/tools/index.js +5 -0
  241. package/dist/tools/registry/index.d.ts +2 -0
  242. package/dist/tools/registry/index.js +2 -0
  243. package/dist/tools/registry/service.d.ts +1 -0
  244. package/dist/tools/registry/service.js +1 -0
  245. package/dist/tools/registry/views.d.ts +1 -0
  246. package/dist/tools/registry/views.js +1 -0
  247. package/dist/tools/service.d.ts +2 -0
  248. package/dist/tools/service.js +1 -0
  249. package/dist/tools/utils.d.ts +2 -0
  250. package/dist/tools/utils.js +57 -0
  251. package/dist/tools/views.d.ts +1 -0
  252. package/dist/tools/views.js +1 -0
  253. package/dist/utils.d.ts +10 -1
  254. package/dist/utils.js +70 -3
  255. package/package.json +87 -26
  256. package/dist/dom/playground/process-dom.js +0 -5
  257. package/dist/dom/playground/test-accessibility.d.ts +0 -44
  258. package/dist/dom/playground/test-accessibility.js +0 -111
  259. /package/dist/{dom/playground/process-dom.d.ts → tools/extraction/views.js} +0 -0
@@ -0,0 +1,566 @@
1
+ import { EventBusEvent } from '../event-bus.js';
2
+ const getTimeout = (envVar, defaultValue) => {
3
+ const raw = process.env[envVar];
4
+ if (raw == null || raw.trim() === '') {
5
+ return defaultValue;
6
+ }
7
+ const parsed = Number(raw);
8
+ if (!Number.isFinite(parsed) || parsed < 0) {
9
+ return defaultValue;
10
+ }
11
+ return parsed;
12
+ };
13
+ const resolveEventTimeout = (eventName, defaultSeconds, explicitTimeout) => explicitTimeout !== undefined
14
+ ? explicitTimeout
15
+ : getTimeout(`TIMEOUT_${eventName}`, defaultSeconds);
16
+ export class BrowserEvent extends EventBusEvent {
17
+ constructor(eventType, init = {}) {
18
+ super(eventType, init);
19
+ }
20
+ }
21
+ export class ElementSelectedEvent extends BrowserEvent {
22
+ node;
23
+ constructor(eventType, init) {
24
+ super(eventType, init);
25
+ this.node = init.node;
26
+ }
27
+ }
28
+ export class NavigateToUrlEvent extends BrowserEvent {
29
+ url;
30
+ wait_until;
31
+ timeout_ms;
32
+ new_tab;
33
+ constructor(init) {
34
+ super('NavigateToUrlEvent', {
35
+ ...init,
36
+ event_timeout: resolveEventTimeout('NavigateToUrlEvent', 15, init.event_timeout),
37
+ });
38
+ this.url = init.url;
39
+ this.wait_until = init.wait_until ?? 'load';
40
+ this.timeout_ms = init.timeout_ms ?? null;
41
+ this.new_tab = init.new_tab ?? false;
42
+ }
43
+ }
44
+ export class ClickElementEvent extends ElementSelectedEvent {
45
+ button;
46
+ constructor(init) {
47
+ super('ClickElementEvent', {
48
+ ...init,
49
+ event_timeout: resolveEventTimeout('ClickElementEvent', 15, init.event_timeout),
50
+ });
51
+ this.button = init.button ?? 'left';
52
+ }
53
+ }
54
+ export class ClickCoordinateEvent extends BrowserEvent {
55
+ coordinate_x;
56
+ coordinate_y;
57
+ button;
58
+ force;
59
+ constructor(init) {
60
+ super('ClickCoordinateEvent', {
61
+ ...init,
62
+ event_timeout: resolveEventTimeout('ClickCoordinateEvent', 15, init.event_timeout),
63
+ });
64
+ this.coordinate_x = init.coordinate_x;
65
+ this.coordinate_y = init.coordinate_y;
66
+ this.button = init.button ?? 'left';
67
+ this.force = init.force ?? false;
68
+ }
69
+ }
70
+ export class TypeTextEvent extends ElementSelectedEvent {
71
+ text;
72
+ clear;
73
+ is_sensitive;
74
+ sensitive_key_name;
75
+ constructor(init) {
76
+ super('TypeTextEvent', {
77
+ ...init,
78
+ event_timeout: resolveEventTimeout('TypeTextEvent', 60, init.event_timeout),
79
+ });
80
+ this.text = init.text;
81
+ this.clear = init.clear ?? true;
82
+ this.is_sensitive = init.is_sensitive ?? false;
83
+ this.sensitive_key_name = init.sensitive_key_name ?? null;
84
+ }
85
+ }
86
+ export class ScrollEvent extends ElementSelectedEvent {
87
+ direction;
88
+ amount;
89
+ constructor(init) {
90
+ super('ScrollEvent', {
91
+ ...init,
92
+ node: init.node ?? null,
93
+ event_timeout: resolveEventTimeout('ScrollEvent', 8, init.event_timeout),
94
+ });
95
+ this.direction = init.direction;
96
+ this.amount = init.amount;
97
+ }
98
+ }
99
+ export class SwitchTabEvent extends BrowserEvent {
100
+ target_id;
101
+ constructor(init = {}) {
102
+ super('SwitchTabEvent', {
103
+ ...init,
104
+ event_timeout: resolveEventTimeout('SwitchTabEvent', 10, init.event_timeout),
105
+ });
106
+ this.target_id = init.target_id ?? null;
107
+ }
108
+ }
109
+ export class CloseTabEvent extends BrowserEvent {
110
+ target_id;
111
+ constructor(init) {
112
+ super('CloseTabEvent', {
113
+ ...init,
114
+ event_timeout: resolveEventTimeout('CloseTabEvent', 10, init.event_timeout),
115
+ });
116
+ this.target_id = init.target_id;
117
+ }
118
+ }
119
+ export class ScreenshotEvent extends BrowserEvent {
120
+ full_page;
121
+ clip;
122
+ constructor(init = {}) {
123
+ super('ScreenshotEvent', {
124
+ ...init,
125
+ event_timeout: resolveEventTimeout('ScreenshotEvent', 15, init.event_timeout),
126
+ });
127
+ this.full_page = init.full_page ?? false;
128
+ this.clip = init.clip ?? null;
129
+ }
130
+ }
131
+ export class BrowserStateRequestEvent extends BrowserEvent {
132
+ include_dom;
133
+ include_screenshot;
134
+ include_recent_events;
135
+ constructor(init = {}) {
136
+ super('BrowserStateRequestEvent', {
137
+ ...init,
138
+ event_timeout: resolveEventTimeout('BrowserStateRequestEvent', 30, init.event_timeout),
139
+ });
140
+ this.include_dom = init.include_dom ?? true;
141
+ this.include_screenshot = init.include_screenshot ?? true;
142
+ this.include_recent_events = init.include_recent_events ?? false;
143
+ }
144
+ }
145
+ export class GoBackEvent extends BrowserEvent {
146
+ constructor(init = {}) {
147
+ super('GoBackEvent', {
148
+ ...init,
149
+ event_timeout: resolveEventTimeout('GoBackEvent', 15, init.event_timeout),
150
+ });
151
+ }
152
+ }
153
+ export class GoForwardEvent extends BrowserEvent {
154
+ constructor(init = {}) {
155
+ super('GoForwardEvent', {
156
+ ...init,
157
+ event_timeout: resolveEventTimeout('GoForwardEvent', 15, init.event_timeout),
158
+ });
159
+ }
160
+ }
161
+ export class RefreshEvent extends BrowserEvent {
162
+ constructor(init = {}) {
163
+ super('RefreshEvent', {
164
+ ...init,
165
+ event_timeout: resolveEventTimeout('RefreshEvent', 15, init.event_timeout),
166
+ });
167
+ }
168
+ }
169
+ export class WaitEvent extends BrowserEvent {
170
+ seconds;
171
+ max_seconds;
172
+ constructor(init = {}) {
173
+ super('WaitEvent', {
174
+ ...init,
175
+ event_timeout: resolveEventTimeout('WaitEvent', 60, init.event_timeout),
176
+ });
177
+ this.seconds = init.seconds ?? 3;
178
+ this.max_seconds = init.max_seconds ?? 10;
179
+ }
180
+ }
181
+ export class SendKeysEvent extends BrowserEvent {
182
+ keys;
183
+ constructor(init) {
184
+ super('SendKeysEvent', {
185
+ ...init,
186
+ event_timeout: resolveEventTimeout('SendKeysEvent', 60, init.event_timeout),
187
+ });
188
+ this.keys = init.keys;
189
+ }
190
+ }
191
+ export class UploadFileEvent extends ElementSelectedEvent {
192
+ file_path;
193
+ constructor(init) {
194
+ super('UploadFileEvent', {
195
+ ...init,
196
+ event_timeout: resolveEventTimeout('UploadFileEvent', 30, init.event_timeout),
197
+ });
198
+ this.file_path = init.file_path;
199
+ }
200
+ }
201
+ export class GetDropdownOptionsEvent extends ElementSelectedEvent {
202
+ constructor(init) {
203
+ super('GetDropdownOptionsEvent', {
204
+ ...init,
205
+ event_timeout: resolveEventTimeout('GetDropdownOptionsEvent', 15, init.event_timeout),
206
+ });
207
+ }
208
+ }
209
+ export class SelectDropdownOptionEvent extends ElementSelectedEvent {
210
+ text;
211
+ constructor(init) {
212
+ super('SelectDropdownOptionEvent', {
213
+ ...init,
214
+ event_timeout: resolveEventTimeout('SelectDropdownOptionEvent', 8, init.event_timeout),
215
+ });
216
+ this.text = init.text;
217
+ }
218
+ }
219
+ export class ScrollToTextEvent extends BrowserEvent {
220
+ text;
221
+ direction;
222
+ constructor(init) {
223
+ super('ScrollToTextEvent', {
224
+ ...init,
225
+ event_timeout: resolveEventTimeout('ScrollToTextEvent', 15, init.event_timeout),
226
+ });
227
+ this.text = init.text;
228
+ this.direction = init.direction ?? 'down';
229
+ }
230
+ }
231
+ export class BrowserStartEvent extends BrowserEvent {
232
+ cdp_url;
233
+ launch_options;
234
+ constructor(init = {}) {
235
+ super('BrowserStartEvent', {
236
+ ...init,
237
+ event_timeout: resolveEventTimeout('BrowserStartEvent', 30, init.event_timeout),
238
+ });
239
+ this.cdp_url = init.cdp_url ?? null;
240
+ this.launch_options = init.launch_options ?? {};
241
+ }
242
+ }
243
+ export class BrowserStopEvent extends BrowserEvent {
244
+ force;
245
+ constructor(init = {}) {
246
+ super('BrowserStopEvent', {
247
+ ...init,
248
+ event_timeout: resolveEventTimeout('BrowserStopEvent', 45, init.event_timeout),
249
+ });
250
+ this.force = init.force ?? false;
251
+ }
252
+ }
253
+ export class BrowserLaunchEvent extends BrowserEvent {
254
+ constructor(init = {}) {
255
+ super('BrowserLaunchEvent', {
256
+ ...init,
257
+ event_timeout: resolveEventTimeout('BrowserLaunchEvent', 30, init.event_timeout),
258
+ });
259
+ }
260
+ }
261
+ export class BrowserKillEvent extends BrowserEvent {
262
+ constructor(init = {}) {
263
+ super('BrowserKillEvent', {
264
+ ...init,
265
+ event_timeout: resolveEventTimeout('BrowserKillEvent', 30, init.event_timeout),
266
+ });
267
+ }
268
+ }
269
+ export class BrowserConnectedEvent extends BrowserEvent {
270
+ cdp_url;
271
+ constructor(init) {
272
+ super('BrowserConnectedEvent', {
273
+ ...init,
274
+ event_timeout: resolveEventTimeout('BrowserConnectedEvent', 30, init.event_timeout),
275
+ });
276
+ this.cdp_url = init.cdp_url;
277
+ }
278
+ }
279
+ export class BrowserStoppedEvent extends BrowserEvent {
280
+ reason;
281
+ constructor(init = {}) {
282
+ super('BrowserStoppedEvent', {
283
+ ...init,
284
+ event_timeout: resolveEventTimeout('BrowserStoppedEvent', 30, init.event_timeout),
285
+ });
286
+ this.reason = init.reason ?? null;
287
+ }
288
+ }
289
+ export class TabCreatedEvent extends BrowserEvent {
290
+ target_id;
291
+ url;
292
+ constructor(init) {
293
+ super('TabCreatedEvent', {
294
+ ...init,
295
+ event_timeout: resolveEventTimeout('TabCreatedEvent', 30, init.event_timeout),
296
+ });
297
+ this.target_id = init.target_id;
298
+ this.url = init.url;
299
+ }
300
+ }
301
+ export class TabClosedEvent extends BrowserEvent {
302
+ target_id;
303
+ constructor(init) {
304
+ super('TabClosedEvent', {
305
+ ...init,
306
+ event_timeout: resolveEventTimeout('TabClosedEvent', 10, init.event_timeout),
307
+ });
308
+ this.target_id = init.target_id;
309
+ }
310
+ }
311
+ export class AgentFocusChangedEvent extends BrowserEvent {
312
+ target_id;
313
+ url;
314
+ constructor(init) {
315
+ super('AgentFocusChangedEvent', {
316
+ ...init,
317
+ event_timeout: resolveEventTimeout('AgentFocusChangedEvent', 10, init.event_timeout),
318
+ });
319
+ this.target_id = init.target_id;
320
+ this.url = init.url;
321
+ }
322
+ }
323
+ export class TargetCrashedEvent extends BrowserEvent {
324
+ target_id;
325
+ error;
326
+ constructor(init) {
327
+ super('TargetCrashedEvent', {
328
+ ...init,
329
+ event_timeout: resolveEventTimeout('TargetCrashedEvent', 10, init.event_timeout),
330
+ });
331
+ this.target_id = init.target_id;
332
+ this.error = init.error;
333
+ }
334
+ }
335
+ export class NavigationStartedEvent extends BrowserEvent {
336
+ target_id;
337
+ url;
338
+ constructor(init) {
339
+ super('NavigationStartedEvent', {
340
+ ...init,
341
+ event_timeout: resolveEventTimeout('NavigationStartedEvent', 30, init.event_timeout),
342
+ });
343
+ this.target_id = init.target_id;
344
+ this.url = init.url;
345
+ }
346
+ }
347
+ export class NavigationCompleteEvent extends BrowserEvent {
348
+ target_id;
349
+ url;
350
+ status;
351
+ error_message;
352
+ loading_status;
353
+ constructor(init) {
354
+ super('NavigationCompleteEvent', {
355
+ ...init,
356
+ event_timeout: resolveEventTimeout('NavigationCompleteEvent', 30, init.event_timeout),
357
+ });
358
+ this.target_id = init.target_id;
359
+ this.url = init.url;
360
+ this.status = init.status ?? null;
361
+ this.error_message = init.error_message ?? null;
362
+ this.loading_status = init.loading_status ?? null;
363
+ }
364
+ }
365
+ export class BrowserErrorEvent extends BrowserEvent {
366
+ error_type;
367
+ message;
368
+ details;
369
+ constructor(init) {
370
+ super('BrowserErrorEvent', {
371
+ ...init,
372
+ event_timeout: resolveEventTimeout('BrowserErrorEvent', 30, init.event_timeout),
373
+ });
374
+ this.error_type = init.error_type;
375
+ this.message = init.message;
376
+ this.details = init.details ?? {};
377
+ }
378
+ }
379
+ export class SaveStorageStateEvent extends BrowserEvent {
380
+ path;
381
+ constructor(init = {}) {
382
+ super('SaveStorageStateEvent', {
383
+ ...init,
384
+ event_timeout: resolveEventTimeout('SaveStorageStateEvent', 45, init.event_timeout),
385
+ });
386
+ this.path = init.path ?? null;
387
+ }
388
+ }
389
+ export class StorageStateSavedEvent extends BrowserEvent {
390
+ path;
391
+ cookies_count;
392
+ origins_count;
393
+ constructor(init) {
394
+ super('StorageStateSavedEvent', {
395
+ ...init,
396
+ event_timeout: resolveEventTimeout('StorageStateSavedEvent', 30, init.event_timeout),
397
+ });
398
+ this.path = init.path;
399
+ this.cookies_count = init.cookies_count;
400
+ this.origins_count = init.origins_count;
401
+ }
402
+ }
403
+ export class LoadStorageStateEvent extends BrowserEvent {
404
+ path;
405
+ constructor(init = {}) {
406
+ super('LoadStorageStateEvent', {
407
+ ...init,
408
+ event_timeout: resolveEventTimeout('LoadStorageStateEvent', 45, init.event_timeout),
409
+ });
410
+ this.path = init.path ?? null;
411
+ }
412
+ }
413
+ export class StorageStateLoadedEvent extends BrowserEvent {
414
+ path;
415
+ cookies_count;
416
+ origins_count;
417
+ constructor(init) {
418
+ super('StorageStateLoadedEvent', {
419
+ ...init,
420
+ event_timeout: resolveEventTimeout('StorageStateLoadedEvent', 30, init.event_timeout),
421
+ });
422
+ this.path = init.path;
423
+ this.cookies_count = init.cookies_count;
424
+ this.origins_count = init.origins_count;
425
+ }
426
+ }
427
+ export class DownloadStartedEvent extends BrowserEvent {
428
+ guid;
429
+ url;
430
+ suggested_filename;
431
+ auto_download;
432
+ constructor(init) {
433
+ super('DownloadStartedEvent', {
434
+ ...init,
435
+ event_timeout: resolveEventTimeout('DownloadStartedEvent', 5, init.event_timeout),
436
+ });
437
+ this.guid = init.guid;
438
+ this.url = init.url;
439
+ this.suggested_filename = init.suggested_filename;
440
+ this.auto_download = init.auto_download ?? false;
441
+ }
442
+ }
443
+ export class DownloadProgressEvent extends BrowserEvent {
444
+ guid;
445
+ received_bytes;
446
+ total_bytes;
447
+ state;
448
+ constructor(init) {
449
+ super('DownloadProgressEvent', {
450
+ ...init,
451
+ event_timeout: resolveEventTimeout('DownloadProgressEvent', 5, init.event_timeout),
452
+ });
453
+ this.guid = init.guid;
454
+ this.received_bytes = init.received_bytes;
455
+ this.total_bytes = init.total_bytes;
456
+ this.state = init.state;
457
+ }
458
+ }
459
+ export class FileDownloadedEvent extends BrowserEvent {
460
+ guid;
461
+ url;
462
+ path;
463
+ file_name;
464
+ file_size;
465
+ file_type;
466
+ mime_type;
467
+ from_cache;
468
+ auto_download;
469
+ constructor(init) {
470
+ super('FileDownloadedEvent', {
471
+ ...init,
472
+ event_timeout: resolveEventTimeout('FileDownloadedEvent', 30, init.event_timeout),
473
+ });
474
+ this.guid = init.guid ?? null;
475
+ this.url = init.url;
476
+ this.path = init.path;
477
+ this.file_name = init.file_name;
478
+ this.file_size = init.file_size;
479
+ this.file_type = init.file_type ?? null;
480
+ this.mime_type = init.mime_type ?? null;
481
+ this.from_cache = init.from_cache ?? false;
482
+ this.auto_download = init.auto_download ?? false;
483
+ }
484
+ }
485
+ export class AboutBlankDVDScreensaverShownEvent extends BrowserEvent {
486
+ target_id;
487
+ error;
488
+ constructor(init) {
489
+ super('AboutBlankDVDScreensaverShownEvent', init);
490
+ this.target_id = init.target_id;
491
+ this.error = init.error ?? null;
492
+ }
493
+ }
494
+ export class DialogOpenedEvent extends BrowserEvent {
495
+ dialog_type;
496
+ message;
497
+ url;
498
+ frame_id;
499
+ constructor(init) {
500
+ super('DialogOpenedEvent', init);
501
+ this.dialog_type = init.dialog_type;
502
+ this.message = init.message;
503
+ this.url = init.url;
504
+ this.frame_id = init.frame_id ?? null;
505
+ }
506
+ }
507
+ export const BROWSER_EVENT_CLASSES = [
508
+ ElementSelectedEvent,
509
+ NavigateToUrlEvent,
510
+ ClickElementEvent,
511
+ ClickCoordinateEvent,
512
+ TypeTextEvent,
513
+ ScrollEvent,
514
+ SwitchTabEvent,
515
+ CloseTabEvent,
516
+ ScreenshotEvent,
517
+ BrowserStateRequestEvent,
518
+ GoBackEvent,
519
+ GoForwardEvent,
520
+ RefreshEvent,
521
+ WaitEvent,
522
+ SendKeysEvent,
523
+ UploadFileEvent,
524
+ GetDropdownOptionsEvent,
525
+ SelectDropdownOptionEvent,
526
+ ScrollToTextEvent,
527
+ BrowserStartEvent,
528
+ BrowserStopEvent,
529
+ BrowserLaunchEvent,
530
+ BrowserKillEvent,
531
+ BrowserConnectedEvent,
532
+ BrowserStoppedEvent,
533
+ TabCreatedEvent,
534
+ TabClosedEvent,
535
+ AgentFocusChangedEvent,
536
+ TargetCrashedEvent,
537
+ NavigationStartedEvent,
538
+ NavigationCompleteEvent,
539
+ BrowserErrorEvent,
540
+ SaveStorageStateEvent,
541
+ StorageStateSavedEvent,
542
+ LoadStorageStateEvent,
543
+ StorageStateLoadedEvent,
544
+ DownloadStartedEvent,
545
+ DownloadProgressEvent,
546
+ FileDownloadedEvent,
547
+ AboutBlankDVDScreensaverShownEvent,
548
+ DialogOpenedEvent,
549
+ ];
550
+ export const BROWSER_EVENT_NAMES = BROWSER_EVENT_CLASSES.map((eventClass) => eventClass.name);
551
+ const checkEventNamesDontOverlap = () => {
552
+ for (const nameA of BROWSER_EVENT_NAMES) {
553
+ if (!nameA.endsWith('Event')) {
554
+ throw new Error(`Event ${nameA} does not end with Event`);
555
+ }
556
+ for (const nameB of BROWSER_EVENT_NAMES) {
557
+ if (nameA === nameB) {
558
+ continue;
559
+ }
560
+ if (nameB.includes(nameA)) {
561
+ throw new Error(`Event ${nameA} is a substring of ${nameB}; event names must be non-overlapping`);
562
+ }
563
+ }
564
+ }
565
+ };
566
+ checkEventNamesDontOverlap();
@@ -161,26 +161,26 @@ export async function loadOrInstallExtension(ext, extensionsDir = path.join(proc
161
161
  * Check if a browser target is an extension
162
162
  */
163
163
  export async function isTargetExtension(target) {
164
- let target_type = null;
165
- let target_ctx = null;
166
- let target_url = null;
167
- try {
168
- target_type = await target.type();
169
- target_ctx = (await target.worker?.()) || (await target.page?.()) || null;
170
- target_url =
171
- (await target.url?.()) || (target_ctx ? await target_ctx.url() : null);
172
- }
173
- catch (error) {
174
- if (error.message?.includes('No target with given id found')) {
175
- // Target already closed
176
- target_type = 'closed';
177
- target_ctx = null;
178
- target_url = 'about:closed';
164
+ const targetInfo = await (async () => {
165
+ try {
166
+ const target_type = await target.type();
167
+ const target_ctx = (await target.worker?.()) || (await target.page?.()) || null;
168
+ const target_url = (await target.url?.()) || (target_ctx ? await target_ctx.url() : null);
169
+ return { target_type, target_ctx, target_url };
179
170
  }
180
- else {
171
+ catch (error) {
172
+ if (error.message?.includes('No target with given id found')) {
173
+ // Target already closed
174
+ return {
175
+ target_type: 'closed',
176
+ target_ctx: null,
177
+ target_url: 'about:closed',
178
+ };
179
+ }
181
180
  throw error;
182
181
  }
183
- }
182
+ })();
183
+ const { target_type, target_ctx, target_url } = targetInfo;
184
184
  const target_is_bg = ['service_worker', 'background_page'].includes(target_type || '');
185
185
  const target_is_extension = target_url?.startsWith('chrome-extension://') || false;
186
186
  const extension_id = target_is_extension
@@ -1,10 +1,14 @@
1
1
  export * from './profile.js';
2
2
  export * from './views.js';
3
3
  export * from './utils.js';
4
+ export * from './cloud/index.js';
4
5
  export * from './session.js';
5
6
  export * from './extensions.js';
6
7
  export * from './dvd-screensaver.js';
7
8
  export * from './playwright-manager.js';
9
+ export * from './events.js';
10
+ export * from './watchdogs/index.js';
11
+ export * from './session-manager.js';
8
12
  export type { Browser, BrowserConfig, BrowserContext, BrowserContextConfig, } from './context.js';
9
13
  export type { Browser as PlaywrightBrowser, BrowserContext as PlaywrightBrowserContext, Page, Locator, FrameLocator, ElementHandle, Playwright, PlaywrightOrPatchright, ClientCertificate, Geolocation, HttpCredentials, ProxySettings, StorageState, ViewportSize, } from './types.js';
10
14
  export { async_playwright } from './types.js';
@@ -1,9 +1,13 @@
1
1
  export * from './profile.js';
2
2
  export * from './views.js';
3
3
  export * from './utils.js';
4
+ export * from './cloud/index.js';
4
5
  export * from './session.js';
5
6
  export * from './extensions.js';
6
7
  export * from './dvd-screensaver.js';
7
8
  export * from './playwright-manager.js';
9
+ export * from './events.js';
10
+ export * from './watchdogs/index.js';
11
+ export * from './session-manager.js';
8
12
  // Re-export the async playwright loader
9
13
  export { async_playwright } from './types.js';
@@ -1,5 +1,6 @@
1
1
  import type { ClientCertificate, Geolocation, HttpCredentials, ProxySettings, ViewportSize, StorageState } from './types.js';
2
2
  export declare const CHROME_DEBUG_PORT = 9242;
3
+ export declare const DOMAIN_OPTIMIZATION_THRESHOLD = 100;
3
4
  export declare const CHROME_DISABLED_COMPONENTS: string[];
4
5
  export declare const CHROME_HEADLESS_ARGS: string[];
5
6
  export declare const CHROME_DOCKER_ARGS: string[];
@@ -131,7 +132,9 @@ export interface BrowserProfileSpecificOptions {
131
132
  stealth: boolean;
132
133
  disable_security: boolean;
133
134
  deterministic_rendering: boolean;
134
- allowed_domains: Nullable<string[]>;
135
+ allowed_domains: Nullable<string[] | Set<string>>;
136
+ prohibited_domains: Nullable<string[] | Set<string>>;
137
+ block_ip_addresses: boolean;
135
138
  keep_alive: Nullable<boolean>;
136
139
  enable_default_extensions: boolean;
137
140
  window_size: Nullable<ViewportSize>;
@@ -157,7 +160,9 @@ export declare class BrowserProfile {
157
160
  toString(): string;
158
161
  describe(): string;
159
162
  get config(): BrowserProfileOptions;
160
- get allowed_domains(): Nullable<string[]>;
163
+ get allowed_domains(): Nullable<string[] | Set<string>>;
164
+ get prohibited_domains(): Nullable<string[] | Set<string>>;
165
+ get block_ip_addresses(): boolean;
161
166
  get cookies_file(): Nullable<string>;
162
167
  get default_navigation_timeout(): Nullable<number>;
163
168
  get downloads_path(): Nullable<string>;
@@ -175,6 +180,7 @@ export declare class BrowserProfile {
175
180
  private warnStorageStateUserDataDirConflict;
176
181
  private warnUserDataDirNonDefault;
177
182
  private warnDeterministicRenderingWeirdness;
183
+ private ensureDefaultDownloadsPath;
178
184
  private getDefaultArgsList;
179
185
  private getWindowSizeArgs;
180
186
  private getWindowPositionArgs;