@agent-infra/browser 0.1.5 → 0.2.0-alpha.3

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 (187) hide show
  1. package/LICENSE +201 -0
  2. package/README.md +35 -52
  3. package/README.zh-CN.md +57 -0
  4. package/dist/actions/index.d.ts +3 -0
  5. package/dist/actions/index.d.ts.map +1 -0
  6. package/dist/actions/index.js +46 -0
  7. package/dist/actions/index.js.map +1 -0
  8. package/dist/actions/index.mjs +7 -0
  9. package/dist/actions/key-map.d.ts +28 -0
  10. package/dist/actions/key-map.d.ts.map +1 -0
  11. package/dist/actions/key-map.js +409 -0
  12. package/dist/actions/key-map.js.map +1 -0
  13. package/dist/actions/key-map.mjs +369 -0
  14. package/dist/actions/key-map.mjs.map +1 -0
  15. package/dist/actions/keyboard.d.ts +21 -0
  16. package/dist/actions/keyboard.d.ts.map +1 -0
  17. package/dist/actions/keyboard.js +196 -0
  18. package/dist/actions/keyboard.js.map +1 -0
  19. package/dist/actions/keyboard.mjs +152 -0
  20. package/dist/actions/keyboard.mjs.map +1 -0
  21. package/dist/actions/keyboard.test.d.ts +2 -0
  22. package/dist/actions/keyboard.test.d.ts.map +1 -0
  23. package/dist/actions/mouse.d.ts +19 -0
  24. package/dist/actions/mouse.d.ts.map +1 -0
  25. package/dist/actions/mouse.js +173 -0
  26. package/dist/actions/mouse.js.map +1 -0
  27. package/dist/actions/mouse.mjs +136 -0
  28. package/dist/actions/mouse.mjs.map +1 -0
  29. package/dist/browser/base.d.ts +47 -0
  30. package/dist/browser/base.d.ts.map +1 -0
  31. package/dist/browser/base.js +156 -0
  32. package/dist/browser/base.js.map +1 -0
  33. package/dist/browser/base.mjs +122 -0
  34. package/dist/browser/base.mjs.map +1 -0
  35. package/dist/browser/browser.d.ts +23 -0
  36. package/dist/browser/browser.d.ts.map +1 -0
  37. package/dist/browser/browser.js +183 -0
  38. package/dist/browser/browser.js.map +1 -0
  39. package/dist/browser/browser.mjs +149 -0
  40. package/dist/browser/browser.mjs.map +1 -0
  41. package/dist/env.d.ts +4 -0
  42. package/dist/env.d.ts.map +1 -0
  43. package/dist/env.js +96 -0
  44. package/dist/env.js.map +1 -0
  45. package/dist/env.mjs +62 -0
  46. package/dist/env.mjs.map +1 -0
  47. package/dist/index.node.d.ts +7 -0
  48. package/dist/index.node.d.ts.map +1 -0
  49. package/dist/index.node.js +106 -0
  50. package/dist/index.node.js.map +1 -0
  51. package/dist/index.node.mjs +10 -0
  52. package/dist/index.web.d.ts +7 -0
  53. package/dist/index.web.d.ts.map +1 -0
  54. package/dist/{index.js → index.web.js} +33 -20
  55. package/dist/index.web.js.map +1 -0
  56. package/dist/index.web.mjs +10 -0
  57. package/dist/injected-script/index.d.ts +3 -0
  58. package/dist/injected-script/index.d.ts.map +1 -0
  59. package/dist/injected-script/index.js +46 -0
  60. package/dist/injected-script/index.js.map +1 -0
  61. package/dist/injected-script/index.mjs +7 -0
  62. package/dist/injected-script/visibility.d.ts +2 -0
  63. package/dist/injected-script/visibility.d.ts.map +1 -0
  64. package/dist/injected-script/visibility.js +66 -0
  65. package/dist/injected-script/visibility.js.map +1 -0
  66. package/dist/injected-script/visibility.mjs +32 -0
  67. package/dist/injected-script/visibility.mjs.map +1 -0
  68. package/dist/injected-script/webdriver.d.ts +2 -0
  69. package/dist/injected-script/webdriver.d.ts.map +1 -0
  70. package/dist/injected-script/webdriver.js +71 -0
  71. package/dist/injected-script/webdriver.js.map +1 -0
  72. package/dist/injected-script/webdriver.mjs +37 -0
  73. package/dist/injected-script/webdriver.mjs.map +1 -0
  74. package/dist/polyfills/index.d.ts +2 -0
  75. package/dist/polyfills/index.d.ts.map +1 -0
  76. package/dist/polyfills/index.js +66 -0
  77. package/dist/polyfills/index.js.map +1 -0
  78. package/dist/polyfills/index.mjs +5 -0
  79. package/dist/polyfills/withResolvers.d.ts +2 -0
  80. package/dist/polyfills/withResolvers.d.ts.map +1 -0
  81. package/dist/polyfills/withResolvers.js +37 -0
  82. package/dist/polyfills/withResolvers.js.map +1 -0
  83. package/dist/polyfills/withResolvers.mjs +19 -0
  84. package/dist/polyfills/withResolvers.mjs.map +1 -0
  85. package/dist/tabs/dialog.d.ts +14 -0
  86. package/dist/tabs/dialog.d.ts.map +1 -0
  87. package/dist/tabs/dialog.js +175 -0
  88. package/dist/tabs/dialog.js.map +1 -0
  89. package/dist/tabs/dialog.mjs +141 -0
  90. package/dist/tabs/dialog.mjs.map +1 -0
  91. package/dist/tabs/index.d.ts +3 -0
  92. package/dist/tabs/index.d.ts.map +1 -0
  93. package/dist/tabs/index.js +46 -0
  94. package/dist/tabs/index.js.map +1 -0
  95. package/dist/tabs/index.mjs +7 -0
  96. package/dist/tabs/tab.d.ts +50 -0
  97. package/dist/tabs/tab.d.ts.map +1 -0
  98. package/dist/tabs/tab.js +579 -0
  99. package/dist/tabs/tab.js.map +1 -0
  100. package/dist/tabs/tab.mjs +545 -0
  101. package/dist/tabs/tab.mjs.map +1 -0
  102. package/dist/tabs/tabs.d.ts +21 -0
  103. package/dist/tabs/tabs.d.ts.map +1 -0
  104. package/dist/tabs/tabs.js +458 -0
  105. package/dist/tabs/tabs.js.map +1 -0
  106. package/dist/tabs/tabs.mjs +424 -0
  107. package/dist/tabs/tabs.mjs.map +1 -0
  108. package/dist/types/actions.d.ts +26 -0
  109. package/dist/types/actions.d.ts.map +1 -0
  110. package/dist/types/actions.js +24 -0
  111. package/dist/types/actions.js.map +1 -0
  112. package/dist/types/browser.d.ts +7 -0
  113. package/dist/types/browser.d.ts.map +1 -0
  114. package/dist/types/browser.js +24 -0
  115. package/dist/types/browser.js.map +1 -0
  116. package/dist/types/browser.mjs +4 -0
  117. package/dist/types/dialog.d.ts +7 -0
  118. package/dist/types/dialog.d.ts.map +1 -0
  119. package/dist/types/dialog.js +24 -0
  120. package/dist/types/dialog.js.map +1 -0
  121. package/dist/types/dialog.mjs +4 -0
  122. package/dist/types/env.d.ts +8 -0
  123. package/dist/types/env.d.ts.map +1 -0
  124. package/dist/{types.js → types/env.js} +1 -1
  125. package/dist/types/env.js.map +1 -0
  126. package/dist/types/env.mjs +4 -0
  127. package/dist/types/index.d.ts +6 -0
  128. package/dist/types/index.d.ts.map +1 -0
  129. package/dist/types/index.js +102 -0
  130. package/dist/types/index.js.map +1 -0
  131. package/dist/types/index.mjs +9 -0
  132. package/dist/types/tabs.d.ts +98 -0
  133. package/dist/types/tabs.d.ts.map +1 -0
  134. package/dist/types/tabs.js +48 -0
  135. package/dist/types/tabs.js.map +1 -0
  136. package/dist/types/tabs.mjs +14 -0
  137. package/dist/types/tabs.mjs.map +1 -0
  138. package/dist/utils/iife.d.ts +2 -0
  139. package/dist/utils/iife.d.ts.map +1 -0
  140. package/dist/utils/iife.js +48 -0
  141. package/dist/utils/iife.js.map +1 -0
  142. package/dist/utils/iife.mjs +14 -0
  143. package/dist/utils/iife.mjs.map +1 -0
  144. package/dist/utils/index.d.ts +4 -0
  145. package/dist/utils/index.d.ts.map +1 -0
  146. package/dist/utils/index.js +50 -0
  147. package/dist/utils/index.js.map +1 -0
  148. package/dist/utils/index.mjs +8 -0
  149. package/dist/utils/mutex.d.ts +21 -0
  150. package/dist/utils/mutex.d.ts.map +1 -0
  151. package/dist/utils/mutex.js +133 -0
  152. package/dist/utils/mutex.js.map +1 -0
  153. package/dist/utils/mutex.mjs +99 -0
  154. package/dist/utils/mutex.mjs.map +1 -0
  155. package/dist/utils/url.d.ts +7 -0
  156. package/dist/utils/url.d.ts.map +1 -0
  157. package/dist/utils/url.js +76 -0
  158. package/dist/utils/url.js.map +1 -0
  159. package/dist/utils/url.mjs +42 -0
  160. package/dist/utils/url.mjs.map +1 -0
  161. package/package.json +21 -13
  162. package/dist/base-browser.d.ts +0 -94
  163. package/dist/base-browser.d.ts.map +0 -1
  164. package/dist/base-browser.js +0 -189
  165. package/dist/base-browser.js.map +0 -1
  166. package/dist/base-browser.mjs +0 -155
  167. package/dist/base-browser.mjs.map +0 -1
  168. package/dist/index.d.ts +0 -15
  169. package/dist/index.d.ts.map +0 -1
  170. package/dist/index.js.map +0 -1
  171. package/dist/index.mjs +0 -8
  172. package/dist/local-browser.d.ts +0 -19
  173. package/dist/local-browser.d.ts.map +0 -1
  174. package/dist/local-browser.js +0 -134
  175. package/dist/local-browser.js.map +0 -1
  176. package/dist/local-browser.mjs +0 -100
  177. package/dist/local-browser.mjs.map +0 -1
  178. package/dist/remote-browser.d.ts +0 -49
  179. package/dist/remote-browser.d.ts.map +0 -1
  180. package/dist/remote-browser.js +0 -89
  181. package/dist/remote-browser.js.map +0 -1
  182. package/dist/remote-browser.mjs +0 -55
  183. package/dist/remote-browser.mjs.map +0 -1
  184. package/dist/types.d.ts +0 -158
  185. package/dist/types.d.ts.map +0 -1
  186. package/dist/types.js.map +0 -1
  187. /package/dist/{types.mjs → types/actions.mjs} +0 -0
