@hanzo/browser-extension 1.7.5 → 1.9.31
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.
- package/LICENSE +9 -18
- package/dist/browser-extension/README.md +1 -1
- package/dist/browser-extension/background-firefox.js +4184 -491
- package/dist/browser-extension/background.js +6938 -2413
- package/dist/browser-extension/browser-control.js +652 -18
- package/dist/browser-extension/chrome/background.js +6938 -2413
- package/dist/browser-extension/chrome/content-script.js +1642 -123
- package/dist/browser-extension/chrome/icon128.png +0 -0
- package/dist/browser-extension/chrome/icon16.png +0 -0
- package/dist/browser-extension/chrome/icon48.png +0 -0
- package/dist/browser-extension/chrome/manifest.json +20 -11
- package/dist/browser-extension/chrome/popup.css +352 -110
- package/dist/browser-extension/chrome/popup.html +159 -48
- package/dist/browser-extension/chrome/popup.js +1418 -46
- package/dist/browser-extension/chrome/sidebar.css +772 -156
- package/dist/browser-extension/chrome/sidebar.html +268 -85
- package/dist/browser-extension/chrome/sidebar.js +25846 -84
- package/dist/browser-extension/cli.js +2 -2
- package/dist/browser-extension/content-script.js +1642 -123
- package/dist/browser-extension/firefox/background.js +4184 -491
- package/dist/browser-extension/firefox/content-script.js +1642 -123
- package/dist/browser-extension/firefox/icon128.png +0 -0
- package/dist/browser-extension/firefox/icon16.png +0 -0
- package/dist/browser-extension/firefox/icon48.png +0 -0
- package/dist/browser-extension/firefox/manifest.json +24 -13
- package/dist/browser-extension/firefox/popup.css +352 -110
- package/dist/browser-extension/firefox/popup.html +159 -48
- package/dist/browser-extension/firefox/popup.js +1418 -46
- package/dist/browser-extension/firefox/sidebar.css +772 -156
- package/dist/browser-extension/firefox/sidebar.html +268 -85
- package/dist/browser-extension/firefox/sidebar.js +25846 -84
- package/dist/browser-extension/icon128.png +0 -0
- package/dist/browser-extension/icon16.png +0 -0
- package/dist/browser-extension/icon48.png +0 -0
- package/dist/browser-extension/manifest.json +20 -11
- package/dist/browser-extension/package.json +1 -1
- package/dist/browser-extension/popup.js +1418 -46
- package/dist/browser-extension/safari/Info.plist +3 -3
- package/dist/browser-extension/safari/background.js +6938 -2413
- package/dist/browser-extension/safari/content-script.js +1642 -123
- package/dist/browser-extension/safari/icon128.png +0 -0
- package/dist/browser-extension/safari/icon16.png +0 -0
- package/dist/browser-extension/safari/icon48.png +0 -0
- package/dist/browser-extension/safari/popup.css +352 -110
- package/dist/browser-extension/safari/popup.html +159 -48
- package/dist/browser-extension/safari/popup.js +1418 -46
- package/dist/browser-extension/safari/sidebar.css +772 -156
- package/dist/browser-extension/safari/sidebar.html +268 -85
- package/dist/browser-extension/safari/sidebar.js +25846 -84
- package/dist/browser-extension/sidebar.js +25846 -84
- package/dist/browser-extension/webgpu-ai.js +78 -5
- package/images/icon128.png +0 -0
- package/images/icon16.png +0 -0
- package/images/icon48.png +0 -0
- package/manifest.json +7 -2
- package/package.json +27 -10
- package/src/chat-widget.tsx +96 -0
- package/src/gui-primitives.tsx +116 -0
- package/src/icon128.png +0 -0
- package/src/icon16.png +0 -0
- package/src/icon32.png +0 -0
- package/src/icon48.png +0 -0
- package/src/manifest-firefox.json +23 -12
- package/src/manifest.json +19 -10
- package/src/package.json +1 -1
- package/src/popup.css +352 -110
- package/src/popup.html +159 -48
- package/src/popup.js +196 -0
- package/src/sidebar.css +772 -156
- package/src/sidebar.html +268 -85
- package/src/sidebar.js +885 -0
- package/.github/workflows/docs.yml +0 -44
- package/.github/workflows/release.yml +0 -55
- package/README.md +0 -126
- package/dist/browser-extension/ai-worker.js +0 -30
- package/dist/browser-extension/cdp-bridge-server.js +0 -444
- package/dist/browser-extension/chrome/icon32.png +0 -0
- package/dist/browser-extension/firefox/icon32.png +0 -0
- package/dist/browser-extension/hanzo-browser-extension-firefox-1.1.0.zip +0 -0
- package/dist/browser-extension/icon32.png +0 -0
- package/dist/browser-extension/popup.css +0 -468
- package/dist/browser-extension/popup.html +0 -191
- package/dist/browser-extension/safari/icon32.png +0 -0
- package/dist/browser-extension/sidebar.css +0 -718
- package/dist/browser-extension/sidebar.html +0 -184
- package/dist/cdp-bridge-server.js +0 -411
- package/dist/hanzo-ai-chrome-1.7.2.zip +0 -0
- package/dist/hanzo-ai-chrome-1.7.3.zip +0 -0
- package/dist/hanzo-ai-firefox-1.7.2.zip +0 -0
- package/dist/hanzo-ai-firefox-1.7.3.zip +0 -0
- package/dist/safari/Hanzo AI/Hanzo AI.xcodeproj/project.pbxproj +0 -1047
- package/dist/safari/Hanzo AI/Hanzo AI.xcodeproj/project.xcworkspace/contents.xcworkspacedata +0 -7
- package/dist/safari/Hanzo AI/Shared (App)/Assets.xcassets/AccentColor.colorset/Contents.json +0 -11
- package/dist/safari/Hanzo AI/Shared (App)/Assets.xcassets/AppIcon.appiconset/Contents.json +0 -98
- package/dist/safari/Hanzo AI/Shared (App)/Assets.xcassets/AppIcon.appiconset/mac-icon-128@1x.png +0 -0
- package/dist/safari/Hanzo AI/Shared (App)/Assets.xcassets/AppIcon.appiconset/mac-icon-128@2x.png +0 -0
- package/dist/safari/Hanzo AI/Shared (App)/Assets.xcassets/AppIcon.appiconset/mac-icon-16@1x.png +0 -0
- package/dist/safari/Hanzo AI/Shared (App)/Assets.xcassets/AppIcon.appiconset/mac-icon-16@2x.png +0 -0
- package/dist/safari/Hanzo AI/Shared (App)/Assets.xcassets/AppIcon.appiconset/mac-icon-256@1x.png +0 -0
- package/dist/safari/Hanzo AI/Shared (App)/Assets.xcassets/AppIcon.appiconset/mac-icon-256@2x.png +0 -0
- package/dist/safari/Hanzo AI/Shared (App)/Assets.xcassets/AppIcon.appiconset/mac-icon-32@1x.png +0 -0
- package/dist/safari/Hanzo AI/Shared (App)/Assets.xcassets/AppIcon.appiconset/mac-icon-32@2x.png +0 -0
- package/dist/safari/Hanzo AI/Shared (App)/Assets.xcassets/AppIcon.appiconset/mac-icon-512@1x.png +0 -0
- package/dist/safari/Hanzo AI/Shared (App)/Assets.xcassets/AppIcon.appiconset/mac-icon-512@2x.png +0 -0
- package/dist/safari/Hanzo AI/Shared (App)/Assets.xcassets/AppIcon.appiconset/universal-icon-1024@1x.png +0 -0
- package/dist/safari/Hanzo AI/Shared (App)/Assets.xcassets/Contents.json +0 -6
- package/dist/safari/Hanzo AI/Shared (App)/Assets.xcassets/LargeIcon.imageset/Contents.json +0 -21
- package/dist/safari/Hanzo AI/Shared (App)/Assets.xcassets/LargeIcon.imageset/icon128.png +0 -0
- package/dist/safari/Hanzo AI/Shared (App)/Resources/Base.lproj/Main.html +0 -20
- package/dist/safari/Hanzo AI/Shared (App)/Resources/Icon.png +0 -0
- package/dist/safari/Hanzo AI/Shared (App)/Resources/Script.js +0 -24
- package/dist/safari/Hanzo AI/Shared (App)/Resources/Style.css +0 -61
- package/dist/safari/Hanzo AI/Shared (App)/ViewController.swift +0 -81
- package/dist/safari/Hanzo AI/Shared (Extension)/SafariWebExtensionHandler.swift +0 -42
- package/dist/safari/Hanzo AI/iOS (App)/AppDelegate.swift +0 -24
- package/dist/safari/Hanzo AI/iOS (App)/Base.lproj/LaunchScreen.storyboard +0 -36
- package/dist/safari/Hanzo AI/iOS (App)/Base.lproj/Main.storyboard +0 -38
- package/dist/safari/Hanzo AI/iOS (App)/Info.plist +0 -27
- package/dist/safari/Hanzo AI/iOS (App)/SceneDelegate.swift +0 -18
- package/dist/safari/Hanzo AI/iOS (Extension)/Info.plist +0 -13
- package/dist/safari/Hanzo AI/macOS (App)/AppDelegate.swift +0 -21
- package/dist/safari/Hanzo AI/macOS (App)/Base.lproj/Main.storyboard +0 -124
- package/dist/safari/Hanzo AI/macOS (App)/Info.plist +0 -8
- package/dist/safari/Hanzo AI/macOS (Extension)/Info.plist +0 -13
- package/docs/_config.yml +0 -13
- package/docs/_layouts/default.html +0 -435
- package/docs/index.md +0 -54
- package/install-extension.sh +0 -75
- package/test/claude-integration.test.ts +0 -251
- package/test/server-frameworks-edge-cases.test.ts +0 -145
- package/test/server-frameworks.test.ts +0 -395
- package/test-cdp-connection.js +0 -140
- package/tsconfig.json +0 -19
|
@@ -1,184 +0,0 @@
|
|
|
1
|
-
<!DOCTYPE html>
|
|
2
|
-
<html lang="en">
|
|
3
|
-
<head>
|
|
4
|
-
<meta charset="UTF-8">
|
|
5
|
-
<meta name="viewport" content="width=device-width, initial-scale=1.0">
|
|
6
|
-
<title>Hanzo AI</title>
|
|
7
|
-
<link rel="stylesheet" href="sidebar.css">
|
|
8
|
-
</head>
|
|
9
|
-
<body>
|
|
10
|
-
<div class="sidebar-container">
|
|
11
|
-
<!-- Header -->
|
|
12
|
-
<header class="sidebar-header">
|
|
13
|
-
<div class="brand">
|
|
14
|
-
<svg class="logo" viewBox="0 0 32 32" fill="none">
|
|
15
|
-
<path d="M16 2L2 9v7c0 8.5 5.5 16.5 14 18 8.5-1.5 14-9.5 14-18V9L16 2z" stroke="currentColor" stroke-width="2"/>
|
|
16
|
-
<path d="M16 8v8l6 4" stroke="currentColor" stroke-width="2" stroke-linecap="round"/>
|
|
17
|
-
</svg>
|
|
18
|
-
<span>Hanzo AI</span>
|
|
19
|
-
</div>
|
|
20
|
-
<div id="header-user" class="header-user hidden">
|
|
21
|
-
<img id="header-avatar" class="header-avatar" src="" alt="">
|
|
22
|
-
</div>
|
|
23
|
-
</header>
|
|
24
|
-
|
|
25
|
-
<!-- Auth Gate (shown when not logged in) -->
|
|
26
|
-
<section id="auth-gate" class="auth-gate">
|
|
27
|
-
<div class="auth-gate-inner">
|
|
28
|
-
<svg class="auth-logo" viewBox="0 0 32 32" fill="none">
|
|
29
|
-
<path d="M16 2L2 9v7c0 8.5 5.5 16.5 14 18 8.5-1.5 14-9.5 14-18V9L16 2z" stroke="currentColor" stroke-width="2"/>
|
|
30
|
-
<path d="M16 8v8l6 4" stroke="currentColor" stroke-width="2" stroke-linecap="round"/>
|
|
31
|
-
</svg>
|
|
32
|
-
<h2>Welcome to Hanzo AI</h2>
|
|
33
|
-
<p class="auth-subtitle">Sign in to start chatting</p>
|
|
34
|
-
<button id="auth-login-btn" class="primary-btn">Sign in with Hanzo</button>
|
|
35
|
-
</div>
|
|
36
|
-
</section>
|
|
37
|
-
|
|
38
|
-
<!-- Tab Bar -->
|
|
39
|
-
<nav id="tab-bar" class="tab-bar hidden">
|
|
40
|
-
<button class="tab active" data-tab="chat">Chat</button>
|
|
41
|
-
<button class="tab" data-tab="tools">Tools</button>
|
|
42
|
-
<button class="tab" data-tab="settings">
|
|
43
|
-
<svg viewBox="0 0 16 16" fill="none" stroke="currentColor" width="14" height="14">
|
|
44
|
-
<path d="M8 10a2 2 0 100-4 2 2 0 000 4z" stroke-width="1.5"/>
|
|
45
|
-
<path d="M13 8a5 5 0 01-10 0 5 5 0 0110 0z" stroke-width="1.5"/>
|
|
46
|
-
</svg>
|
|
47
|
-
</button>
|
|
48
|
-
</nav>
|
|
49
|
-
|
|
50
|
-
<!-- Chat Tab -->
|
|
51
|
-
<div id="tab-chat" class="tab-content active">
|
|
52
|
-
<div id="chat-messages" class="chat-messages">
|
|
53
|
-
<div class="chat-welcome">
|
|
54
|
-
<p>How can I help you today?</p>
|
|
55
|
-
</div>
|
|
56
|
-
</div>
|
|
57
|
-
<div class="chat-input-area">
|
|
58
|
-
<div class="model-selector">
|
|
59
|
-
<select id="model-select">
|
|
60
|
-
<option value="">Loading models...</option>
|
|
61
|
-
</select>
|
|
62
|
-
</div>
|
|
63
|
-
<div class="chat-input-row">
|
|
64
|
-
<textarea id="chat-input" placeholder="Ask anything..." rows="1"></textarea>
|
|
65
|
-
<button id="chat-send" class="send-btn" disabled>
|
|
66
|
-
<svg viewBox="0 0 20 20" fill="currentColor" width="18" height="18">
|
|
67
|
-
<path d="M2.5 2.5l15 7.5-15 7.5v-6l10-1.5-10-1.5v-6z"/>
|
|
68
|
-
</svg>
|
|
69
|
-
</button>
|
|
70
|
-
</div>
|
|
71
|
-
</div>
|
|
72
|
-
</div>
|
|
73
|
-
|
|
74
|
-
<!-- Tools Tab -->
|
|
75
|
-
<div id="tab-tools" class="tab-content">
|
|
76
|
-
<!-- ZAP / MCP Status -->
|
|
77
|
-
<div class="panel">
|
|
78
|
-
<h3>ZAP / MCP</h3>
|
|
79
|
-
<div class="status-row">
|
|
80
|
-
<span>Status</span>
|
|
81
|
-
<span id="zap-status" class="status-value">
|
|
82
|
-
<span class="status-indicator"></span>
|
|
83
|
-
Checking...
|
|
84
|
-
</span>
|
|
85
|
-
</div>
|
|
86
|
-
<div class="status-row">
|
|
87
|
-
<span>Connected MCPs</span>
|
|
88
|
-
<span id="mcp-count" class="status-value">0</span>
|
|
89
|
-
</div>
|
|
90
|
-
<div class="status-row">
|
|
91
|
-
<span>Tools Available</span>
|
|
92
|
-
<span id="tools-count" class="status-value">0</span>
|
|
93
|
-
</div>
|
|
94
|
-
</div>
|
|
95
|
-
|
|
96
|
-
<!-- Active Agents -->
|
|
97
|
-
<div class="panel">
|
|
98
|
-
<div class="panel-header">
|
|
99
|
-
<h3>Active Agents</h3>
|
|
100
|
-
<span id="agent-count" class="badge">0</span>
|
|
101
|
-
</div>
|
|
102
|
-
<div id="agent-list" class="agent-list">
|
|
103
|
-
<div class="empty-state">No active agents</div>
|
|
104
|
-
</div>
|
|
105
|
-
</div>
|
|
106
|
-
|
|
107
|
-
<!-- Tab Filesystem -->
|
|
108
|
-
<div class="panel">
|
|
109
|
-
<div class="panel-header">
|
|
110
|
-
<h3>Tab Filesystem</h3>
|
|
111
|
-
<button class="icon-btn small" id="refresh-tabs" title="Refresh">
|
|
112
|
-
<svg viewBox="0 0 16 16" fill="none" stroke="currentColor">
|
|
113
|
-
<path d="M14 2v5h-5M2 7a6 6 0 0111.5-2.5L14 5M2 14v-5h5M14 9a6 6 0 01-11.5 2.5L2 11" stroke-width="1.5"/>
|
|
114
|
-
</svg>
|
|
115
|
-
</button>
|
|
116
|
-
</div>
|
|
117
|
-
<div id="tab-fs" class="tab-filesystem">
|
|
118
|
-
<div class="empty-state">Click refresh to load tabs</div>
|
|
119
|
-
</div>
|
|
120
|
-
</div>
|
|
121
|
-
|
|
122
|
-
<!-- WebGPU Status -->
|
|
123
|
-
<div class="panel">
|
|
124
|
-
<h3>WebGPU AI</h3>
|
|
125
|
-
<div class="status-row">
|
|
126
|
-
<span>Status</span>
|
|
127
|
-
<span id="gpu-status" class="status-value">
|
|
128
|
-
<span class="status-indicator warning"></span>
|
|
129
|
-
Checking...
|
|
130
|
-
</span>
|
|
131
|
-
</div>
|
|
132
|
-
</div>
|
|
133
|
-
</div>
|
|
134
|
-
|
|
135
|
-
<!-- Settings Tab -->
|
|
136
|
-
<div id="tab-settings" class="tab-content">
|
|
137
|
-
<div class="panel">
|
|
138
|
-
<h3>Account</h3>
|
|
139
|
-
<div id="settings-user" class="settings-user">
|
|
140
|
-
<img id="settings-avatar" class="user-avatar" src="" alt="">
|
|
141
|
-
<div class="user-details">
|
|
142
|
-
<div id="settings-name" class="user-name"></div>
|
|
143
|
-
<div id="settings-email" class="user-email"></div>
|
|
144
|
-
</div>
|
|
145
|
-
</div>
|
|
146
|
-
<button id="settings-logout" class="danger-btn">Sign Out</button>
|
|
147
|
-
</div>
|
|
148
|
-
|
|
149
|
-
<div class="panel">
|
|
150
|
-
<h3>Connection</h3>
|
|
151
|
-
<label class="setting-item">
|
|
152
|
-
<span>ZAP Port</span>
|
|
153
|
-
<input type="number" id="setting-zap-port" value="9999" min="1" max="65535">
|
|
154
|
-
</label>
|
|
155
|
-
<label class="setting-item">
|
|
156
|
-
<span>Auto-reconnect</span>
|
|
157
|
-
<input type="checkbox" id="setting-auto-reconnect" checked>
|
|
158
|
-
</label>
|
|
159
|
-
</div>
|
|
160
|
-
|
|
161
|
-
<div class="panel">
|
|
162
|
-
<h3>Chat</h3>
|
|
163
|
-
<label class="setting-item">
|
|
164
|
-
<span>Default Model</span>
|
|
165
|
-
<select id="setting-default-model">
|
|
166
|
-
<option value="">Auto</option>
|
|
167
|
-
</select>
|
|
168
|
-
</label>
|
|
169
|
-
<label class="setting-item">
|
|
170
|
-
<span>Temperature</span>
|
|
171
|
-
<input type="number" id="setting-temperature" value="0.7" min="0" max="2" step="0.1">
|
|
172
|
-
</label>
|
|
173
|
-
</div>
|
|
174
|
-
|
|
175
|
-
<div class="panel">
|
|
176
|
-
<h3>Data</h3>
|
|
177
|
-
<button id="clear-chat-history" class="secondary-btn">Clear Chat History</button>
|
|
178
|
-
</div>
|
|
179
|
-
</div>
|
|
180
|
-
</div>
|
|
181
|
-
|
|
182
|
-
<script src="sidebar.js"></script>
|
|
183
|
-
</body>
|
|
184
|
-
</html>
|
|
@@ -1,411 +0,0 @@
|
|
|
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 CDPBridgeServer = class {
|
|
41
|
-
constructor(port = 9223) {
|
|
42
|
-
this.clients = /* @__PURE__ */ new Map();
|
|
43
|
-
this.pendingCommands = /* @__PURE__ */ new Map();
|
|
44
|
-
this.commandId = 0;
|
|
45
|
-
this.httpPort = port;
|
|
46
|
-
this.wss = new import_ws.WebSocketServer({ port, path: "/cdp" });
|
|
47
|
-
this.wss.on("connection", (ws) => {
|
|
48
|
-
console.log("[hanzo.browser] Extension connected");
|
|
49
|
-
ws.on("message", (data) => {
|
|
50
|
-
try {
|
|
51
|
-
const message = JSON.parse(data.toString());
|
|
52
|
-
this.handleMessage(ws, message);
|
|
53
|
-
} catch (error) {
|
|
54
|
-
console.error("[hanzo.browser] Error:", error.message);
|
|
55
|
-
}
|
|
56
|
-
});
|
|
57
|
-
ws.on("close", () => {
|
|
58
|
-
console.log("[hanzo.browser] Extension disconnected");
|
|
59
|
-
this.clients.delete(ws);
|
|
60
|
-
});
|
|
61
|
-
ws.on("error", (error) => {
|
|
62
|
-
console.error("[hanzo.browser] WebSocket error:", error);
|
|
63
|
-
});
|
|
64
|
-
});
|
|
65
|
-
console.log(`[hanzo.browser] Server listening on ws://localhost:${port}/cdp`);
|
|
66
|
-
}
|
|
67
|
-
handleMessage(ws, message) {
|
|
68
|
-
if (message.type === "register") {
|
|
69
|
-
this.clients.set(ws, {
|
|
70
|
-
ws,
|
|
71
|
-
capabilities: message.capabilities || []
|
|
72
|
-
});
|
|
73
|
-
console.log("[hanzo.browser] Registered:", message.capabilities?.join(", "));
|
|
74
|
-
return;
|
|
75
|
-
}
|
|
76
|
-
if (message.id !== void 0) {
|
|
77
|
-
const pending = this.pendingCommands.get(message.id);
|
|
78
|
-
if (pending) {
|
|
79
|
-
if (message.error) {
|
|
80
|
-
pending.reject(new Error(message.error.message));
|
|
81
|
-
} else {
|
|
82
|
-
pending.resolve(message.result);
|
|
83
|
-
}
|
|
84
|
-
this.pendingCommands.delete(message.id);
|
|
85
|
-
}
|
|
86
|
-
return;
|
|
87
|
-
}
|
|
88
|
-
if (message.type === "event") {
|
|
89
|
-
console.log(`[hanzo.browser] Event: ${message.method}`);
|
|
90
|
-
}
|
|
91
|
-
}
|
|
92
|
-
async sendRaw(method, params) {
|
|
93
|
-
const client = Array.from(this.clients.values())[0];
|
|
94
|
-
if (!client) {
|
|
95
|
-
throw new Error("No browser extension connected");
|
|
96
|
-
}
|
|
97
|
-
const id = ++this.commandId;
|
|
98
|
-
return new Promise((resolve, reject) => {
|
|
99
|
-
this.pendingCommands.set(id, { resolve, reject });
|
|
100
|
-
client.ws.send(JSON.stringify({ id, method, params }));
|
|
101
|
-
setTimeout(() => {
|
|
102
|
-
if (this.pendingCommands.has(id)) {
|
|
103
|
-
this.pendingCommands.delete(id);
|
|
104
|
-
reject(new Error("Command timeout"));
|
|
105
|
-
}
|
|
106
|
-
}, 3e4);
|
|
107
|
-
});
|
|
108
|
-
}
|
|
109
|
-
/**
|
|
110
|
-
* Unified hanzo.browser interface - matches mcp__hanzo__browser pattern
|
|
111
|
-
*/
|
|
112
|
-
async browser(params) {
|
|
113
|
-
const { action, ...rest } = params;
|
|
114
|
-
switch (action) {
|
|
115
|
-
// Navigation
|
|
116
|
-
case "navigate":
|
|
117
|
-
return this.sendRaw("Page.navigate", { url: rest.url });
|
|
118
|
-
case "navigate_back":
|
|
119
|
-
case "go_back":
|
|
120
|
-
return this.sendRaw("Page.goBack");
|
|
121
|
-
case "navigate_forward":
|
|
122
|
-
case "go_forward":
|
|
123
|
-
return this.sendRaw("Page.goForward");
|
|
124
|
-
case "reload":
|
|
125
|
-
return this.sendRaw("Page.reload");
|
|
126
|
-
case "url":
|
|
127
|
-
return this.sendRaw("Runtime.evaluate", {
|
|
128
|
-
expression: "window.location.href",
|
|
129
|
-
returnByValue: true
|
|
130
|
-
});
|
|
131
|
-
case "title":
|
|
132
|
-
return this.sendRaw("Runtime.evaluate", {
|
|
133
|
-
expression: "document.title",
|
|
134
|
-
returnByValue: true
|
|
135
|
-
});
|
|
136
|
-
case "content":
|
|
137
|
-
return this.sendRaw("Runtime.evaluate", {
|
|
138
|
-
expression: "document.documentElement.outerHTML",
|
|
139
|
-
returnByValue: true
|
|
140
|
-
});
|
|
141
|
-
// Screenshots
|
|
142
|
-
case "screenshot":
|
|
143
|
-
const screenshot = await this.sendRaw("hanzo.screenshot", {
|
|
144
|
-
format: rest.format || "png",
|
|
145
|
-
fullPage: rest.fullPage
|
|
146
|
-
});
|
|
147
|
-
if (rest.filename && screenshot.data) {
|
|
148
|
-
const buffer = Buffer.from(screenshot.data, "base64");
|
|
149
|
-
fs.writeFileSync(rest.filename, buffer);
|
|
150
|
-
return { saved: rest.filename, bytes: buffer.length };
|
|
151
|
-
}
|
|
152
|
-
return screenshot;
|
|
153
|
-
case "snapshot":
|
|
154
|
-
return this.sendRaw("Accessibility.getFullAXTree");
|
|
155
|
-
// Input - Click
|
|
156
|
-
case "click":
|
|
157
|
-
return this.sendRaw("hanzo.click", {
|
|
158
|
-
selector: rest.selector || rest.ref
|
|
159
|
-
});
|
|
160
|
-
case "dblclick":
|
|
161
|
-
case "double_click":
|
|
162
|
-
return this.sendRaw("hanzo.dblclick", {
|
|
163
|
-
selector: rest.selector || rest.ref
|
|
164
|
-
});
|
|
165
|
-
case "hover":
|
|
166
|
-
return this.sendRaw("hanzo.hover", {
|
|
167
|
-
selector: rest.selector || rest.ref
|
|
168
|
-
});
|
|
169
|
-
// Input - Type
|
|
170
|
-
case "type":
|
|
171
|
-
return this.sendRaw("hanzo.type", {
|
|
172
|
-
selector: rest.selector || rest.ref,
|
|
173
|
-
text: rest.text
|
|
174
|
-
});
|
|
175
|
-
case "fill":
|
|
176
|
-
return this.sendRaw("hanzo.fill", {
|
|
177
|
-
selector: rest.selector || rest.ref,
|
|
178
|
-
value: rest.value || rest.text
|
|
179
|
-
});
|
|
180
|
-
case "clear":
|
|
181
|
-
return this.sendRaw("hanzo.clear", {
|
|
182
|
-
selector: rest.selector || rest.ref
|
|
183
|
-
});
|
|
184
|
-
case "press_key":
|
|
185
|
-
case "press":
|
|
186
|
-
return this.sendRaw("Input.dispatchKeyEvent", {
|
|
187
|
-
type: "keyDown",
|
|
188
|
-
key: rest.key
|
|
189
|
-
});
|
|
190
|
-
// Forms
|
|
191
|
-
case "select_option":
|
|
192
|
-
return this.sendRaw("hanzo.select", {
|
|
193
|
-
selector: rest.selector || rest.ref,
|
|
194
|
-
value: rest.value
|
|
195
|
-
});
|
|
196
|
-
case "check":
|
|
197
|
-
return this.sendRaw("hanzo.check", {
|
|
198
|
-
selector: rest.selector || rest.ref
|
|
199
|
-
});
|
|
200
|
-
case "uncheck":
|
|
201
|
-
return this.sendRaw("hanzo.uncheck", {
|
|
202
|
-
selector: rest.selector || rest.ref
|
|
203
|
-
});
|
|
204
|
-
// Evaluate
|
|
205
|
-
case "evaluate":
|
|
206
|
-
return this.sendRaw("Runtime.evaluate", {
|
|
207
|
-
expression: rest.code || rest.function || rest.expression,
|
|
208
|
-
returnByValue: true
|
|
209
|
-
});
|
|
210
|
-
// Wait
|
|
211
|
-
case "wait":
|
|
212
|
-
await new Promise((resolve) => setTimeout(resolve, (rest.timeout || 1) * 1e3));
|
|
213
|
-
return { waited: rest.timeout || 1 };
|
|
214
|
-
case "wait_for_load":
|
|
215
|
-
return this.sendRaw("Page.waitForLoadState", {
|
|
216
|
-
state: rest.state || "load"
|
|
217
|
-
});
|
|
218
|
-
// Tabs
|
|
219
|
-
case "tabs":
|
|
220
|
-
case "list_tabs":
|
|
221
|
-
return this.sendRaw("Target.getTargets");
|
|
222
|
-
case "new_tab":
|
|
223
|
-
return this.sendRaw("Target.createTarget", { url: rest.url || "about:blank" });
|
|
224
|
-
case "close_tab":
|
|
225
|
-
return this.sendRaw("Target.closeTarget", { targetId: rest.tabId });
|
|
226
|
-
case "select_tab":
|
|
227
|
-
return this.sendRaw("Target.activateTarget", { targetId: rest.tabId });
|
|
228
|
-
// Console/Network
|
|
229
|
-
case "console_messages":
|
|
230
|
-
case "console":
|
|
231
|
-
return this.sendRaw("Console.getMessages");
|
|
232
|
-
case "network_requests":
|
|
233
|
-
return this.sendRaw("Network.getResponseBodies");
|
|
234
|
-
// Status
|
|
235
|
-
case "status":
|
|
236
|
-
return {
|
|
237
|
-
connected: this.clients.size > 0,
|
|
238
|
-
clients: this.clients.size,
|
|
239
|
-
port: this.httpPort
|
|
240
|
-
};
|
|
241
|
-
default:
|
|
242
|
-
return this.sendRaw(action, rest);
|
|
243
|
-
}
|
|
244
|
-
}
|
|
245
|
-
isConnected() {
|
|
246
|
-
return this.clients.size > 0;
|
|
247
|
-
}
|
|
248
|
-
close() {
|
|
249
|
-
this.wss.close();
|
|
250
|
-
}
|
|
251
|
-
};
|
|
252
|
-
async function startJSONRPCServer(bridgeServer) {
|
|
253
|
-
const http = require("http");
|
|
254
|
-
const httpServer = http.createServer(async (req, res) => {
|
|
255
|
-
if (req.method === "POST") {
|
|
256
|
-
let body = "";
|
|
257
|
-
req.on("data", (chunk) => body += chunk);
|
|
258
|
-
req.on("end", async () => {
|
|
259
|
-
try {
|
|
260
|
-
const request = JSON.parse(body);
|
|
261
|
-
const result = await bridgeServer.browser(request.params || request);
|
|
262
|
-
res.writeHead(200, { "Content-Type": "application/json" });
|
|
263
|
-
res.end(JSON.stringify({ result }));
|
|
264
|
-
} catch (error) {
|
|
265
|
-
res.writeHead(500, { "Content-Type": "application/json" });
|
|
266
|
-
res.end(JSON.stringify({ error: error.message }));
|
|
267
|
-
}
|
|
268
|
-
});
|
|
269
|
-
} else {
|
|
270
|
-
res.writeHead(200, { "Content-Type": "application/json" });
|
|
271
|
-
res.end(JSON.stringify({
|
|
272
|
-
service: "hanzo.browser",
|
|
273
|
-
connected: bridgeServer.isConnected(),
|
|
274
|
-
actions: [
|
|
275
|
-
"navigate",
|
|
276
|
-
"navigate_back",
|
|
277
|
-
"reload",
|
|
278
|
-
"url",
|
|
279
|
-
"title",
|
|
280
|
-
"content",
|
|
281
|
-
"screenshot",
|
|
282
|
-
"snapshot",
|
|
283
|
-
"click",
|
|
284
|
-
"dblclick",
|
|
285
|
-
"hover",
|
|
286
|
-
"type",
|
|
287
|
-
"fill",
|
|
288
|
-
"clear",
|
|
289
|
-
"press_key",
|
|
290
|
-
"select_option",
|
|
291
|
-
"check",
|
|
292
|
-
"uncheck",
|
|
293
|
-
"evaluate",
|
|
294
|
-
"wait",
|
|
295
|
-
"wait_for_load",
|
|
296
|
-
"tabs",
|
|
297
|
-
"new_tab",
|
|
298
|
-
"close_tab",
|
|
299
|
-
"select_tab",
|
|
300
|
-
"console",
|
|
301
|
-
"network_requests",
|
|
302
|
-
"status"
|
|
303
|
-
]
|
|
304
|
-
}));
|
|
305
|
-
}
|
|
306
|
-
});
|
|
307
|
-
httpServer.listen(9224, () => {
|
|
308
|
-
console.log("[hanzo.browser] HTTP API at http://localhost:9224");
|
|
309
|
-
});
|
|
310
|
-
}
|
|
311
|
-
async function main() {
|
|
312
|
-
const port = parseInt(process.env.CDP_PORT || "9223");
|
|
313
|
-
const server = new CDPBridgeServer(port);
|
|
314
|
-
startJSONRPCServer(server);
|
|
315
|
-
console.log("\n[hanzo.browser] Commands:");
|
|
316
|
-
console.log(" navigate <url> - Go to URL");
|
|
317
|
-
console.log(" screenshot [file] - Capture screen");
|
|
318
|
-
console.log(" click <selector> - Click element");
|
|
319
|
-
console.log(" type <sel> <text> - Type into element");
|
|
320
|
-
console.log(" eval <js> - Run JavaScript");
|
|
321
|
-
console.log(" tabs - List all tabs");
|
|
322
|
-
console.log(" status - Connection status");
|
|
323
|
-
console.log(" quit - Exit\n");
|
|
324
|
-
const rl = readline.createInterface({
|
|
325
|
-
input: process.stdin,
|
|
326
|
-
output: process.stdout
|
|
327
|
-
});
|
|
328
|
-
const prompt = () => {
|
|
329
|
-
rl.question("hanzo.browser> ", async (line) => {
|
|
330
|
-
const parts = line.trim().split(" ");
|
|
331
|
-
const action = parts[0];
|
|
332
|
-
const args = parts.slice(1);
|
|
333
|
-
if (!action) {
|
|
334
|
-
prompt();
|
|
335
|
-
return;
|
|
336
|
-
}
|
|
337
|
-
try {
|
|
338
|
-
let result;
|
|
339
|
-
switch (action) {
|
|
340
|
-
case "quit":
|
|
341
|
-
case "exit":
|
|
342
|
-
server.close();
|
|
343
|
-
rl.close();
|
|
344
|
-
process.exit(0);
|
|
345
|
-
case "navigate":
|
|
346
|
-
result = await server.browser({ action: "navigate", url: args[0] });
|
|
347
|
-
console.log("Navigated to:", args[0]);
|
|
348
|
-
break;
|
|
349
|
-
case "screenshot":
|
|
350
|
-
result = await server.browser({
|
|
351
|
-
action: "screenshot",
|
|
352
|
-
filename: args[0] || `screenshot-${Date.now()}.png`
|
|
353
|
-
});
|
|
354
|
-
console.log("Screenshot:", result);
|
|
355
|
-
break;
|
|
356
|
-
case "click":
|
|
357
|
-
result = await server.browser({ action: "click", selector: args[0] });
|
|
358
|
-
console.log("Clicked:", args[0]);
|
|
359
|
-
break;
|
|
360
|
-
case "type":
|
|
361
|
-
result = await server.browser({
|
|
362
|
-
action: "type",
|
|
363
|
-
selector: args[0],
|
|
364
|
-
text: args.slice(1).join(" ")
|
|
365
|
-
});
|
|
366
|
-
console.log("Typed into:", args[0]);
|
|
367
|
-
break;
|
|
368
|
-
case "eval":
|
|
369
|
-
result = await server.browser({
|
|
370
|
-
action: "evaluate",
|
|
371
|
-
expression: args.join(" ")
|
|
372
|
-
});
|
|
373
|
-
console.log("Result:", result?.result?.value);
|
|
374
|
-
break;
|
|
375
|
-
case "tabs":
|
|
376
|
-
result = await server.browser({ action: "tabs" });
|
|
377
|
-
console.log("Tabs:", result?.targetInfos?.map((t) => t.title).join(", "));
|
|
378
|
-
break;
|
|
379
|
-
case "status":
|
|
380
|
-
result = await server.browser({ action: "status" });
|
|
381
|
-
console.log("Status:", result);
|
|
382
|
-
break;
|
|
383
|
-
case "url":
|
|
384
|
-
result = await server.browser({ action: "url" });
|
|
385
|
-
console.log("URL:", result?.result?.value);
|
|
386
|
-
break;
|
|
387
|
-
case "title":
|
|
388
|
-
result = await server.browser({ action: "title" });
|
|
389
|
-
console.log("Title:", result?.result?.value);
|
|
390
|
-
break;
|
|
391
|
-
default:
|
|
392
|
-
result = await server.browser({ action, ...Object.fromEntries(
|
|
393
|
-
args.map((a, i) => [i === 0 ? "selector" : `arg${i}`, a])
|
|
394
|
-
) });
|
|
395
|
-
console.log("Result:", result);
|
|
396
|
-
}
|
|
397
|
-
} catch (error) {
|
|
398
|
-
console.error("Error:", error.message);
|
|
399
|
-
}
|
|
400
|
-
prompt();
|
|
401
|
-
});
|
|
402
|
-
};
|
|
403
|
-
prompt();
|
|
404
|
-
}
|
|
405
|
-
if (require.main === module) {
|
|
406
|
-
main();
|
|
407
|
-
}
|
|
408
|
-
// Annotate the CommonJS export names for ESM import in node:
|
|
409
|
-
0 && (module.exports = {
|
|
410
|
-
CDPBridgeServer
|
|
411
|
-
});
|
|
Binary file
|
|
Binary file
|
|
Binary file
|
|
Binary file
|