@hanzo/browser-extension 1.7.2

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 (134) hide show
  1. package/.github/workflows/docs.yml +44 -0
  2. package/.github/workflows/release.yml +55 -0
  3. package/LICENSE +21 -0
  4. package/README.md +126 -0
  5. package/dist/browser-extension/README.md +43 -0
  6. package/dist/browser-extension/ai-worker.js +30 -0
  7. package/dist/browser-extension/background-firefox.js +617 -0
  8. package/dist/browser-extension/background.js +2737 -0
  9. package/dist/browser-extension/browser-control.js +683 -0
  10. package/dist/browser-extension/cdp-bridge-server.js +444 -0
  11. package/dist/browser-extension/chrome/ai-worker.js +571 -0
  12. package/dist/browser-extension/chrome/background.js +2737 -0
  13. package/dist/browser-extension/chrome/callback.html +17 -0
  14. package/dist/browser-extension/chrome/content-script.js +1270 -0
  15. package/dist/browser-extension/chrome/icon128.png +0 -0
  16. package/dist/browser-extension/chrome/icon16.png +0 -0
  17. package/dist/browser-extension/chrome/icon32.png +0 -0
  18. package/dist/browser-extension/chrome/icon48.png +0 -0
  19. package/dist/browser-extension/chrome/manifest.json +57 -0
  20. package/dist/browser-extension/chrome/popup.css +519 -0
  21. package/dist/browser-extension/chrome/popup.html +242 -0
  22. package/dist/browser-extension/chrome/popup.js +267 -0
  23. package/dist/browser-extension/chrome/sidebar.css +1176 -0
  24. package/dist/browser-extension/chrome/sidebar.html +280 -0
  25. package/dist/browser-extension/chrome/sidebar.js +778 -0
  26. package/dist/browser-extension/cli.js +233 -0
  27. package/dist/browser-extension/content-script.js +1270 -0
  28. package/dist/browser-extension/firefox/ai-worker.js +571 -0
  29. package/dist/browser-extension/firefox/background.js +617 -0
  30. package/dist/browser-extension/firefox/callback.html +17 -0
  31. package/dist/browser-extension/firefox/content-script.js +1270 -0
  32. package/dist/browser-extension/firefox/icon128.png +0 -0
  33. package/dist/browser-extension/firefox/icon16.png +0 -0
  34. package/dist/browser-extension/firefox/icon32.png +0 -0
  35. package/dist/browser-extension/firefox/icon48.png +0 -0
  36. package/dist/browser-extension/firefox/manifest.json +66 -0
  37. package/dist/browser-extension/firefox/popup.css +519 -0
  38. package/dist/browser-extension/firefox/popup.html +242 -0
  39. package/dist/browser-extension/firefox/popup.js +267 -0
  40. package/dist/browser-extension/firefox/sidebar.css +1176 -0
  41. package/dist/browser-extension/firefox/sidebar.html +280 -0
  42. package/dist/browser-extension/firefox/sidebar.js +778 -0
  43. package/dist/browser-extension/hanzo-browser-extension-firefox-1.1.0.zip +0 -0
  44. package/dist/browser-extension/icon128.png +0 -0
  45. package/dist/browser-extension/icon16.png +0 -0
  46. package/dist/browser-extension/icon32.png +0 -0
  47. package/dist/browser-extension/icon48.png +0 -0
  48. package/dist/browser-extension/manifest.json +57 -0
  49. package/dist/browser-extension/package.json +41 -0
  50. package/dist/browser-extension/popup.css +468 -0
  51. package/dist/browser-extension/popup.html +191 -0
  52. package/dist/browser-extension/popup.js +267 -0
  53. package/dist/browser-extension/safari/Info.plist +21 -0
  54. package/dist/browser-extension/safari/ai-worker.js +571 -0
  55. package/dist/browser-extension/safari/background.js +2737 -0
  56. package/dist/browser-extension/safari/callback.html +17 -0
  57. package/dist/browser-extension/safari/content-script.js +1270 -0
  58. package/dist/browser-extension/safari/icon128.png +0 -0
  59. package/dist/browser-extension/safari/icon16.png +0 -0
  60. package/dist/browser-extension/safari/icon32.png +0 -0
  61. package/dist/browser-extension/safari/icon48.png +0 -0
  62. package/dist/browser-extension/safari/popup.css +519 -0
  63. package/dist/browser-extension/safari/popup.html +242 -0
  64. package/dist/browser-extension/safari/popup.js +267 -0
  65. package/dist/browser-extension/safari/sidebar.css +1176 -0
  66. package/dist/browser-extension/safari/sidebar.html +280 -0
  67. package/dist/browser-extension/safari/sidebar.js +778 -0
  68. package/dist/browser-extension/sidebar.css +718 -0
  69. package/dist/browser-extension/sidebar.html +184 -0
  70. package/dist/browser-extension/sidebar.js +778 -0
  71. package/dist/browser-extension/webgpu-ai.js +495 -0
  72. package/dist/cdp-bridge-server.js +411 -0
  73. package/dist/safari/Hanzo AI/Hanzo AI.xcodeproj/project.pbxproj +1047 -0
  74. package/dist/safari/Hanzo AI/Hanzo AI.xcodeproj/project.xcworkspace/contents.xcworkspacedata +7 -0
  75. package/dist/safari/Hanzo AI/Shared (App)/Assets.xcassets/AccentColor.colorset/Contents.json +11 -0
  76. package/dist/safari/Hanzo AI/Shared (App)/Assets.xcassets/AppIcon.appiconset/Contents.json +98 -0
  77. package/dist/safari/Hanzo AI/Shared (App)/Assets.xcassets/AppIcon.appiconset/mac-icon-128@1x.png +0 -0
  78. package/dist/safari/Hanzo AI/Shared (App)/Assets.xcassets/AppIcon.appiconset/mac-icon-128@2x.png +0 -0
  79. package/dist/safari/Hanzo AI/Shared (App)/Assets.xcassets/AppIcon.appiconset/mac-icon-16@1x.png +0 -0
  80. package/dist/safari/Hanzo AI/Shared (App)/Assets.xcassets/AppIcon.appiconset/mac-icon-16@2x.png +0 -0
  81. package/dist/safari/Hanzo AI/Shared (App)/Assets.xcassets/AppIcon.appiconset/mac-icon-256@1x.png +0 -0
  82. package/dist/safari/Hanzo AI/Shared (App)/Assets.xcassets/AppIcon.appiconset/mac-icon-256@2x.png +0 -0
  83. package/dist/safari/Hanzo AI/Shared (App)/Assets.xcassets/AppIcon.appiconset/mac-icon-32@1x.png +0 -0
  84. package/dist/safari/Hanzo AI/Shared (App)/Assets.xcassets/AppIcon.appiconset/mac-icon-32@2x.png +0 -0
  85. package/dist/safari/Hanzo AI/Shared (App)/Assets.xcassets/AppIcon.appiconset/mac-icon-512@1x.png +0 -0
  86. package/dist/safari/Hanzo AI/Shared (App)/Assets.xcassets/AppIcon.appiconset/mac-icon-512@2x.png +0 -0
  87. package/dist/safari/Hanzo AI/Shared (App)/Assets.xcassets/AppIcon.appiconset/universal-icon-1024@1x.png +0 -0
  88. package/dist/safari/Hanzo AI/Shared (App)/Assets.xcassets/Contents.json +6 -0
  89. package/dist/safari/Hanzo AI/Shared (App)/Assets.xcassets/LargeIcon.imageset/Contents.json +21 -0
  90. package/dist/safari/Hanzo AI/Shared (App)/Assets.xcassets/LargeIcon.imageset/icon128.png +0 -0
  91. package/dist/safari/Hanzo AI/Shared (App)/Resources/Base.lproj/Main.html +20 -0
  92. package/dist/safari/Hanzo AI/Shared (App)/Resources/Icon.png +0 -0
  93. package/dist/safari/Hanzo AI/Shared (App)/Resources/Script.js +24 -0
  94. package/dist/safari/Hanzo AI/Shared (App)/Resources/Style.css +61 -0
  95. package/dist/safari/Hanzo AI/Shared (App)/ViewController.swift +81 -0
  96. package/dist/safari/Hanzo AI/Shared (Extension)/SafariWebExtensionHandler.swift +42 -0
  97. package/dist/safari/Hanzo AI/iOS (App)/AppDelegate.swift +24 -0
  98. package/dist/safari/Hanzo AI/iOS (App)/Base.lproj/LaunchScreen.storyboard +36 -0
  99. package/dist/safari/Hanzo AI/iOS (App)/Base.lproj/Main.storyboard +38 -0
  100. package/dist/safari/Hanzo AI/iOS (App)/Info.plist +27 -0
  101. package/dist/safari/Hanzo AI/iOS (App)/SceneDelegate.swift +18 -0
  102. package/dist/safari/Hanzo AI/iOS (Extension)/Info.plist +13 -0
  103. package/dist/safari/Hanzo AI/macOS (App)/AppDelegate.swift +21 -0
  104. package/dist/safari/Hanzo AI/macOS (App)/Base.lproj/Main.storyboard +124 -0
  105. package/dist/safari/Hanzo AI/macOS (App)/Info.plist +8 -0
  106. package/dist/safari/Hanzo AI/macOS (Extension)/Info.plist +13 -0
  107. package/docs/_config.yml +13 -0
  108. package/docs/_layouts/default.html +435 -0
  109. package/docs/index.md +54 -0
  110. package/install-extension.sh +75 -0
  111. package/manifest.json +29 -0
  112. package/package.json +32 -0
  113. package/src/ai-worker.js +571 -0
  114. package/src/callback.html +17 -0
  115. package/src/chat-widget.tsx +93 -0
  116. package/src/icon128.png +0 -0
  117. package/src/icon16.png +0 -0
  118. package/src/icon32.png +0 -0
  119. package/src/icon48.png +0 -0
  120. package/src/manifest-firefox.json +66 -0
  121. package/src/manifest.json +57 -0
  122. package/src/package.json +41 -0
  123. package/src/popup.css +519 -0
  124. package/src/popup.html +242 -0
  125. package/src/popup.js +192 -0
  126. package/src/sidebar.css +1176 -0
  127. package/src/sidebar.html +280 -0
  128. package/src/sidebar.js +884 -0
  129. package/src/webgpu.d.ts +131 -0
  130. package/test/claude-integration.test.ts +251 -0
  131. package/test/server-frameworks-edge-cases.test.ts +145 -0
  132. package/test/server-frameworks.test.ts +395 -0
  133. package/test-cdp-connection.js +140 -0
  134. package/tsconfig.json +19 -0