package/LICENSE ADDED
@@ -0,0 +1,201 @@
1
+ Apache License
2
+ Version 2.0, January 2004
3
+ http://www.apache.org/licenses/
4
+
5
+ TERMS AND CONDITIONS FOR USE, REPRODUCTION, AND DISTRIBUTION
6
+
7
+ 1. Definitions.
8
+
9
+ "License" shall mean the terms and conditions for use, reproduction,
10
+ and distribution as defined by Sections 1 through 9 of this document.
11
+
12
+ "Licensor" shall mean the copyright owner or entity authorized by
13
+ the copyright owner that is granting the License.
14
+
15
+ "Legal Entity" shall mean the union of the acting entity and all
16
+ other entities that control, are controlled by, or are under common
17
+ control with that entity. For the purposes of this definition,
18
+ "control" means (i) the power, direct or indirect, to cause the
19
+ direction or management of such entity, whether by contract or
20
+ otherwise, or (ii) ownership of fifty percent (50%) or more of the
21
+ outstanding shares, or (iii) beneficial ownership of such entity.
22
+
23
+ "You" (or "Your") shall mean an individual or Legal Entity
24
+ exercising permissions granted by this License.
25
+
26
+ "Source" form shall mean the preferred form for making modifications,
27
+ including but not limited to software source code, documentation
28
+ source, and configuration files.
29
+
30
+ "Object" form shall mean any form resulting from mechanical
31
+ transformation or translation of a Source form, including but
32
+ not limited to compiled object code, generated documentation,
33
+ and conversions to other media types.
34
+
35
+ "Work" shall mean the work of authorship, whether in Source or
36
+ Object form, made available under the License, as indicated by a
37
+ copyright notice that is included in or attached to the work
38
+ (an example is provided in the Appendix below).
39
+
40
+ "Derivative Works" shall mean any work, whether in Source or Object
41
+ form, that is based on (or derived from) the Work and for which the
42
+ editorial revisions, annotations, elaborations, or other modifications
43
+ represent, as a whole, an original work of authorship. For the purposes
44
+ of this License, Derivative Works shall not include works that remain
45
+ separable from, or merely link (or bind by name) to the interfaces of,
46
+ the Work and Derivative Works thereof.
47
+
48
+ "Contribution" shall mean any work of authorship, including
49
+ the original version of the Work and any modifications or additions
50
+ to that Work or Derivative Works thereof, that is intentionally
51
+ submitted to Licensor for inclusion in the Work by the copyright owner
52
+ or by an individual or Legal Entity authorized to submit on behalf of
53
+ the copyright owner. For the purposes of this definition, "submitted"
54
+ means any form of electronic, verbal, or written communication sent
55
+ to the Licensor or its representatives, including but not limited to
56
+ communication on electronic mailing lists, source code control systems,
57
+ and issue tracking systems that are managed by, or on behalf of, the
58
+ Licensor for the purpose of discussing and improving the Work, but
59
+ excluding communication that is conspicuously marked or otherwise
60
+ designated in writing by the copyright owner as "Not a Contribution."
61
+
62
+ "Contributor" shall mean Licensor and any individual or Legal Entity
63
+ on behalf of whom a Contribution has been received by Licensor and
64
+ subsequently incorporated within the Work.
65
+
66
+ 2. Grant of Copyright License. Subject to the terms and conditions of
67
+ this License, each Contributor hereby grants to You a perpetual,
68
+ worldwide, non-exclusive, no-charge, royalty-free, irrevocable
69
+ copyright license to reproduce, prepare Derivative Works of,
70
+ publicly display, publicly perform, sublicense, and distribute the
71
+ Work and such Derivative Works in Source or Object form.
72
+
73
+ 3. Grant of Patent License. Subject to the terms and conditions of
74
+ this License, each Contributor hereby grants to You a perpetual,
75
+ worldwide, non-exclusive, no-charge, royalty-free, irrevocable
76
+ (except as stated in this section) patent license to make, have made,
77
+ use, offer to sell, sell, import, and otherwise transfer the Work,
78
+ where such license applies only to those patent claims licensable
79
+ by such Contributor that are necessarily infringed by their
80
+ Contribution(s) alone or by combination of their Contribution(s)
81
+ with the Work to which such Contribution(s) was submitted. If You
82
+ institute patent litigation against any entity (including a
83
+ cross-claim or counterclaim in a lawsuit) alleging that the Work
84
+ or a Contribution incorporated within the Work constitutes direct
85
+ or contributory patent infringement, then any patent licenses
86
+ granted to You under this License for that Work shall terminate
87
+ as of the date such litigation is filed.
88
+
89
+ 4. Redistribution. You may reproduce and distribute copies of the
90
+ Work or Derivative Works thereof in any medium, with or without
91
+ modifications, and in Source or Object form, provided that You
92
+ meet the following conditions:
93
+
94
+ (a) You must give any other recipients of the Work or
95
+ Derivative Works a copy of this License; and
96
+
97
+ (b) You must cause any modified files to carry prominent notices
98
+ stating that You changed the files; and
99
+
100
+ (c) You must retain, in the Source form of any Derivative Works
101
+ that You distribute, all copyright, patent, trademark, and
102
+ attribution notices from the Source form of the Work,
103
+ excluding those notices that do not pertain to any part of
104
+ the Derivative Works; and
105
+
106
+ (d) If the Work includes a "NOTICE" text file as part of its
107
+ distribution, then any Derivative Works that You distribute must
108
+ include a readable copy of the attribution notices contained
109
+ within such NOTICE file, excluding those notices that do not
110
+ pertain to any part of the Derivative Works, in at least one
111
+ of the following places: within a NOTICE text file distributed
112
+ as part of the Derivative Works; within the Source form or
113
+ documentation, if provided along with the Derivative Works; or,
114
+ within a display generated by the Derivative Works, if and
115
+ wherever such third-party notices normally appear. The contents
116
+ of the NOTICE file are for informational purposes only and
117
+ do not modify the License. You may add Your own attribution
118
+ notices within Derivative Works that You distribute, alongside
119
+ or as an addendum to the NOTICE text from the Work, provided
120
+ that such additional attribution notices cannot be construed
121
+ as modifying the License.
122
+
123
+ You may add Your own copyright statement to Your modifications and
124
+ may provide additional or different license terms and conditions
125
+ for use, reproduction, or distribution of Your modifications, or
126
+ for any such Derivative Works as a whole, provided Your use,
127
+ reproduction, and distribution of the Work otherwise complies with
128
+ the conditions stated in this License.
129
+
130
+ 5. Submission of Contributions. Unless You explicitly state otherwise,
131
+ any Contribution intentionally submitted for inclusion in the Work
132
+ by You to the Licensor shall be under the terms and conditions of
133
+ this License, without any additional terms or conditions.
134
+ Notwithstanding the above, nothing herein shall supersede or modify
135
+ the terms of any separate license agreement you may have executed
136
+ with Licensor regarding such Contributions.
137
+
138
+ 6. Trademarks. This License does not grant permission to use the trade
139
+ names, trademarks, service marks, or product names of the Licensor,
140
+ except as required for reasonable and customary use in describing the
141
+ origin of the Work and reproducing the content of the NOTICE file.
142
+
143
+ 7. Disclaimer of Warranty. Unless required by applicable law or
144
+ agreed to in writing, Licensor provides the Work (and each
145
+ Contributor provides its Contributions) on an "AS IS" BASIS,
146
+ WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or
147
+ implied, including, without limitation, any warranties or conditions
148
+ of TITLE, NON-INFRINGEMENT, MERCHANTABILITY, or FITNESS FOR A
149
+ PARTICULAR PURPOSE. You are solely responsible for determining the
150
+ appropriateness of using or redistributing the Work and assume any
151
+ risks associated with Your exercise of permissions under this License.
152
+
153
+ 8. Limitation of Liability. In no event and under no legal theory,
154
+ whether in tort (including negligence), contract, or otherwise,
155
+ unless required by applicable law (such as deliberate and grossly
156
+ negligent acts) or agreed to in writing, shall any Contributor be
157
+ liable to You for damages, including any direct, indirect, special,
158
+ incidental, or consequential damages of any character arising as a
159
+ result of this License or out of the use or inability to use the
160
+ Work (including but not limited to damages for loss of goodwill,
161
+ work stoppage, computer failure or malfunction, or any and all
162
+ other commercial damages or losses), even if such Contributor
163
+ has been advised of the possibility of such damages.
164
+
165
+ 9. Accepting Warranty or Additional Liability. While redistributing
166
+ the Work or Derivative Works thereof, You may choose to offer,
167
+ and charge a fee for, acceptance of support, warranty, indemnity,
168
+ or other liability obligations and/or rights consistent with this
169
+ License. However, in accepting such obligations, You may act only
170
+ on Your own behalf and on Your sole responsibility, not on behalf
171
+ of any other Contributor, and only if You agree to indemnify,
172
+ defend, and hold each Contributor harmless for any liability
173
+ incurred by, or claims asserted against, such Contributor by reason
174
+ of your accepting any such warranty or additional liability.
175
+
176
+ END OF TERMS AND CONDITIONS
177
+
178
+ APPENDIX: How to apply the Apache License to your work.
179
+
180
+ To apply the Apache License to your work, attach the following
181
+ boilerplate notice, with the fields enclosed by brackets "[]"
182
+ replaced with your own identifying information. (Don't include
183
+ the brackets!) The text should be enclosed in the appropriate
184
+ comment syntax for the file format. We also recommend that a
185
+ file or class name and description of purpose be included on the
186
+ same "printed page" as the copyright notice for easier
187
+ identification within third-party archives.
188
+
189
+ Copyright [yyyy] [name of copyright owner]
190
+
191
+ Licensed under the Apache License, Version 2.0 (the "License");
192
+ you may not use this file except in compliance with the License.
193
+ You may obtain a copy of the License at
194
+
195
+ http://www.apache.org/licenses/LICENSE-2.0
196
+
197
+ Unless required by applicable law or agreed to in writing, software
198
+ distributed under the License is distributed on an "AS IS" BASIS,
199
+ WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
200
+ See the License for the specific language governing permissions and
201
+ limitations under the License.
package/README.md CHANGED
@@ -1,74 +1,57 @@
1
- # @agent-infra/browser
2
-
3
- A tiny Browser Control library based on [puppeteer](https://github.com/puppeteer/puppeteer), built for **Agent Tars**.
4
-
5
- <p>
6
- <a href="https://npmjs.com/package/@agent-infra/browser?activeTab=readme"><img src="https://img.shields.io/npm/v/@agent-infra/browser?style=flat-square&colorA=564341&colorB=EDED91" alt="npm version" /></a>
7
- <a href="https://npmcharts.com/compare/@agent-infra/browser?minimal=true"><img src="https://img.shields.io/npm/dm/@agent-infra/browser.svg?style=flat-square&colorA=564341&colorB=EDED91" alt="downloads" /></a>
8
- <a href="https://nodejs.org/en/about/previous-releases"><img src="https://img.shields.io/node/v/@agent-infra/browser.svg?style=flat-square&colorA=564341&colorB=EDED91" alt="node version"></a>
9
- <a href="https://github.com/bytedance/UI-TARS-desktop/blob/main/LICENSE"><img src="https://img.shields.io/badge/License-Apache%202.0-blue.svg?style=flat-square&colorA=564341&colorB=EDED91" alt="license" /></a>
10
- </p>
11
-
12
- ## Features
1
+ <div align="right">
2
+ <a href="README.zh-CN.md">简体中文</a> | <b>English</b>
3
+ </div>
13
4
 
14
- - 🔍 **Browser Detection** - Auto-detects installed browsers across platforms
15
- - 🔄 **Remote Browser Support** - Connect to remote browser instances
16
- - 🛡️ **Type Safety** - Written in TypeScript with full type definitions
17
-
18
- ## Architecture
5
+ # @agent-infra/browser
19
6
 
20
- ```mermaid
21
- graph TD
22
- A[Browser Interface] --> B[Local Browser]
23
- A --> C[Remote Browser]
24
- B --> D[Browser Finder]
25
- B --> E[Browser Adapter]
26
- C --> E
27
- E --> F[Puppeteer Adapter]
28
- F --> G[Browser Control]
29
- ```
7
+ **@agent-infra/browser** is an SDK based on **puppeteer** specifically designed to provide foundational functionality for browser agents. It provides high-level abstractions for tab management, dialog handling, hotkey support, and more while maintaining simple and intuitive APIs.
30
8
 
31
9
  ## Installation
32
10
 
33
11
  ```bash
34
12
  npm install @agent-infra/browser
35
- # or
36
- yarn add @agent-infra/browser
37
- # or
38
- pnpm add @agent-infra/browser
39
13
  ```
40
14
 
41
15
  ## Quick Start
42
16
 
17
+ Here is a simple usage demo. Browser will find the Chrome or Edge browser installed on your computer, launch a controlled browser instance, and then execute some operations through CDP control.
18
+
43
19
  ```typescript
44
- import { LocalBrowser } from '@agent-infra/browser';
20
+ import { Browser } from '@agent-infra/browser';
21
+
22
+ // Create browser instance
23
+ const browser = await Browser.create();
45
24
 
46
- async function main() {
47
- // Initialize browser
48
- const browser = new LocalBrowser();
25
+ // Set User-Agent (optional)
26
+ browser.setUserAgent({
27
+ userAgent:
28
+ 'Mozilla/5.0 (Windows NT 10.0; Win64; x64) AppleWebKit/537.36 (KHTML, like Gecko) Chrome/120.0.0.0 Safari/537.36',
29
+ });
49
30
 
50
- try {
51
- // Launch browser
52
- await browser.launch({ headless: false });
31
+ // Get current active tab
32
+ const activeTab = browser.getActiveTab();
53
33
 
54
- // Create new page
55
- const page = await browser.createPage();
34
+ // Navigate to specified webpage
35
+ await activeTab.goto('https://example.com');
56
36
 
57
- // Navigate to URL
58
- await page.goto('https://example.com');
37
+ // Take screenshot
38
+ const screenshot = await activeTab.screenshot();
59
39
 
60
- // Take screenshot
61
- await page.screenshot({ path: 'example.png' });
62
- } finally {
63
- // Always close browser
64
- await browser.close();
65
- }
66
- }
40
+ // Close browser
41
+ await browser.close();
67
42
  ```
68
43
 
44
+ ## Complete Documentation
45
+
46
+ For detailed API documentation and advanced usage examples, please refer to our [complete documentation](../../docs/browser.md).
47
+
48
+ ## License
49
+
50
+ Apache License 2.0.
51
+
69
52
  ## Credits
70
53
 
71
- Thanks to:
54
+ Special thanks to the open source projects that inspired this toolkit:
72
55
 
73
- - [EGOIST](https://github.com/egoist) for creating a great AI chatbot product [ChatWise](https://chatwise.app/) from which we draw a lot of inspiration for browser detection functionality.
74
- - The [puppeteer](https://github.com/puppeteer/puppeteer) project which helps us operate the browser better.
56
+ - [puppeteer](https://github.com/puppeteer/puppeteer) - The underlying browser automation library
57
+ - [Chrome DevTools Protocol](https://chromedevtools.github.io/devtools-protocol/) - Chrome DevTools Protocol
@@ -0,0 +1,57 @@
1
+ <div align="right">
2
+ <b>简体中文</b> | <a href="README.md">English</a>
3
+ </div>
4
+
5
+ # @agent-infra/browser
6
+
7
+ **@agent-infra/browser** 是一个基于 **puppeteer** 的 SDK,专门设计用于为浏览器代理提供基础功能。它提供了标签页管理、对话框处理、热键支持等方面的高级抽象,同时保持了简单直观的 API。
8
+
9
+ ## 安装
10
+
11
+ ```bash
12
+ npm install @agent-infra/browser
13
+ ```
14
+
15
+ ## 快速开始
16
+
17
+ 这是一个简单的使用示例。Browser 会找到您计算机上安装的 Chrome 或 Edge 浏览器,启动一个受控的浏览器实例,然后通过 CDP 控制执行一些操作。
18
+
19
+ ```typescript
20
+ import { Browser } from '@agent-infra/browser';
21
+
22
+ // 创建浏览器实例
23
+ const browser = await Browser.create();
24
+
25
+ // 设置 User-Agent(可选)
26
+ browser.setUserAgent({
27
+ userAgent:
28
+ 'Mozilla/5.0 (Windows NT 10.0; Win64; x64) AppleWebKit/537.36 (KHTML, like Gecko) Chrome/120.0.0.0 Safari/537.36',
29
+ });
30
+
31
+ // 获取当前活动标签页
32
+ const activeTab = browser.getActiveTab();
33
+
34
+ // 导航到指定网页
35
+ await activeTab.goto('https://example.com');
36
+
37
+ // 截图
38
+ const screenshot = await activeTab.screenshot();
39
+
40
+ // 关闭浏览器
41
+ await browser.close();
42
+ ```
43
+
44
+ ## 完整文档
45
+
46
+ 有关详细的 API 文档和高级使用示例,请参考我们的[完整文档](../../docs/browser.zh-CN.md)。
47
+
48
+ ## 许可证
49
+
50
+ Apache License 2.0。
51
+
52
+ ## 致谢
53
+
54
+ 特别感谢启发此工具包的开源项目:
55
+
56
+ - [puppeteer](https://github.com/puppeteer/puppeteer) - 底层浏览器自动化库
57
+ - [Chrome DevTools Protocol](https://chromedevtools.github.io/devtools-protocol/) - Chrome 开发者工具协议
@@ -0,0 +1,3 @@
1
+ export { Keyboard } from './keyboard';
2
+ export { Mouse } from './mouse';
3
+ //# sourceMappingURL=index.d.ts.map
@@ -0,0 +1 @@
1
+ {"version":3,"file":"index.d.ts","sourceRoot":"","sources":["../../src/actions/index.ts"],"names":[],"mappings":"AAKA,OAAO,EAAE,QAAQ,EAAE,MAAM,YAAY,CAAC;AACtC,OAAO,EAAE,KAAK,EAAE,MAAM,SAAS,CAAC"}
@@ -0,0 +1,46 @@
1
+ /**
2
+ * Copyright (c) 2025 Bytedance, Inc. and its affiliates.
3
+ * SPDX-License-Identifier: Apache-2.0
4
+ */
5
+ "use strict";
6
+ var __webpack_require__ = {};
7
+ (()=>{
8
+ __webpack_require__.d = (exports1, definition)=>{
9
+ for(var key in definition)if (__webpack_require__.o(definition, key) && !__webpack_require__.o(exports1, key)) Object.defineProperty(exports1, key, {
10
+ enumerable: true,
11
+ get: definition[key]
12
+ });
13
+ };
14
+ })();
15
+ (()=>{
16
+ __webpack_require__.o = (obj, prop)=>Object.prototype.hasOwnProperty.call(obj, prop);
17
+ })();
18
+ (()=>{
19
+ __webpack_require__.r = (exports1)=>{
20
+ if ('undefined' != typeof Symbol && Symbol.toStringTag) Object.defineProperty(exports1, Symbol.toStringTag, {
21
+ value: 'Module'
22
+ });
23
+ Object.defineProperty(exports1, '__esModule', {
24
+ value: true
25
+ });
26
+ };
27
+ })();
28
+ var __webpack_exports__ = {};
29
+ __webpack_require__.r(__webpack_exports__);
30
+ __webpack_require__.d(__webpack_exports__, {
31
+ Mouse: ()=>external_mouse_js_namespaceObject.Mouse,
32
+ Keyboard: ()=>external_keyboard_js_namespaceObject.Keyboard
33
+ });
34
+ const external_keyboard_js_namespaceObject = require("./keyboard.js");
35
+ const external_mouse_js_namespaceObject = require("./mouse.js");
36
+ exports.Keyboard = __webpack_exports__.Keyboard;
37
+ exports.Mouse = __webpack_exports__.Mouse;
38
+ for(var __webpack_i__ in __webpack_exports__)if (-1 === [
39
+ "Keyboard",
40
+ "Mouse"
41
+ ].indexOf(__webpack_i__)) exports[__webpack_i__] = __webpack_exports__[__webpack_i__];
42
+ Object.defineProperty(exports, '__esModule', {
43
+ value: true
44
+ });
45
+
46
+ //# sourceMappingURL=index.js.map
@@ -0,0 +1 @@
1
+ {"version":3,"file":"actions/index.js","sources":["webpack://@agent-infra/browser/webpack/runtime/define_property_getters","webpack://@agent-infra/browser/webpack/runtime/has_own_property","webpack://@agent-infra/browser/webpack/runtime/make_namespace_object"],"sourcesContent":["__webpack_require__.d = (exports, definition) => {\n\tfor(var key in definition) {\n if(__webpack_require__.o(definition, key) && !__webpack_require__.o(exports, key)) {\n Object.defineProperty(exports, key, { enumerable: true, get: definition[key] });\n }\n }\n};","__webpack_require__.o = (obj, prop) => (Object.prototype.hasOwnProperty.call(obj, prop))","// define __esModule on exports\n__webpack_require__.r = (exports) => {\n\tif(typeof Symbol !== 'undefined' && Symbol.toStringTag) {\n\t\tObject.defineProperty(exports, Symbol.toStringTag, { value: 'Module' });\n\t}\n\tObject.defineProperty(exports, '__esModule', { value: true });\n};"],"names":["__webpack_require__","definition","key","Object","obj","prop","Symbol"],"mappings":";;;;;;;IAAAA,oBAAoB,CAAC,GAAG,CAAC,UAASC;QACjC,IAAI,IAAIC,OAAOD,WACR,IAAGD,oBAAoB,CAAC,CAACC,YAAYC,QAAQ,CAACF,oBAAoB,CAAC,CAAC,UAASE,MACzEC,OAAO,cAAc,CAAC,UAASD,KAAK;YAAE,YAAY;YAAM,KAAKD,UAAU,CAACC,IAAI;QAAC;IAGzF;;;ICNAF,oBAAoB,CAAC,GAAG,CAACI,KAAKC,OAAUF,OAAO,SAAS,CAAC,cAAc,CAAC,IAAI,CAACC,KAAKC;;;ICClFL,oBAAoB,CAAC,GAAG,CAAC;QACxB,IAAG,AAAkB,eAAlB,OAAOM,UAA0BA,OAAO,WAAW,EACrDH,OAAO,cAAc,CAAC,UAASG,OAAO,WAAW,EAAE;YAAE,OAAO;QAAS;QAEtEH,OAAO,cAAc,CAAC,UAAS,cAAc;YAAE,OAAO;QAAK;IAC5D"}
@@ -0,0 +1,7 @@
1
+ /**
2
+ * Copyright (c) 2025 Bytedance, Inc. and its affiliates.
3
+ * SPDX-License-Identifier: Apache-2.0
4
+ */
5
+ import { Keyboard } from "./keyboard.mjs";
6
+ import { Mouse } from "./mouse.mjs";
7
+ export { Keyboard, Mouse };
@@ -0,0 +1,28 @@
1
+ /**
2
+ * The following code is modified based on
3
+ * https://github.com/puppeteer/puppeteer/blob/main/packages/puppeteer-core/src/common/USKeyboardLayout.ts
4
+ *
5
+ * Copyright 2017 Google Inc.
6
+ * SPDX-License-Identifier: Apache-2.0
7
+ * https://github.com/puppeteer/puppeteer/blob/main/LICENSE
8
+ */
9
+ import type { KeyInput } from 'puppeteer-core';
10
+ /**
11
+ * Only adapt for common macOS system hotkeys
12
+ *
13
+ * See issues:
14
+ * - https://github.com/bytedance/UI-TARS-desktop/pull/560
15
+ *
16
+ * References:
17
+ * - Mac shortcuts list: https://support.apple.com/zh-cn/102650
18
+ * - Chrome: https://support.google.com/chrome/answer/157179
19
+ * - CDP: https://chromedevtools.github.io/devtools-protocol/tot/Input/#method-dispatchKeyEvent
20
+ * - Commands: https://source.chromium.org/chromium/chromium/src/+/main:third_party/blink/renderer/core/editing/commands/editor_command_names.h
21
+ */
22
+ export declare const MAC_SYSTEM_HOTKEY_MAP: Map<string, {
23
+ key: KeyInput;
24
+ commands: string;
25
+ }>;
26
+ export declare const KEY_ABBR_TO_STANDARD_MAP: Readonly<Record<string, KeyInput>>;
27
+ export declare const KEY_LOW_TO_STANDARD_MAP: Readonly<Record<string, KeyInput>>;
28
+ //# sourceMappingURL=key-map.d.ts.map
@@ -0,0 +1 @@
1
+ {"version":3,"file":"key-map.d.ts","sourceRoot":"","sources":["../../src/actions/key-map.ts"],"names":[],"mappings":"AAAA;;;;;;;GAOG;AACH,OAAO,KAAK,EAAE,QAAQ,EAAE,MAAM,gBAAgB,CAAC;AAE/C;;;;;;;;;;;GAWG;AACH,eAAO,MAAM,qBAAqB;SAEzB,QAAQ;cAAY,MAAM;EAuBjC,CAAC;AAEH,eAAO,MAAM,wBAAwB,EAAE,QAAQ,CAAC,MAAM,CAAC,MAAM,EAAE,QAAQ,CAAC,CAmBvE,CAAC;AAGF,eAAO,MAAM,uBAAuB,EAAE,QAAQ,CAAC,MAAM,CAAC,MAAM,EAAE,QAAQ,CAAC,CAsOtE,CAAC"}