@glittering0717/ai-browser 2.5.7 → 2.5.9
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/README.md +3 -3
- package/llms-install.md +11 -8
- package/package.json +2 -2
- package/scripts/marketing/data_snapshot.sh +2 -1
- package/scripts/release.cjs +213 -80
- package/scripts/render_icon.cjs +51 -28
- package/scripts/skill.cjs +8 -0
- package/scripts/verify_asar.cjs +8 -2
- package/scripts/verify_build.cjs +71 -32
- package/src/main/axExtractor.js +1 -1
- package/src/main/capability_probe.js +2 -2
- package/src/main/error_log.js +102 -0
- package/src/main/index.js +24 -4
- package/src/main/page_manager.js +30 -11
- package/src/main/window_open_shim_source.js +2 -2
- package/src/main/ws_server.js +14 -1
- package/src/preload/extractor.cjs +2 -2
- package/src/renderer/download.html +1 -1
- package/src/shared/browser_identity.cjs +1 -1
- package/src/shared/doc_coverage.js +6 -6
- package/src/shared/frame_probe.cjs +1 -1
- package/src/shared/frame_read_source.js +4 -4
- package/src/shared/media_doc.cjs +1 -1
- package/src/shared/opened_tab.js +1 -1
- package/src/shared/version.js +1 -1
- package/src/shared/view_liveness.cjs +31 -1
- package/tools/coverage_probe.cjs +4 -4
package/scripts/render_icon.cjs
CHANGED
|
@@ -14,10 +14,11 @@
|
|
|
14
14
|
// build_dmg.cjs 的 icon 选项只读 build/icon.icns;icon.svg 是母版;
|
|
15
15
|
// 其余 png/iconset 都是本脚本的再生产物,改了 SVG 重跑本脚本即可。
|
|
16
16
|
//
|
|
17
|
-
// # 用法(必须在 Electron 下运行,不是 node
|
|
18
|
-
//
|
|
19
|
-
//
|
|
20
|
-
//
|
|
17
|
+
// # 用法(必须在 Electron 下运行,不是 node)
|
|
18
|
+
// npm run icons
|
|
19
|
+
// 等价于 node scripts/render_icon.cjs —— 脚本检测到自己在普通 node 下,
|
|
20
|
+
// 会用 require('electron') 返回的二进制路径把**自己**重新拉进 Electron 跑,
|
|
21
|
+
// 所以 macOS / Windows / Linux 同一条命令,不写死 *.app 路径。
|
|
21
22
|
'use strict';
|
|
22
23
|
|
|
23
24
|
const fs = require('node:fs');
|
|
@@ -63,19 +64,30 @@ const SIZES = [
|
|
|
63
64
|
[1024, 'icon_512x512@2x.png'],
|
|
64
65
|
];
|
|
65
66
|
|
|
66
|
-
//
|
|
67
|
+
// 普通 node 下 require('electron') 拿到的是**二进制路径字符串**(三平台一致)。
|
|
68
|
+
// 用它把本脚本重新拉进 Electron:这样入口不再依赖 macOS 的 Electron.app 结构。
|
|
67
69
|
let electron;
|
|
68
70
|
try {
|
|
69
71
|
electron = require('electron');
|
|
70
72
|
} catch (_) {
|
|
71
73
|
electron = null;
|
|
72
74
|
}
|
|
75
|
+
if (typeof electron === 'string') {
|
|
76
|
+
const env = { ...process.env };
|
|
77
|
+
// 只要这个变量存在(哪怕空串),Electron 都会按 node 模式启动,必须删掉。
|
|
78
|
+
delete env.ELECTRON_RUN_AS_NODE;
|
|
79
|
+
const r = spawnSync(electron, ['--no-sandbox', '--disable-gpu', __filename], {
|
|
80
|
+
stdio: 'inherit',
|
|
81
|
+
env,
|
|
82
|
+
});
|
|
83
|
+
process.exit(r.status ?? 1);
|
|
84
|
+
}
|
|
73
85
|
if (!electron || typeof electron.app === 'undefined') {
|
|
74
|
-
console.error('[icon]
|
|
86
|
+
console.error('[icon] 找不到 Electron 运行时(node_modules/electron 没装好?)。');
|
|
75
87
|
process.exit(2);
|
|
76
88
|
}
|
|
77
89
|
|
|
78
|
-
const { app, BrowserWindow } = electron;
|
|
90
|
+
const { app, BrowserWindow, nativeImage } = electron;
|
|
79
91
|
|
|
80
92
|
app.commandLine.appendSwitch('disable-gpu'); // 无头环境没有 GL,别让 GPU 进程拖后腿
|
|
81
93
|
|
|
@@ -86,8 +98,15 @@ function run(cmd, args) {
|
|
|
86
98
|
}
|
|
87
99
|
}
|
|
88
100
|
|
|
101
|
+
// 用 Electron 自带的 nativeImage 缩放,替代 macOS 专属的 sips —— 三平台同一套。
|
|
102
|
+
function resizedPng(img, size) {
|
|
103
|
+
return img.resize({ width: size, height: size, quality: 'best' }).toPNG();
|
|
104
|
+
}
|
|
105
|
+
|
|
89
106
|
app.whenReady().then(async () => {
|
|
90
|
-
// 窗口 1024,capturePage 在 Retina 下返回 2x(2048×2048
|
|
107
|
+
// 窗口 1024,capturePage 在 Retina 下返回 2x(2048×2048)——这就是母版位图。
|
|
108
|
+
// offscreen: 离屏渲染不受"窗口不能大于屏幕可用高度"的限制;否则在 1080p
|
|
109
|
+
// 笔记本上 1024×1024 会被裁成 1024×1001,图被纵向拉伸(实测)。
|
|
91
110
|
const SIZE = 1024;
|
|
92
111
|
const win = new BrowserWindow({
|
|
93
112
|
width: SIZE,
|
|
@@ -96,7 +115,7 @@ app.whenReady().then(async () => {
|
|
|
96
115
|
transparent: true,
|
|
97
116
|
backgroundColor: '#00000000',
|
|
98
117
|
useContentSize: true,
|
|
99
|
-
webPreferences: { offscreen:
|
|
118
|
+
webPreferences: { offscreen: true },
|
|
100
119
|
});
|
|
101
120
|
|
|
102
121
|
try {
|
|
@@ -108,23 +127,31 @@ app.whenReady().then(async () => {
|
|
|
108
127
|
if (img.isEmpty()) throw new Error('capturePage returned an empty image');
|
|
109
128
|
|
|
110
129
|
const png = img.toPNG();
|
|
111
|
-
fs.writeFileSync(PNG_2X, png);
|
|
112
130
|
const w = img.getSize().width;
|
|
113
131
|
const h = img.getSize().height;
|
|
132
|
+
// 非正方形说明截取被窗口约束裁过,再缩放会把图形拉变形 —— 宁可失败。
|
|
133
|
+
if (w !== h) throw new Error(`capturePage 返回 ${w}x${h},不是正方形(窗口被屏幕尺寸限制?)`);
|
|
134
|
+
fs.writeFileSync(PNG_2X, png);
|
|
135
|
+
const master = nativeImage.createFromBuffer(png);
|
|
114
136
|
console.log(`[icon] ${path.relative(ROOT, SVG)} -> ${path.relative(ROOT, PNG_2X)} (${w}x${h}, ${png.length} bytes)`);
|
|
115
137
|
|
|
116
|
-
//
|
|
117
|
-
|
|
118
|
-
|
|
119
|
-
// 2)
|
|
120
|
-
|
|
121
|
-
|
|
122
|
-
|
|
123
|
-
|
|
138
|
+
// 1) 1024 预览图 / Windows·Linux 窗口图标源(三平台都要)
|
|
139
|
+
fs.writeFileSync(PNG, resizedPng(master, 1024));
|
|
140
|
+
|
|
141
|
+
// 2) icns 只有 macOS 打包读;Windows 读 build/icon.ico,Linux 直接读 png。
|
|
142
|
+
if (process.platform === 'darwin') {
|
|
143
|
+
fs.rmSync(ICONSET, { recursive: true, force: true });
|
|
144
|
+
fs.mkdirSync(ICONSET, { recursive: true });
|
|
145
|
+
for (const [size, name] of SIZES) {
|
|
146
|
+
fs.writeFileSync(path.join(ICONSET, name), resizedPng(master, size));
|
|
147
|
+
}
|
|
148
|
+
fs.rmSync(ICNS, { force: true });
|
|
149
|
+
run('iconutil', ['-c', 'icns', ICONSET, '-o', ICNS]);
|
|
150
|
+
const icnsSize = fs.statSync(ICNS).size;
|
|
151
|
+
console.log(`[icon] iconset: ${SIZES.length} sizes -> ${path.relative(ROOT, ICNS)} (${icnsSize} bytes)`);
|
|
152
|
+
} else {
|
|
153
|
+
console.log(`[icon] 跳过 icns(${process.platform} 打包不读它;Windows 用 build/icon.ico)`);
|
|
124
154
|
}
|
|
125
|
-
// 3) 打 icns
|
|
126
|
-
fs.rmSync(ICNS, { force: true });
|
|
127
|
-
run('iconutil', ['-c', 'icns', ICONSET, '-o', ICNS]);
|
|
128
155
|
|
|
129
156
|
// 4) Dock 专用图:同一个图形按系统图标网格缩到 DOCK_CONTENT,透明居中
|
|
130
157
|
const stage = path.join(ROOT, 'build', '.dock_stage.html');
|
|
@@ -140,7 +167,7 @@ app.whenReady().then(async () => {
|
|
|
140
167
|
const dockWin = new BrowserWindow({
|
|
141
168
|
width: SIZE, height: SIZE, show: false, transparent: true,
|
|
142
169
|
backgroundColor: '#00000000', useContentSize: true,
|
|
143
|
-
webPreferences: { offscreen:
|
|
170
|
+
webPreferences: { offscreen: true },
|
|
144
171
|
});
|
|
145
172
|
await dockWin.loadFile(stage);
|
|
146
173
|
await new Promise((r) => setTimeout(r, 300));
|
|
@@ -151,14 +178,10 @@ app.whenReady().then(async () => {
|
|
|
151
178
|
} finally {
|
|
152
179
|
fs.rmSync(stage, { force: true });
|
|
153
180
|
}
|
|
154
|
-
fs.writeFileSync(
|
|
155
|
-
run('sips', ['-Z', String(SIZE), path.join(ROOT, 'build', 'icon-dock@2x.png'), '-o', DOCK_PNG]);
|
|
156
|
-
fs.rmSync(path.join(ROOT, 'build', 'icon-dock@2x.png'), { force: true });
|
|
181
|
+
fs.writeFileSync(DOCK_PNG, resizedPng(nativeImage.createFromBuffer(dockPng), SIZE));
|
|
157
182
|
console.log(`[icon] dock 图: ${path.relative(ROOT, DOCK_PNG)}(内容占 ${(DOCK_CONTENT * 100).toFixed(1)}%,与系统图标同尺寸)`);
|
|
158
183
|
|
|
159
|
-
|
|
160
|
-
console.log(`[icon] iconset: ${SIZES.length} sizes -> ${path.relative(ROOT, ICNS)} (${icnsSize} bytes)`);
|
|
161
|
-
console.log('[icon] done. build_dmg.cjs 会读取 build/icon.icns');
|
|
184
|
+
console.log('[icon] done.');
|
|
162
185
|
app.exit(0);
|
|
163
186
|
} catch (e) {
|
|
164
187
|
console.error(`[icon] FAILED: ${e.message}`);
|
package/scripts/skill.cjs
CHANGED
|
@@ -21,10 +21,18 @@ const SKILLS_ROOT = path.join(__dirname, '..', 'skills');
|
|
|
21
21
|
const MARKER = '.ai-browser-skill';
|
|
22
22
|
|
|
23
23
|
// 已知客户端的技能目录。宁可只列确定正确的几个,也不猜。
|
|
24
|
+
// 每个客户端从自己的目录扫 SKILL.md(frontmatter 里 name + description),
|
|
25
|
+
// 格式一致,所以同一份文件能直接拷。目录不存在说明没装那个客户端,跳过。
|
|
26
|
+
//
|
|
27
|
+
// Trae CN 是 2026-11-28 补上的:之前只装 WorkBuddy / Claude / Codex,
|
|
28
|
+
// 用户在 Trae 里让 agent「用 ai-browser」,agent 根本看不到这个技能 ——
|
|
29
|
+
// 而 Trae 索引里恰好有一个 Vercel 的 `agent-browser`(名字相近、场景重叠),
|
|
30
|
+
// 于是它要么匹配到那个,要么退回去用 Trae 内置的 Chrome 通道。
|
|
24
31
|
const TARGETS = [
|
|
25
32
|
{ id: 'workbuddy', label: 'WorkBuddy', dir: path.join(os.homedir(), '.workbuddy', 'skills') },
|
|
26
33
|
{ id: 'claude', label: 'Claude Code', dir: path.join(os.homedir(), '.claude', 'skills') },
|
|
27
34
|
{ id: 'codex', label: 'Codex', dir: path.join(os.homedir(), '.codex', 'skills') },
|
|
35
|
+
{ id: 'trae', label: 'Trae CN', dir: path.join(os.homedir(), '.trae-cn', 'skills') },
|
|
28
36
|
];
|
|
29
37
|
|
|
30
38
|
function listSkills() {
|
package/scripts/verify_asar.cjs
CHANGED
|
@@ -99,7 +99,13 @@ function verifyAsarDeps(target, opts = {}) {
|
|
|
99
99
|
return { ok: false, asar: null, checked: 0, typesOnly: 0, violations: [{ pkg: '(app.asar)', entry: '找不到 app.asar', why: '' }] };
|
|
100
100
|
}
|
|
101
101
|
|
|
102
|
-
|
|
102
|
+
// listPackage 返回的是**宿主平台**的路径(Windows 是 `\a\b`,POSIX 是 `/a/b`)。
|
|
103
|
+
// 内部统一成 `/` 形式做比较;需要回传给 @electron/asar 时再按 path.sep 还原,
|
|
104
|
+
// 因为它的 Filesystem 用 path.sep 拆目录,两边都得说得通。
|
|
105
|
+
const toNative = (rel) => rel.split('/').join(path.sep);
|
|
106
|
+
const entries = new Set(
|
|
107
|
+
asarMod.listPackage(asarPath).map((p) => p.replace(/[\\/]+/g, '/').replace(/^\/+/, ''))
|
|
108
|
+
);
|
|
103
109
|
|
|
104
110
|
// 与 Node 的解析规则一致:无扩展名要试 .js/.json/.node,目录要退到 index.*
|
|
105
111
|
const SUFFIX = ['', '.js', '.json', '.node', '/index.js', '/index.json', '/index.node'];
|
|
@@ -155,7 +161,7 @@ function verifyAsarDeps(target, opts = {}) {
|
|
|
155
161
|
checked++;
|
|
156
162
|
let meta = null;
|
|
157
163
|
try {
|
|
158
|
-
meta = JSON.parse(asarMod.extractFile(asarPath, pj).toString('utf8'));
|
|
164
|
+
meta = JSON.parse(asarMod.extractFile(asarPath, toNative(pj)).toString('utf8'));
|
|
159
165
|
} catch (_) {
|
|
160
166
|
violations.push({ pkg: pkgName, entry: '(package.json 无法解析)', why: '' });
|
|
161
167
|
continue;
|
package/scripts/verify_build.cjs
CHANGED
|
@@ -9,10 +9,12 @@
|
|
|
9
9
|
//
|
|
10
10
|
// 这类漂移(source ≠ package)是所有桌面分发共同的问题,靠"记得重新打包"
|
|
11
11
|
// 解决不了,必须能机器判定。这里做三件事:
|
|
12
|
-
// 1.
|
|
12
|
+
// 1. 版本一致:产物里声明的版本 == package.json 版本
|
|
13
|
+
// (macOS 看 Info.plist,Windows/Linux 看 asar 内的 package.json)
|
|
13
14
|
// 2. 内容一致:asar 里的 src/** 与磁盘上的 src/** 逐字节相同(少一个文件、
|
|
14
15
|
// 多一个文件、内容有 diff 都算失败)
|
|
15
|
-
// 3.
|
|
16
|
+
// 3. 产物存在:当前平台的安装产物在 dist/
|
|
17
|
+
// (macOS: *.dmg,Windows: dist/installer/*-Setup.exe)
|
|
16
18
|
//
|
|
17
19
|
// # 用法
|
|
18
20
|
// node scripts/verify_build.cjs # 失败退出码 1
|
|
@@ -36,48 +38,73 @@ function sha(buf) {
|
|
|
36
38
|
return crypto.createHash('sha256').update(buf).digest('hex').slice(0, 16);
|
|
37
39
|
}
|
|
38
40
|
|
|
39
|
-
// ---- 1.
|
|
41
|
+
// ---- 1. 找到打包后的 asar(macOS: *.app,Windows/Linux: 便携目录)----------
|
|
40
42
|
const distDir = path.join(ROOT, 'dist');
|
|
41
43
|
if (!fs.existsSync(distDir)) {
|
|
42
|
-
fail('dist/ 不存在 ——
|
|
44
|
+
fail('dist/ 不存在 —— 还没打过包');
|
|
43
45
|
process.exit(1);
|
|
44
46
|
}
|
|
45
|
-
const
|
|
46
|
-
|
|
47
|
-
|
|
48
|
-
|
|
47
|
+
const asar = require('@electron/asar');
|
|
48
|
+
const platform = process.platform;
|
|
49
|
+
let appPath = null;
|
|
50
|
+
let asarPath = null;
|
|
51
|
+
if (platform === 'darwin') {
|
|
52
|
+
const appDirName = fs.readdirSync(distDir).find((n) => n.endsWith('-darwin-arm64'));
|
|
53
|
+
if (!appDirName) {
|
|
54
|
+
fail('dist/ 里没有 *-darwin-arm64 目录');
|
|
55
|
+
process.exit(1);
|
|
56
|
+
}
|
|
57
|
+
appPath = path.join(distDir, appDirName, 'AI Browser.app');
|
|
58
|
+
asarPath = path.join(appPath, 'Contents', 'Resources', 'app.asar');
|
|
59
|
+
} else if (platform === 'win32') {
|
|
60
|
+
const appDirName = fs.readdirSync(distDir).find((n) => n.endsWith('-win32-x64'));
|
|
61
|
+
if (!appDirName) {
|
|
62
|
+
fail('dist/ 里没有 *-win32-x64 目录');
|
|
63
|
+
process.exit(1);
|
|
64
|
+
}
|
|
65
|
+
asarPath = path.join(distDir, appDirName, 'resources', 'app.asar');
|
|
66
|
+
} else {
|
|
67
|
+
const appDirName = fs.readdirSync(distDir).find((n) => n.endsWith('-linux-x64'));
|
|
68
|
+
if (!appDirName) {
|
|
69
|
+
fail('dist/ 里没有 *-linux-x64 目录');
|
|
70
|
+
process.exit(1);
|
|
71
|
+
}
|
|
72
|
+
asarPath = path.join(distDir, appDirName, 'resources', 'app.asar');
|
|
49
73
|
}
|
|
50
|
-
const appPath = path.join(distDir, appDirName, 'AI Browser.app');
|
|
51
|
-
const asarPath = path.join(appPath, 'Contents', 'Resources', 'app.asar');
|
|
52
74
|
if (!fs.existsSync(asarPath)) {
|
|
53
75
|
fail(`asar 不存在:${asarPath}`);
|
|
54
76
|
process.exit(1);
|
|
55
77
|
}
|
|
56
78
|
|
|
57
79
|
// ---- 2. 版本一致 -----------------------------------------------------------
|
|
58
|
-
|
|
59
|
-
|
|
80
|
+
// macOS 读 bundle 的 Info.plist(用户在"关于"里看到的就是它);Windows/Linux
|
|
81
|
+
// 没有 plist,读 asar 里 package.json 的 version —— 都是"产物自己声明的版本"。
|
|
82
|
+
let appVer = null;
|
|
83
|
+
if (platform === 'darwin') {
|
|
60
84
|
try {
|
|
61
|
-
|
|
85
|
+
appVer = require('node:child_process').execFileSync(
|
|
62
86
|
'/usr/libexec/PlistBuddy',
|
|
63
|
-
['-c', 'Print :CFBundleShortVersionString',
|
|
87
|
+
['-c', 'Print :CFBundleShortVersionString', path.join(appPath, 'Contents', 'Info.plist')],
|
|
64
88
|
{ encoding: 'utf8' }
|
|
65
89
|
).trim();
|
|
66
|
-
|
|
67
|
-
|
|
68
|
-
|
|
90
|
+
} catch { appVer = null; }
|
|
91
|
+
} else {
|
|
92
|
+
try {
|
|
93
|
+
appVer = JSON.parse(asar.extractFile(asarPath, 'package.json').toString('utf8')).version;
|
|
94
|
+
} catch { appVer = null; }
|
|
95
|
+
}
|
|
69
96
|
|
|
70
|
-
if (
|
|
71
|
-
ok(
|
|
97
|
+
if (appVer === pkg.version) {
|
|
98
|
+
ok(`打包产物版本 ${appVer} 与 package.json 一致`);
|
|
72
99
|
} else {
|
|
73
|
-
problems.push(
|
|
74
|
-
fail(
|
|
100
|
+
problems.push(`打包产物版本 ${appVer || '?'} ≠ package.json ${pkg.version} —— 产物是旧版,需要重新打包`);
|
|
101
|
+
fail(`打包产物版本 ${appVer || '?'} ≠ package.json ${pkg.version}`);
|
|
75
102
|
}
|
|
76
103
|
|
|
77
104
|
// ---- 3. 内容一致:asar 里的 src/** vs 磁盘 src/** --------------------------
|
|
78
105
|
// @electron/asar 的 extractFile 只接受 asar 内的相对路径,且对不存在的路径抛错;
|
|
79
106
|
// 用它既能比对内容,也能发现"asar 里少了某个新文件"。
|
|
80
|
-
|
|
107
|
+
// 路径用 path.join 拼(Windows 需要 `\`,POSIX 需要 `/`),两边都对。
|
|
81
108
|
|
|
82
109
|
function walk(dir, base = dir, out = []) {
|
|
83
110
|
for (const e of fs.readdirSync(dir, { withFileTypes: true })) {
|
|
@@ -117,15 +144,26 @@ if (!missing.length && !drifted.length) {
|
|
|
117
144
|
ok(`asar 内 src/** 与源码逐字节一致(${same} 个文件)`);
|
|
118
145
|
}
|
|
119
146
|
|
|
120
|
-
// ---- 4.
|
|
121
|
-
const
|
|
122
|
-
|
|
123
|
-
|
|
124
|
-
|
|
125
|
-
|
|
126
|
-
}
|
|
127
|
-
|
|
128
|
-
|
|
147
|
+
// ---- 4. 安装产物存在且版本正确 ---------------------------------------------
|
|
148
|
+
const artifact = platform === 'darwin'
|
|
149
|
+
? {
|
|
150
|
+
name: `AI-Browser-${pkg.version}-arm64.dmg`,
|
|
151
|
+
full: path.join(distDir, `AI-Browser-${pkg.version}-arm64.dmg`),
|
|
152
|
+
label: 'dmg',
|
|
153
|
+
}
|
|
154
|
+
: platform === 'win32'
|
|
155
|
+
? {
|
|
156
|
+
name: `AI-Browser-${pkg.version}-win32-x64-Setup.exe`,
|
|
157
|
+
full: path.join(distDir, 'installer', `AI-Browser-${pkg.version}-win32-x64-Setup.exe`),
|
|
158
|
+
label: '安装器',
|
|
159
|
+
}
|
|
160
|
+
: null;
|
|
161
|
+
if (artifact && fs.existsSync(artifact.full)) {
|
|
162
|
+
const mb = (fs.statSync(artifact.full).size / 1024 / 1024).toFixed(1);
|
|
163
|
+
ok(`${artifact.label}就绪:${artifact.name}(${mb} MB)`);
|
|
164
|
+
} else if (artifact) {
|
|
165
|
+
problems.push(`${path.relative(ROOT, artifact.full)} 不存在`);
|
|
166
|
+
fail(`缺 ${artifact.name}`);
|
|
129
167
|
}
|
|
130
168
|
|
|
131
169
|
// ---- 结论 -----------------------------------------------------------------
|
|
@@ -134,7 +172,8 @@ if (problems.length) {
|
|
|
134
172
|
fail(`打包产物与源码不同步(${problems.length} 项)`);
|
|
135
173
|
if (!quiet) {
|
|
136
174
|
console.log(' 用户装上的是旧代码,任何"已修复"的说法都不成立。');
|
|
137
|
-
console.log(' 修复:node scripts/
|
|
175
|
+
console.log(' 修复:node scripts/build_win.cjs && node scripts/build_installer.cjs(Windows)');
|
|
176
|
+
console.log(' node scripts/build_dmg.cjs(macOS)');
|
|
138
177
|
}
|
|
139
178
|
process.exit(1);
|
|
140
179
|
}
|
package/src/main/axExtractor.js
CHANGED
|
@@ -399,7 +399,7 @@ export function mergeFrameTrees(mainTree, frames = []) {
|
|
|
399
399
|
// 为什么内容块也要留:这个函数原来只留 `actions.length > 0` 的节点,也就是
|
|
400
400
|
// 只有"能点的东西"算数。于是跨进程 frame 里的标题/列表/表格单元——也就是
|
|
401
401
|
// agent 真正要**读懂**的东西——即使被读出来也会在这里被丢第二次(第一次是
|
|
402
|
-
//
|
|
402
|
+
// 采集端的选择器)。某教学平台的章节列表就是这么整片消失的。
|
|
403
403
|
const CONTENT_ROLES = new Set(['text', 'heading', 'listitem', 'cell', 'paragraph', 'term', 'note']);
|
|
404
404
|
const lift = (tv) => {
|
|
405
405
|
const out = [];
|
|
@@ -389,7 +389,7 @@ export function rankAppGlobals(globals) {
|
|
|
389
389
|
/**
|
|
390
390
|
* "树为什么这么薄" —— 三种归因必须分开说。
|
|
391
391
|
*
|
|
392
|
-
* 事故(2026-10-19
|
|
392
|
+
* 事故(2026-10-19,某教学平台学习页):树只有 27 个节点、13 个可操作,探针**自己
|
|
393
393
|
* 测到了** 1 个跨进程 iframe(`iframe: 跨进程 1 个`、`canvas 顶层级 0`),却在
|
|
394
394
|
* 结论里写 "the UI is largely canvas-rendered, so the tree cannot see the content"。
|
|
395
395
|
* 归因错了:内容看不见是因为它在 iframe 里,不是因为它画在 canvas 上。这个错误
|
|
@@ -436,7 +436,7 @@ export function recommend({ flat, dom, endpoints, coverage }) {
|
|
|
436
436
|
const totalCanvas = topCanvas + frameCanvas;
|
|
437
437
|
const sameOriginFrame = iframes.find((f) => f.sameOrigin);
|
|
438
438
|
// 跨进程、且**有尺寸**的帧:内容在另一个渲染进程里,顶层文档读不到。广告/埋点
|
|
439
|
-
// 帧通常是 0×0,不算。这是"树薄"
|
|
439
|
+
// 帧通常是 0×0,不算。这是"树薄"最常见的真实原因(某教学平台、B站图文、掘金都属这类)。
|
|
440
440
|
const opaqueFrames = iframes.filter((f) => {
|
|
441
441
|
if (!f || f.sameOrigin) return false;
|
|
442
442
|
const box = f.box;
|
package/src/main/error_log.js
CHANGED
|
@@ -34,6 +34,8 @@ const FIELD_MAX = 4000;
|
|
|
34
34
|
|
|
35
35
|
let logFile = null;
|
|
36
36
|
let logDir = null;
|
|
37
|
+
let flightFile = null;
|
|
38
|
+
let flightSeq = 0;
|
|
37
39
|
let wroteBytes = 0;
|
|
38
40
|
let dropped = 0;
|
|
39
41
|
// 写不进去的**原因**。以前只 dropped += 1,事后只知道"少了 30 条",不知道
|
|
@@ -147,6 +149,93 @@ function readLastEntry(file) {
|
|
|
147
149
|
} catch { return null; }
|
|
148
150
|
}
|
|
149
151
|
|
|
152
|
+
// ── 黑匣子:native 崩溃瞬间"正在做什么" ───────────────────────────────────
|
|
153
|
+
//
|
|
154
|
+
// 2026-11-28 的两次崩溃(objc_retain / SIGSEGV,都在主线程的 JS 回调里,相隔
|
|
155
|
+
// 一小时多,栈一模一样)暴露了一个空白:**native 段错误不给 JS 任何机会**。
|
|
156
|
+
// 没有 uncaughtException、没有 finally、error.jsonl 里最后一行是崩溃前 2 秒的
|
|
157
|
+
// 一张心跳 —— 能证明"崩在 Electron 的视图代码里",但查不到"是哪个调用触发的",
|
|
158
|
+
// 于是每次只能在"哪个 API 最可疑"上猜。
|
|
159
|
+
//
|
|
160
|
+
// 做法:把"当前正在做什么"写进一个**固定大小、每次覆盖**的小文件。崩溃后它停在
|
|
161
|
+
// phase:'run',下一次启动读到就知道崩在哪个调用上。
|
|
162
|
+
//
|
|
163
|
+
// 为什么不是往 error.jsonl 追加一行:那样每次点击都要写盘,2MB 的滚动日志几分钟
|
|
164
|
+
// 就被冲干净,真正的现场反而没了。覆盖写一行既不会长大,也不挤掉别的日志。
|
|
165
|
+
//
|
|
166
|
+
// 开销:一次 writeFileSync(约 40µs,只进 page cache)。只挂在 WS 调用和两个
|
|
167
|
+
// 1.5s/2s 的定时器上,属于噪声级别。
|
|
168
|
+
const FLIGHT_NAME = 'inflight.txt';
|
|
169
|
+
|
|
170
|
+
function writeFlight(obj) {
|
|
171
|
+
if (!flightFile) return;
|
|
172
|
+
try {
|
|
173
|
+
fs.writeFileSync(flightFile, JSON.stringify(obj) + '\n');
|
|
174
|
+
} catch {
|
|
175
|
+
/* 黑匣子写不进去绝不影响主流程 */
|
|
176
|
+
}
|
|
177
|
+
}
|
|
178
|
+
|
|
179
|
+
function clipVal(v, n = 120) {
|
|
180
|
+
if (v === null || v === undefined) return v;
|
|
181
|
+
// 数字/布尔原样留着:tab 号变成 "7" 之后,人读日志还得自己换算,
|
|
182
|
+
// 而这类字段本来就不可能超长。
|
|
183
|
+
if (typeof v === 'number') return Number.isFinite(v) ? v : String(v);
|
|
184
|
+
if (typeof v === 'boolean') return v;
|
|
185
|
+
let s;
|
|
186
|
+
try {
|
|
187
|
+
s = typeof v === 'string' ? v : JSON.stringify(v);
|
|
188
|
+
} catch {
|
|
189
|
+
s = String(v);
|
|
190
|
+
}
|
|
191
|
+
return s.length > n ? s.slice(0, n) + '…' : s;
|
|
192
|
+
}
|
|
193
|
+
|
|
194
|
+
/**
|
|
195
|
+
* 记下"开始做某事"。返回的 seq 交给 flightEnd 收尾。
|
|
196
|
+
* @param {string} label 例如 'rpc:ui.act' / 'timer:refreshTabBar'
|
|
197
|
+
* @param {object} [detail] 少量可定位的字段(方法名、tab、url、op…)
|
|
198
|
+
*/
|
|
199
|
+
export function flightBegin(label, detail) {
|
|
200
|
+
flightSeq += 1;
|
|
201
|
+
const seq = flightSeq;
|
|
202
|
+
const d = {};
|
|
203
|
+
if (detail && typeof detail === 'object') {
|
|
204
|
+
for (const k of Object.keys(detail).slice(0, 8)) d[k] = clipVal(detail[k]);
|
|
205
|
+
}
|
|
206
|
+
writeFlight({
|
|
207
|
+
phase: 'run',
|
|
208
|
+
seq,
|
|
209
|
+
ts: nowIso(),
|
|
210
|
+
pid: process.pid,
|
|
211
|
+
uptime_ms: Math.round(process.uptime() * 1000),
|
|
212
|
+
label: String(label || ''),
|
|
213
|
+
detail: d,
|
|
214
|
+
});
|
|
215
|
+
return seq;
|
|
216
|
+
}
|
|
217
|
+
|
|
218
|
+
/** 记下"做完了"。正常退出/正常完成都应该是 idle —— 停在 run 就是崩在那一句。 */
|
|
219
|
+
export function flightEnd(seq) {
|
|
220
|
+
writeFlight({
|
|
221
|
+
phase: 'idle',
|
|
222
|
+
seq: seq === undefined ? null : seq,
|
|
223
|
+
ts: nowIso(),
|
|
224
|
+
pid: process.pid,
|
|
225
|
+
});
|
|
226
|
+
}
|
|
227
|
+
|
|
228
|
+
/** 读黑匣子(启动时用:上一轮停在 run 就说明它是崩在那一句上)。 */
|
|
229
|
+
export function readFlight() {
|
|
230
|
+
if (!flightFile) return null;
|
|
231
|
+
try {
|
|
232
|
+
const t = fs.readFileSync(flightFile, 'utf8').trim();
|
|
233
|
+
return t ? JSON.parse(t) : null;
|
|
234
|
+
} catch {
|
|
235
|
+
return null;
|
|
236
|
+
}
|
|
237
|
+
}
|
|
238
|
+
|
|
150
239
|
/**
|
|
151
240
|
* 初始化日志目录。**必须在 app ready 之前调用**,否则早期崩溃(最常见的那类)
|
|
152
241
|
* 落不了盘。
|
|
@@ -160,12 +249,15 @@ export function initErrorLog(opts) {
|
|
|
160
249
|
if (opts && Number(opts.maxBytes) > 0) maxBytes = Number(opts.maxBytes);
|
|
161
250
|
if (opts && Number(opts.keep) > 0) keepFiles = Math.max(1, Number(opts.keep));
|
|
162
251
|
logFile = path.join(dir, 'error.jsonl');
|
|
252
|
+
flightFile = path.join(dir, FLIGHT_NAME);
|
|
163
253
|
try {
|
|
164
254
|
fs.mkdirSync(dir, { recursive: true });
|
|
165
255
|
try { wroteBytes = fs.statSync(logFile).size; } catch { wroteBytes = 0; }
|
|
166
256
|
// 先看上一行:不是 shutdown 就说明上一个进程是硬退(崩溃/被 kill)。这条
|
|
167
257
|
// 判断必须在写 boot 之前做,否则读到的是自己刚写的 boot。
|
|
168
258
|
const prev = readLastEntry(logFile);
|
|
259
|
+
// 黑匣子也要在覆盖前读:上一轮停在 phase:'run' 就是"崩在这一句上"。
|
|
260
|
+
const prevFlight = readFlight();
|
|
169
261
|
// 进程边界的标记行:读日志时能一眼看出"这是哪一次启动",以及上一次
|
|
170
262
|
// 是不是异常结束(没有 shutdown 行就说明是硬退)
|
|
171
263
|
appendLine({
|
|
@@ -179,6 +271,8 @@ export function initErrorLog(opts) {
|
|
|
179
271
|
});
|
|
180
272
|
// 把"上次没正常退出"显式记一笔:比让读日志的人自己去比 boot/shutdown 更省事,
|
|
181
273
|
// 而且带上了上一个 pid / 最后一条的时间与类别,能直接对上崩溃报告。
|
|
274
|
+
// prev_inflight 是 native 崩溃唯一的指认证据 —— 有它就不用在"哪个 API 可疑"
|
|
275
|
+
// 上猜了(见上面黑匣子那段注释)。
|
|
182
276
|
if (prev && prev.kind !== 'shutdown') {
|
|
183
277
|
const prevT = Date.parse(prev.ts);
|
|
184
278
|
appendLine({
|
|
@@ -189,8 +283,12 @@ export function initErrorLog(opts) {
|
|
|
189
283
|
prev_ts: prev.ts || null,
|
|
190
284
|
prev_kind: prev.kind || null,
|
|
191
285
|
gap_ms: Number.isFinite(prevT) ? (Date.now() - prevT) : null,
|
|
286
|
+
prev_inflight: prevFlight && prevFlight.phase === 'run' ? prevFlight : null,
|
|
192
287
|
});
|
|
193
288
|
}
|
|
289
|
+
// 覆盖掉上一轮的黑匣子,别让它一直谎报"还在忙"。
|
|
290
|
+
flightBegin('boot');
|
|
291
|
+
flightEnd();
|
|
194
292
|
} catch {
|
|
195
293
|
logFile = null;
|
|
196
294
|
}
|
|
@@ -315,6 +413,8 @@ export function recentErrors(limit = 50, kind = null) {
|
|
|
315
413
|
|
|
316
414
|
/** 正常退出时补一行收尾 —— 日志里没有 shutdown 行 = 上次是硬退。 */
|
|
317
415
|
export function markShutdown(reason) {
|
|
416
|
+
// 先把黑匣子置 idle:正常退出的进程不该在下一次启动时被当成"崩在某句上"。
|
|
417
|
+
flightEnd(null);
|
|
318
418
|
recordError('shutdown', { reason: reason || 'normal' });
|
|
319
419
|
}
|
|
320
420
|
|
|
@@ -322,6 +422,8 @@ export function markShutdown(reason) {
|
|
|
322
422
|
export function __resetForTests() {
|
|
323
423
|
logFile = null;
|
|
324
424
|
logDir = null;
|
|
425
|
+
flightFile = null;
|
|
426
|
+
flightSeq = 0;
|
|
325
427
|
wroteBytes = 0;
|
|
326
428
|
dropped = 0;
|
|
327
429
|
writeError = null;
|
package/src/main/index.js
CHANGED
|
@@ -12,13 +12,13 @@ import { config } from '../shared/config.js';
|
|
|
12
12
|
import mediaDoc from '../shared/media_doc.cjs';
|
|
13
13
|
import { parseWatchdogTargets, isWatchdogEnabled } from '../shared/watchdog.js';
|
|
14
14
|
import { wrapSetActive } from '../shared/tab_hooks.js';
|
|
15
|
-
import { initErrorLog, recordError, markShutdown, getLogPath, recordDiag } from './error_log.js';
|
|
15
|
+
import { initErrorLog, recordError, markShutdown, getLogPath, recordDiag, flightBegin, flightEnd } from './error_log.js';
|
|
16
16
|
import errorBanner from '../shared/error_banner.cjs';
|
|
17
17
|
// .cjs 一律默认导入:ESM 从 .cjs 做具名导入依赖 cjs-module-lexer 静态识别,
|
|
18
18
|
// 而 tests/test_imports.js 只认 ESM `export` 语法,会误报"没有导出它"。全项目约定
|
|
19
19
|
// 用默认导入(见 blank_page.cjs / error_banner.cjs),这里保持一致。
|
|
20
20
|
import viewLiveness from '../shared/view_liveness.cjs';
|
|
21
|
-
const { isAlive, liveness } = viewLiveness;
|
|
21
|
+
const { isAlive, liveness, frameAlive } = viewLiveness;
|
|
22
22
|
import { classifyShowReason, describeShowUrl } from '../shared/window_show.js';
|
|
23
23
|
// 地址栏跟随的挂载状态机(幂等 wire)。抽成模块是因为它原来写在闭包里,
|
|
24
24
|
// 判据只能 grep 源码 —— 实测监听累到 3 个时测试照样全绿。
|
|
@@ -244,7 +244,11 @@ function createTabBarView() {
|
|
|
244
244
|
* @param {boolean} force 渲染进程刚死时为 true,跳过"最小间隔"节流(但仍受上限约束)。
|
|
245
245
|
*/
|
|
246
246
|
function ensureTabBarAlive(force = false) {
|
|
247
|
-
|
|
247
|
+
// isAlive 只管"对象还在",管不了"这一帧还能不能收脚本":渲染进程崩过之后
|
|
248
|
+
// webContents 仍在(isDestroyed=false)但 mainFrame 已 detached,此时标签栏
|
|
249
|
+
// 是一片空白却永远不会被重建 —— 两个定时器每 1.5s/2s 往里撞一次,实测刷出
|
|
250
|
+
// 3482 条 "Render frame was disposed"。两种形态都要判死才会自愈。
|
|
251
|
+
if (isAlive(tabBarView) && frameAlive(tabBarView)) return tabBarView;
|
|
248
252
|
if (!mainWindow || mainWindow.isDestroyed()) return null;
|
|
249
253
|
const now = Date.now();
|
|
250
254
|
if (!force && now - tabBarRebuildAt < TAB_BAR_REBUILD_MIN_GAP) return null;
|
|
@@ -1216,8 +1220,20 @@ function StartNetworkWatchdog() {
|
|
|
1216
1220
|
}
|
|
1217
1221
|
|
|
1218
1222
|
function refreshTabBar() {
|
|
1219
|
-
|
|
1223
|
+
// frameAlive 而不是 isAlive:渲染进程崩过之后 webContents 还在、mainFrame 已
|
|
1224
|
+
// detached,这时 executeJavaScript 必然失败("Render frame was disposed")。
|
|
1225
|
+
// 判死的活儿交给 ensureTabBarAlive 去重建,别在这儿每 2s 撞一次。
|
|
1226
|
+
if (!isAlive(tabBarView) || !frameAlive(tabBarView)) {
|
|
1227
|
+
ensureTabBarAlive(false);
|
|
1228
|
+
return;
|
|
1229
|
+
}
|
|
1230
|
+
const flight = flightBegin('timer:refreshTabBar');
|
|
1231
|
+
try {
|
|
1220
1232
|
tabBarView.webContents.executeJavaScript('renderTabs && renderTabs()').catch(() => {});
|
|
1233
|
+
} catch (_) {
|
|
1234
|
+
/* 视图在这几毫秒内又失效:交给下一轮 ensureTabBarAlive */
|
|
1235
|
+
} finally {
|
|
1236
|
+
flightEnd(flight);
|
|
1221
1237
|
}
|
|
1222
1238
|
}
|
|
1223
1239
|
|
|
@@ -1358,12 +1374,16 @@ function pushNavState() {
|
|
|
1358
1374
|
// stderr 刷一条没意义的错误。它加载完成后会自己 invoke('nav:state') 拉一次,
|
|
1359
1375
|
// 所以加载中直接跳过本次推送即可,1.5s 后下一轮再推。
|
|
1360
1376
|
try { if (view.webContents.isLoading()) return; } catch (_) { return; }
|
|
1377
|
+
// 同 refreshTabBar:帧已经 detach 时不要再往里发脚本。
|
|
1378
|
+
if (!frameAlive(view)) return;
|
|
1361
1379
|
const state = buildNavState();
|
|
1380
|
+
const flight = flightBegin('timer:pushNavState');
|
|
1362
1381
|
try {
|
|
1363
1382
|
view.webContents.executeJavaScript(
|
|
1364
1383
|
'window.__onNavState && window.__onNavState(' + JSON.stringify(state) + ')'
|
|
1365
1384
|
).catch(() => {});
|
|
1366
1385
|
} catch (_) { /* 视图在这几毫秒内又失效:交给下一轮自愈 */ }
|
|
1386
|
+
finally { flightEnd(flight); }
|
|
1367
1387
|
}
|
|
1368
1388
|
|
|
1369
1389
|
/**
|