@@ -0,0 +1,444 @@
1
+ #!/usr/bin/env node
2
+ "use strict";
3
+ var __create = Object.create;
4
+ var __defProp = Object.defineProperty;
5
+ var __getOwnPropDesc = Object.getOwnPropertyDescriptor;
6
+ var __getOwnPropNames = Object.getOwnPropertyNames;
7
+ var __getProtoOf = Object.getPrototypeOf;
8
+ var __hasOwnProp = Object.prototype.hasOwnProperty;
9
+ var __export = (target, all) => {
10
+ for (var name in all)
11
+ __defProp(target, name, { get: all[name], enumerable: true });
12
+ };
13
+ var __copyProps = (to, from, except, desc) => {
14
+ if (from && typeof from === "object" || typeof from === "function") {
15
+ for (let key of __getOwnPropNames(from))
16
+ if (!__hasOwnProp.call(to, key) && key !== except)
17
+ __defProp(to, key, { get: () => from[key], enumerable: !(desc = __getOwnPropDesc(from, key)) || desc.enumerable });
18
+ }
19
+ return to;
20
+ };
21
+ var __toESM = (mod, isNodeMode, target) => (target = mod != null ? __create(__getProtoOf(mod)) : {}, __copyProps(
22
+ // If the importer is in node compatibility mode or this is not an ESM
23
+ // file that has been converted to a CommonJS file using a Babel-
24
+ // compatible transform (i.e. "__esModule" has not been set), then set
25
+ // "default" to the CommonJS "module.exports" for node compatibility.
26
+ isNodeMode || !mod || !mod.__esModule ? __defProp(target, "default", { value: mod, enumerable: true }) : target,
27
+ mod
28
+ ));
29
+ var __toCommonJS = (mod) => __copyProps(__defProp({}, "__esModule", { value: true }), mod);
30
+
31
+ // src/cdp-bridge-server.ts
32
+ var cdp_bridge_server_exports = {};
33
+ __export(cdp_bridge_server_exports, {
34
+ CDPBridgeServer: () => CDPBridgeServer
35
+ });
36
+ module.exports = __toCommonJS(cdp_bridge_server_exports);
37
+ var import_ws = require("ws");
38
+ var readline = __toESM(require("readline"));
39
+ var fs = __toESM(require("fs"));
40
+ var path = __toESM(require("path"));
41
+ var CDPBridgeServer = class {
42
+ constructor(port = 9223) {
43
+ this.clients = /* @__PURE__ */ new Map();
44
+ this.pendingCommands = /* @__PURE__ */ new Map();
45
+ this.commandId = 0;
46
+ this.httpPort = port;
47
+ this.wss = new import_ws.WebSocketServer({ port, path: "/cdp" });
48
+ this.wss.on("connection", (ws) => {
49
+ console.log("[hanzo.browser] Extension connected");
50
+ ws.on("message", (data) => {
51
+ try {
52
+ const message = JSON.parse(data.toString());
53
+ this.handleMessage(ws, message);
54
+ } catch (error) {
55
+ console.error("[hanzo.browser] Error:", error.message);
56
+ }
57
+ });
58
+ ws.on("close", () => {
59
+ console.log("[hanzo.browser] Extension disconnected");
60
+ this.clients.delete(ws);
61
+ });
62
+ ws.on("error", (error) => {
63
+ console.error("[hanzo.browser] WebSocket error:", error);
64
+ });
65
+ });
66
+ console.log(`[hanzo.browser] Server listening on ws://localhost:${port}/cdp`);
67
+ }
68
+ handleMessage(ws, message) {
69
+ var _a;
70
+ if (message.type === "register") {
71
+ this.clients.set(ws, {
72
+ ws,
73
+ capabilities: message.capabilities || [],
74
+ browser: message.browser || "unknown"
75
+ });
76
+ console.log(`[hanzo.browser] Registered ${message.browser || "unknown"}:`, (_a = message.capabilities) == null ? void 0 : _a.join(", "));
77
+ return;
78
+ }
79
+ if (message.type === "config") {
80
+ this.saveConfig(message.key, message.value);
81
+ return;
82
+ }
83
+ if (message.id !== void 0) {
84
+ const pending = this.pendingCommands.get(message.id);
85
+ if (pending) {
86
+ if (message.error) {
87
+ pending.reject(new Error(message.error.message));
88
+ } else {
89
+ pending.resolve(message.result);
90
+ }
91
+ this.pendingCommands.delete(message.id);
92
+ }
93
+ return;
94
+ }
95
+ if (message.type === "event") {
96
+ console.log(`[hanzo.browser] Event: ${message.method}`);
97
+ }
98
+ }
99
+ /** Save a config value to ~/.hanzo/extension/config.json */
100
+ saveConfig(key, value) {
101
+ const configDir = path.join(
102
+ process.env.HOME || process.env.USERPROFILE || ".",
103
+ ".hanzo",
104
+ "extension"
105
+ );
106
+ const configPath = path.join(configDir, "config.json");
107
+ try {
108
+ fs.mkdirSync(configDir, { recursive: true });
109
+ let config = {};
110
+ if (fs.existsSync(configPath)) {
111
+ config = JSON.parse(fs.readFileSync(configPath, "utf-8"));
112
+ }
113
+ config[key] = value;
114
+ fs.writeFileSync(configPath, JSON.stringify(config, null, 2) + "\n");
115
+ console.log(`[hanzo.browser] Config saved: ${key} = ${JSON.stringify(value)}`);
116
+ } catch (error) {
117
+ console.error(`[hanzo.browser] Failed to save config: ${error.message}`);
118
+ }
119
+ }
120
+ /** Get connected browser names */
121
+ getConnectedBrowsers() {
122
+ return Array.from(this.clients.values()).map((c) => c.browser || "unknown").filter((b) => b !== "unknown");
123
+ }
124
+ async sendRaw(method, params) {
125
+ const client = Array.from(this.clients.values())[0];
126
+ if (!client) {
127
+ throw new Error("No browser extension connected");
128
+ }
129
+ const id = ++this.commandId;
130
+ return new Promise((resolve, reject) => {
131
+ this.pendingCommands.set(id, { resolve, reject });
132
+ client.ws.send(JSON.stringify({ id, method, params }));
133
+ setTimeout(() => {
134
+ if (this.pendingCommands.has(id)) {
135
+ this.pendingCommands.delete(id);
136
+ reject(new Error("Command timeout"));
137
+ }
138
+ }, 3e4);
139
+ });
140
+ }
141
+ /**
142
+ * Unified hanzo.browser interface - matches mcp__hanzo__browser pattern
143
+ */
144
+ async browser(params) {
145
+ const { action, ...rest } = params;
146
+ switch (action) {
147
+ // Navigation
148
+ case "navigate":
149
+ return this.sendRaw("Page.navigate", { url: rest.url });
150
+ case "navigate_back":
151
+ case "go_back":
152
+ return this.sendRaw("Page.goBack");
153
+ case "navigate_forward":
154
+ case "go_forward":
155
+ return this.sendRaw("Page.goForward");
156
+ case "reload":
157
+ return this.sendRaw("Page.reload");
158
+ case "url":
159
+ return this.sendRaw("hanzo.url");
160
+ case "title":
161
+ return this.sendRaw("hanzo.title");
162
+ case "tab_info":
163
+ return this.sendRaw("hanzo.tabInfo");
164
+ case "content":
165
+ return this.sendRaw("Runtime.evaluate", {
166
+ expression: "document.documentElement.outerHTML",
167
+ returnByValue: true
168
+ });
169
+ // Screenshots
170
+ case "screenshot":
171
+ const screenshot = await this.sendRaw("hanzo.screenshot", {
172
+ format: rest.format || "png",
173
+ fullPage: rest.fullPage
174
+ });
175
+ if (rest.filename && screenshot.data) {
176
+ const buffer = Buffer.from(screenshot.data, "base64");
177
+ fs.writeFileSync(rest.filename, buffer);
178
+ return { saved: rest.filename, bytes: buffer.length };
179
+ }
180
+ return screenshot;
181
+ case "snapshot":
182
+ return this.sendRaw("Accessibility.getFullAXTree");
183
+ // Input - Click
184
+ case "click":
185
+ return this.sendRaw("hanzo.click", {
186
+ selector: rest.selector || rest.ref
187
+ });
188
+ case "dblclick":
189
+ case "double_click":
190
+ return this.sendRaw("hanzo.dblclick", {
191
+ selector: rest.selector || rest.ref
192
+ });
193
+ case "hover":
194
+ return this.sendRaw("hanzo.hover", {
195
+ selector: rest.selector || rest.ref
196
+ });
197
+ // Input - Type
198
+ case "type":
199
+ return this.sendRaw("hanzo.type", {
200
+ selector: rest.selector || rest.ref,
201
+ text: rest.text
202
+ });
203
+ case "fill":
204
+ return this.sendRaw("hanzo.fill", {
205
+ selector: rest.selector || rest.ref,
206
+ value: rest.value || rest.text
207
+ });
208
+ case "clear":
209
+ return this.sendRaw("hanzo.clear", {
210
+ selector: rest.selector || rest.ref
211
+ });
212
+ case "press_key":
213
+ case "press":
214
+ return this.sendRaw("Input.dispatchKeyEvent", {
215
+ type: "keyDown",
216
+ key: rest.key
217
+ });
218
+ // Forms
219
+ case "select_option":
220
+ return this.sendRaw("hanzo.select", {
221
+ selector: rest.selector || rest.ref,
222
+ value: rest.value
223
+ });
224
+ case "check":
225
+ return this.sendRaw("hanzo.check", {
226
+ selector: rest.selector || rest.ref
227
+ });
228
+ case "uncheck":
229
+ return this.sendRaw("hanzo.uncheck", {
230
+ selector: rest.selector || rest.ref
231
+ });
232
+ // Evaluate
233
+ case "evaluate":
234
+ return this.sendRaw("Runtime.evaluate", {
235
+ expression: rest.code || rest.function || rest.expression,
236
+ returnByValue: true
237
+ });
238
+ // Wait
239
+ case "wait":
240
+ await new Promise((resolve) => setTimeout(resolve, (rest.timeout || 1) * 1e3));
241
+ return { waited: rest.timeout || 1 };
242
+ case "wait_for_load":
243
+ return this.sendRaw("Page.waitForLoadState", {
244
+ state: rest.state || "load"
245
+ });
246
+ // Tabs
247
+ case "tabs":
248
+ case "list_tabs":
249
+ return this.sendRaw("Target.getTargets");
250
+ case "new_tab":
251
+ return this.sendRaw("Target.createTarget", { url: rest.url || "about:blank" });
252
+ case "close_tab":
253
+ return this.sendRaw("Target.closeTarget", { targetId: rest.tabId });
254
+ case "select_tab":
255
+ return this.sendRaw("Target.activateTarget", { targetId: rest.tabId });
256
+ // Console/Network
257
+ case "console_messages":
258
+ case "console":
259
+ return this.sendRaw("Console.getMessages");
260
+ case "network_requests":
261
+ return this.sendRaw("Network.getResponseBodies");
262
+ // Status
263
+ case "status":
264
+ return {
265
+ connected: this.clients.size > 0,
266
+ clients: this.clients.size,
267
+ port: this.httpPort
268
+ };
269
+ default:
270
+ return this.sendRaw(action, rest);
271
+ }
272
+ }
273
+ isConnected() {
274
+ return this.clients.size > 0;
275
+ }
276
+ close() {
277
+ this.wss.close();
278
+ }
279
+ };
280
+ async function startJSONRPCServer(bridgeServer) {
281
+ const http = require("http");
282
+ const httpServer = http.createServer(async (req, res) => {
283
+ if (req.method === "POST") {
284
+ let body = "";
285
+ req.on("data", (chunk) => body += chunk);
286
+ req.on("end", async () => {
287
+ try {
288
+ const request = JSON.parse(body);
289
+ const result = await bridgeServer.browser(request.params || request);
290
+ res.writeHead(200, { "Content-Type": "application/json" });
291
+ res.end(JSON.stringify({ result }));
292
+ } catch (error) {
293
+ res.writeHead(500, { "Content-Type": "application/json" });
294
+ res.end(JSON.stringify({ error: error.message }));
295
+ }
296
+ });
297
+ } else {
298
+ res.writeHead(200, { "Content-Type": "application/json" });
299
+ res.end(JSON.stringify({
300
+ service: "hanzo.browser",
301
+ connected: bridgeServer.isConnected(),
302
+ browsers: bridgeServer.getConnectedBrowsers(),
303
+ actions: [
304
+ "navigate",
305
+ "navigate_back",
306
+ "reload",
307
+ "url",
308
+ "title",
309
+ "content",
310
+ "screenshot",
311
+ "snapshot",
312
+ "click",
313
+ "dblclick",
314
+ "hover",
315
+ "type",
316
+ "fill",
317
+ "clear",
318
+ "press_key",
319
+ "select_option",
320
+ "check",
321
+ "uncheck",
322
+ "evaluate",
323
+ "wait",
324
+ "wait_for_load",
325
+ "tabs",
326
+ "new_tab",
327
+ "close_tab",
328
+ "select_tab",
329
+ "console",
330
+ "network_requests",
331
+ "takeover.start",
332
+ "takeover.end",
333
+ "takeover.cursor",
334
+ "status"
335
+ ]
336
+ }));
337
+ }
338
+ });
339
+ httpServer.listen(9224, () => {
340
+ console.log("[hanzo.browser] HTTP API at http://localhost:9224");
341
+ });
342
+ }
343
+ async function main() {
344
+ const port = parseInt(process.env.CDP_PORT || "9223");
345
+ const server = new CDPBridgeServer(port);
346
+ startJSONRPCServer(server);
347
+ console.log("\n[hanzo.browser] Commands:");
348
+ console.log(" navigate <url> - Go to URL");
349
+ console.log(" screenshot [file] - Capture screen");
350
+ console.log(" click <selector> - Click element");
351
+ console.log(" type <sel> <text> - Type into element");
352
+ console.log(" eval <js> - Run JavaScript");
353
+ console.log(" tabs - List all tabs");
354
+ console.log(" status - Connection status");
355
+ console.log(" quit - Exit\n");
356
+ const rl = readline.createInterface({
357
+ input: process.stdin,
358
+ output: process.stdout
359
+ });
360
+ const prompt = () => {
361
+ rl.question("hanzo.browser> ", async (line) => {
362
+ var _a, _b, _c, _d;
363
+ const parts = line.trim().split(" ");
364
+ const action = parts[0];
365
+ const args = parts.slice(1);
366
+ if (!action) {
367
+ prompt();
368
+ return;
369
+ }
370
+ try {
371
+ let result;
372
+ switch (action) {
373
+ case "quit":
374
+ case "exit":
375
+ server.close();
376
+ rl.close();
377
+ process.exit(0);
378
+ case "navigate":
379
+ result = await server.browser({ action: "navigate", url: args[0] });
380
+ console.log("Navigated to:", args[0]);
381
+ break;
382
+ case "screenshot":
383
+ result = await server.browser({
384
+ action: "screenshot",
385
+ filename: args[0] || `screenshot-${Date.now()}.png`
386
+ });
387
+ console.log("Screenshot:", result);
388
+ break;
389
+ case "click":
390
+ result = await server.browser({ action: "click", selector: args[0] });
391
+ console.log("Clicked:", args[0]);
392
+ break;
393
+ case "type":
394
+ result = await server.browser({
395
+ action: "type",
396
+ selector: args[0],
397
+ text: args.slice(1).join(" ")
398
+ });
399
+ console.log("Typed into:", args[0]);
400
+ break;
401
+ case "eval":
402
+ result = await server.browser({
403
+ action: "evaluate",
404
+ expression: args.join(" ")
405
+ });
406
+ console.log("Result:", (_a = result == null ? void 0 : result.result) == null ? void 0 : _a.value);
407
+ break;
408
+ case "tabs":
409
+ result = await server.browser({ action: "tabs" });
410
+ console.log("Tabs:", (_b = result == null ? void 0 : result.targetInfos) == null ? void 0 : _b.map((t) => t.title).join(", "));
411
+ break;
412
+ case "status":
413
+ result = await server.browser({ action: "status" });
414
+ console.log("Status:", result);
415
+ break;
416
+ case "url":
417
+ result = await server.browser({ action: "url" });
418
+ console.log("URL:", (_c = result == null ? void 0 : result.result) == null ? void 0 : _c.value);
419
+ break;
420
+ case "title":
421
+ result = await server.browser({ action: "title" });
422
+ console.log("Title:", (_d = result == null ? void 0 : result.result) == null ? void 0 : _d.value);
423
+ break;
424
+ default:
425
+ result = await server.browser({ action, ...Object.fromEntries(
426
+ args.map((a, i) => [i === 0 ? "selector" : `arg${i}`, a])
427
+ ) });
428
+ console.log("Result:", result);
429
+ }
430
+ } catch (error) {
431
+ console.error("Error:", error.message);
432
+ }
433
+ prompt();
434
+ });
435
+ };
436
+ prompt();
437
+ }
438
+ if (require.main === module) {
439
+ main();
440
+ }
441
+ // Annotate the CommonJS export names for ESM import in node:
442
+ 0 && (module.exports = {
443
+ CDPBridgeServer
444
+ });