@glittering0717/ai-browser 0.0.0-stage → 1.2.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.
- package/LICENSE +21 -0
- package/README.md +784 -2
- package/bin/ai-browser.cjs +78 -0
- package/examples/AGENT_INSTRUCTIONS.md +166 -0
- package/examples/mcp-config.json +12 -0
- package/llms-install.md +158 -0
- package/package.json +78 -4
- package/scripts/electron_resolve.cjs +241 -0
- package/scripts/start.cjs +60 -0
- package/src/main/axExtractor.js +436 -0
- package/src/main/canvas_hook_source.js +654 -0
- package/src/main/canvas_monitor.js +269 -0
- package/src/main/capability_probe.js +415 -0
- package/src/main/download_monitor.js +137 -0
- package/src/main/index.js +359 -0
- package/src/main/mcp_server.js +408 -0
- package/src/main/mcp_tools.js +289 -0
- package/src/main/mcp_ws.js +178 -0
- package/src/main/network_monitor.js +805 -0
- package/src/main/page_manager.js +2743 -0
- package/src/main/snapshot_diff.js +371 -0
- package/src/main/ws_server.js +440 -0
- package/src/preload/actions.cjs +190 -0
- package/src/preload/bridge.cjs +75 -0
- package/src/preload/extractor.cjs +936 -0
- package/src/preload/watcher.cjs +241 -0
- package/src/renderer/tab_bar.html +115 -0
- package/src/shared/config.js +32 -0
- package/src/shared/deadline.js +89 -0
- package/src/shared/guards.js +17 -0
- package/src/shared/protocol.js +116 -0
- package/src/shared/value_contract.cjs +132 -0
- package/src/shared/version.js +5 -0
- package/src/shared/watchdog.js +57 -0
|
@@ -0,0 +1,75 @@
|
|
|
1
|
+
// preload/bridge.cjs — AI Browser entry (CommonJS, loaded by Electron preload)
|
|
2
|
+
// v6.9, split into modules: extractor.cjs / actions.cjs / watcher.cjs
|
|
3
|
+
// Responsible only for: IPC wiring + module orchestration.
|
|
4
|
+
// Requires local .cjs modules — the tab BrowserView MUST set sandbox:false
|
|
5
|
+
// (see page_manager.newTab) since a sandboxed preload can only require
|
|
6
|
+
// Electron's whitelist, not arbitrary local files.
|
|
7
|
+
const { contextBridge, ipcRenderer } = require("electron");
|
|
8
|
+
const { extractTree, extractPageContext } = require("./extractor.cjs");
|
|
9
|
+
const { executeAction } = require("./actions.cjs");
|
|
10
|
+
const { startTracking } = require("./watcher.cjs");
|
|
11
|
+
|
|
12
|
+
// Watch event → push to main via IPC
|
|
13
|
+
function sendEvent(event, data) {
|
|
14
|
+
ipcRenderer.send("ai:event", { event: event, data: data || {} });
|
|
15
|
+
}
|
|
16
|
+
|
|
17
|
+
// ============================================================
|
|
18
|
+
// IPC EXPOSURE
|
|
19
|
+
// ============================================================
|
|
20
|
+
|
|
21
|
+
contextBridge.exposeInMainWorld("__ai_browser__", {
|
|
22
|
+
sendTree: function(tree) { ipcRenderer.send("ai:tree", tree); },
|
|
23
|
+
sendDiff: function(changes) { ipcRenderer.send("ai:diff", changes); }
|
|
24
|
+
});
|
|
25
|
+
|
|
26
|
+
// Extract tree request — echo back the request id so the main process can
|
|
27
|
+
// match this response to the caller (concurrent requests / multi-tab safe).
|
|
28
|
+
ipcRenderer.on("ai:extract", function(_event, params) {
|
|
29
|
+
params = params || {};
|
|
30
|
+
var id = params.id;
|
|
31
|
+
try {
|
|
32
|
+
var tree = extractTree();
|
|
33
|
+
var ctx = extractPageContext();
|
|
34
|
+
ipcRenderer.send("ai:tree", { tree: tree, context: ctx, id: id });
|
|
35
|
+
} catch(e) {
|
|
36
|
+
console.error("[bridge] extractTree crash:", e.message, e.stack);
|
|
37
|
+
// Return empty fallback
|
|
38
|
+
ipcRenderer.send("ai:tree", {
|
|
39
|
+
tree: { id: "root", role: "generic", label: "[error: " + e.message + "]", states: ["visible"], actions: [], bounds: { x: 0, y: 0, width: 0, height: 0 } },
|
|
40
|
+
context: { modals: [], forms: [], session: {}, stats: {} },
|
|
41
|
+
id: id
|
|
42
|
+
});
|
|
43
|
+
}
|
|
44
|
+
});
|
|
45
|
+
|
|
46
|
+
// Action request
|
|
47
|
+
ipcRenderer.on("ai:action", function(_event, data) {
|
|
48
|
+
data = data || {};
|
|
49
|
+
var result = executeAction(data.target, data.action, data.params);
|
|
50
|
+
result.id = data.id;
|
|
51
|
+
ipcRenderer.send("ai:action_result", result);
|
|
52
|
+
});
|
|
53
|
+
|
|
54
|
+
// Evaluate request — run arbitrary JS in page context
|
|
55
|
+
ipcRenderer.on("ai:evaluate", function(_event, data) {
|
|
56
|
+
data = data || {};
|
|
57
|
+
try {
|
|
58
|
+
var result = eval(data.js);
|
|
59
|
+
ipcRenderer.send("ai:evaluate_result", { value: result, id: data.id });
|
|
60
|
+
} catch(e) {
|
|
61
|
+
ipcRenderer.send("ai:evaluate_result", { error: e.message, id: data.id });
|
|
62
|
+
}
|
|
63
|
+
});
|
|
64
|
+
|
|
65
|
+
// Start watchers only after page is fully loaded.
|
|
66
|
+
// Observing during DOM construction causes massive mutation queues that block
|
|
67
|
+
// the renderer (each flush runs expensive querySelectorAll via scanCaptcha/scanMessages).
|
|
68
|
+
function startWatchers() {
|
|
69
|
+
startTracking({ onEvent: sendEvent });
|
|
70
|
+
}
|
|
71
|
+
if (document.readyState === "complete") {
|
|
72
|
+
setTimeout(startWatchers, 100);
|
|
73
|
+
} else {
|
|
74
|
+
window.addEventListener("load", function() { setTimeout(startWatchers, 100); });
|
|
75
|
+
}
|