comate-ui-inspector 0.1.0 → 0.1.1
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/cli.mjs +15 -3
- package/extension/bridge-content.js +35 -15
- package/package.json +1 -1
package/cli.mjs
CHANGED
|
@@ -34,7 +34,11 @@ function nmDirs() {
|
|
|
34
34
|
'Library/Application Support/Microsoft Edge/NativeMessagingHosts',
|
|
35
35
|
'Library/Application Support/BraveSoftware/Brave-Browser/NativeMessagingHosts',
|
|
36
36
|
]
|
|
37
|
-
: [
|
|
37
|
+
: [
|
|
38
|
+
'.config/google-chrome/NativeMessagingHosts',
|
|
39
|
+
'.config/microsoft-edge/NativeMessagingHosts',
|
|
40
|
+
'.config/chromium/NativeMessagingHosts',
|
|
41
|
+
];
|
|
38
42
|
return rels.map(rel => join(home, rel));
|
|
39
43
|
}
|
|
40
44
|
|
|
@@ -51,10 +55,15 @@ function out(text) {
|
|
|
51
55
|
}
|
|
52
56
|
function install() {
|
|
53
57
|
chmodSync(hostPath, 0o755);
|
|
58
|
+
// 用壳脚本硬编码 node 绝对路径:Chrome 拉起 native host 时 PATH 极简(不含 nvm 等目录),
|
|
59
|
+
// 直接 `#!/usr/bin/env node` 会找不到 node 导致 host 起不来;壳脚本规避这点。
|
|
60
|
+
const wrapperPath = resolve(pkgRoot, 'extension/native-host/host-wrapper.sh');
|
|
61
|
+
writeFileSync(wrapperPath, `#!/bin/sh\nexec "${process.execPath}" "${hostPath}" "$@"\n`);
|
|
62
|
+
chmodSync(wrapperPath, 0o755);
|
|
54
63
|
const manifest = {
|
|
55
64
|
name: HOST_NAME,
|
|
56
65
|
description: 'ui-inspector native messaging host',
|
|
57
|
-
path:
|
|
66
|
+
path: wrapperPath,
|
|
58
67
|
type: 'stdio',
|
|
59
68
|
allowed_origins: [`chrome-extension://${EXT_ID}/`],
|
|
60
69
|
};
|
|
@@ -97,6 +106,10 @@ function uninstall({purge}) {
|
|
|
97
106
|
out(`removed host manifest -> ${file}`);
|
|
98
107
|
}
|
|
99
108
|
}
|
|
109
|
+
const wrapperPath = resolve(pkgRoot, 'extension/native-host/host-wrapper.sh');
|
|
110
|
+
if (existsSync(wrapperPath)) {
|
|
111
|
+
rmSync(wrapperPath);
|
|
112
|
+
}
|
|
100
113
|
const config = readHooks();
|
|
101
114
|
if (config?.hooks?.UserPromptSubmit) {
|
|
102
115
|
const before = config.hooks.UserPromptSubmit.length;
|
|
@@ -151,4 +164,3 @@ if (cmd === 'install') {
|
|
|
151
164
|
} else {
|
|
152
165
|
help();
|
|
153
166
|
}
|
|
154
|
-
|
|
@@ -1,29 +1,49 @@
|
|
|
1
1
|
/*
|
|
2
2
|
* ISOLATED world 内容脚本:MAIN world 与 background 之间的中继。
|
|
3
3
|
*
|
|
4
|
-
* - 收到 MAIN 发来的 selection(window.postMessage)→ 转给 background
|
|
5
|
-
* - 每 1.5s 问 background 要一次
|
|
4
|
+
* - 收到 MAIN 发来的 selection(window.postMessage)→ 转给 background 写入本地 host;
|
|
5
|
+
* - 每 1.5s 问 background 要一次 state 的 count;count 为 0(AI 调 MCP 清空后)
|
|
6
6
|
* → 回发 cleared 给 MAIN,让它撤掉页面高亮。
|
|
7
|
+
*
|
|
8
|
+
* 健壮性:扩展被重载后旧页面里的本脚本会「上下文失效」,此时访问 chrome.runtime 会抛
|
|
9
|
+
* "Extension context invalidated"。用 alive() 判活 + try/catch 兜住,并在失效时停掉轮询。
|
|
7
10
|
*/
|
|
8
11
|
(function () {
|
|
12
|
+
const alive = () => !!(chrome.runtime && chrome.runtime.id);
|
|
13
|
+
|
|
9
14
|
window.addEventListener('message', event => {
|
|
10
|
-
if (event.source !== window) {
|
|
15
|
+
if (event.source !== window || !event.data || event.data.__uiInspector !== 'selection') {
|
|
16
|
+
return;
|
|
17
|
+
}
|
|
18
|
+
if (!alive()) {
|
|
11
19
|
return;
|
|
12
20
|
}
|
|
13
|
-
|
|
14
|
-
|
|
15
|
-
|
|
21
|
+
try {
|
|
22
|
+
chrome.runtime.sendMessage(
|
|
23
|
+
{type: 'ingest', targets: event.data.targets || []},
|
|
24
|
+
() => void chrome.runtime.lastError
|
|
25
|
+
);
|
|
26
|
+
} catch {
|
|
27
|
+
// 扩展已重载、上下文失效:刷新页面即恢复
|
|
16
28
|
}
|
|
17
29
|
});
|
|
18
30
|
|
|
19
|
-
setInterval(() => {
|
|
20
|
-
|
|
21
|
-
|
|
22
|
-
|
|
23
|
-
|
|
24
|
-
|
|
25
|
-
|
|
26
|
-
|
|
27
|
-
|
|
31
|
+
const timer = setInterval(() => {
|
|
32
|
+
if (!alive()) {
|
|
33
|
+
clearInterval(timer);
|
|
34
|
+
return;
|
|
35
|
+
}
|
|
36
|
+
try {
|
|
37
|
+
chrome.runtime.sendMessage({type: 'state'}, resp => {
|
|
38
|
+
if (chrome.runtime.lastError) {
|
|
39
|
+
return;
|
|
40
|
+
}
|
|
41
|
+
if (resp && resp.ok && resp.count === 0) {
|
|
42
|
+
window.postMessage({__uiInspectorBridge: 'cleared'}, '*');
|
|
43
|
+
}
|
|
44
|
+
});
|
|
45
|
+
} catch {
|
|
46
|
+
clearInterval(timer);
|
|
47
|
+
}
|
|
28
48
|
}, 1500);
|
|
29
49
|
})();
|