@glittering0717/ai-browser 2.5.6 → 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.
@@ -1,8 +1,9 @@
1
1
  ---
2
2
  name: content-publish
3
3
  description: >-
4
- 适用于用户要求"把内容/文章发布到某个平台(CSDN、知乎、掘金、其他博客/社区等)"、或用编辑器录入并提交内容的自动化发布/提交流程任务。触发词:发布到、发博客、发文章、submit/publish this post、发布内容。
5
- 注意边界:若用户只是想编辑某个已有页面而非提交发布,用 browse_navigate / browse_act 直接处理即可,不需本 skill 的发布校验步骤。
4
+ content-publish —— 只在「要把内容提交到某个平台」时用我:CSDN / 知乎 / 掘金 / 公众号 / 其它博客社区。
5
+ 触发词:发布到、发到、发博客、发帖、发一篇、投稿、发出去、上传到平台、帮我发。
6
+ 不适用:只编辑不提交 → ai-browser 的 browse_act;只读文章 → read-webpage 技能。
6
7
  ---
7
8
 
8
9
  # 内容发布 / 提交流程(content-publish)
@@ -54,7 +55,13 @@ description: >-
54
55
  | 审核 / 待审核 | 进入人工/系统审核 |
55
56
  | 报错 toast / message_appeared 事件体 | 失败,需读取提示原文 |
56
57
 
57
- ## 边界与替代
58
+ ## 不适用(交给谁)
59
+ - 只是编辑已有页面、不提交 → `browse_navigate` / `browse_act`,不需要发布校验
60
+ - 只是读一篇文章 → `read-webpage` 技能
61
+ - 还不知道正文从哪来(要先抓文章内容)→ 先用 `ai-browser` 取,再回来发布
62
+ - 目标是某个接口而不是页面 → `ai-browser` 的 `references/network.md`
63
+
64
+ ## 操作边界
58
65
  - skill 不保存账号/密码,登录与验证码需用户配合。
59
66
  - 若某平台按钮文案不同,用 `browse_get_tree` 的 label 动态定位,不要硬编码选择器。
60
67
  - 发布属于不可逆操作:点击前可用 `browse_get_tree` 确认拿到的确实是发布按钮(label 含"发布/提交"),避免误点。
@@ -1,8 +1,9 @@
1
1
  ---
2
2
  name: read-webpage
3
3
  description: >-
4
- 适用于需要阅读、理解或总结某个网页的正文文章内容(标题 + 段落)的任务,尤其是新闻/博客/公众号等文章型页面。触发词:读这篇文章、阅读该页、总结内容、提炼要点、这篇文章讲了什么、extract the article、summarize this page。
5
- 注意边界:若只需读取页面上的控件/标签/按钮/少量文本,请用 browse_get_tree,不要用本 skill;目标是交互(登录、表单、评论)而非读正文时也不要用本 skill。
4
+ read-webpage —— 只在「要把一整篇文章的正文取出来」时用我:标题 + 段落,新闻/博客/公众号/掘金这类页面。
5
+ 触发词:读这篇文章、看看这篇、帮我读一下、这页讲了啥、这篇写的是什么、提取正文、翻译这页、总结这篇。
6
+ 不适用:读控件 / 按钮 / 少量文本 → browse_get_tree;要交互(登录 / 表单 / 评论 / 发布)→ ai-browser 主循环。
6
7
  ---
7
8
 
8
9
  # 网页正文提取(read-webpage)
@@ -46,7 +47,13 @@ description: >-
46
47
  - 输出为标题 + 段落数组(同一套提取脚本主体),可直接交给用户阅读或总结。
47
48
  - 空结果时明确提示,不强行拼接垃圾文本。
48
49
 
49
- ## 边界与替代
50
+ ## 不适用(交给谁)
51
+ - 只要读控件 / 标签 / 按钮 / 少量文本 → `browse_get_tree`,不要提正文
52
+ - 目的是交互(登录、填表、评论、发布)→ 回 `ai-browser` 的主循环
53
+ - 要的是接口返回的 JSON,而不是页面上的字 → `ai-browser` 的 `references/network.md`
54
+ - 页面根本还没打开、不知道在哪 → 先用 `browse_navigate` 过去(`ai-browser` 主循环)
55
+
56
+ ## 技术边界
50
57
  - 只用于"正文文章"。登录框、评论、表格、导航等非文章内容走 `browse_get_tree` / `browse_act`。
51
58
  - 不分页/不处理懒加载(动态新增段落不会出现);长文分段处理或提示用户。
52
59
  - 静默失败判据:若取回的 title 与 paras 均为空,判为"非文章页"。
@@ -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,超星泛雅学习页):树只有 27 个节点、13 个可操作,探针**自己
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,不算。这是"树薄"最常见的真实原因(泛雅、B站图文、掘金都属这类)。
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;
@@ -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
- if (isAlive(tabBarView)) return tabBarView;
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
- if (isAlive(tabBarView)) {
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
  /**
@@ -90,7 +90,7 @@ const server = new Server(
90
90
 
91
91
  // Tool definitions — curated minimal MCP_TOOLS (see mcp_tools.js). Kept small
92
92
  // to reduce per-message token cost; low-frequency/flow capabilities live in
93
- // skills/ (read-webpage, web-network-monitor).
93
+ // skills/ (ai-browser + read-webpage / content-publish) and its references/.
94
94
  server.setRequestHandler(ListToolsRequestSchema, async () => ({
95
95
  tools: MCP_TOOLS
96
96
  }));
@@ -314,8 +314,11 @@ server.setRequestHandler(CallToolRequestSchema, async (request) => {
314
314
  return { content: [{ type: 'text', text: JSON.stringify(result) }] };
315
315
  }
316
316
  if (op === 'configure') {
317
+ // reload 必须转发:hook 对"安装之前已经画完"的内容无能为力,重载是拿到
318
+ // 完整绘制历史的唯一办法(hard-pages.md 就是按这个教 agent 的)。
319
+ // 曾被漏在这里 —— schema 也没声明,于是文档教的"现装现读"静默无效。
317
320
  const result = await wsClient.call('ui.canvas_configure', {
318
- tab: args.tab, mode: args.mode, clear: args.clear,
321
+ tab: args.tab, mode: args.mode, clear: args.clear, reload: args.reload,
319
322
  });
320
323
  return { content: [{ type: 'text', text: JSON.stringify(result) }] };
321
324
  }
@@ -415,8 +418,9 @@ async function main() {
415
418
  const stale = skillMod.drift();
416
419
  if (stale.length) {
417
420
  const s = stale[0];
421
+ const why = s.contentOnly ? `changed (still ${VERSION})` : `${s.from} -> ${VERSION}`;
418
422
  console.error(
419
- `[mcp] skills out of date (${s.target}/${s.skill} ${s.from} -> ${VERSION})` +
423
+ `[mcp] skills out of date (${s.target}/${s.skill} ${why})` +
420
424
  (stale.length > 1 ? ` and ${stale.length - 1} more` : '') +
421
425
  ' — run `ai-browser skill install` to refresh'
422
426
  );
@@ -306,7 +306,8 @@ export const MCP_TOOLS = [
306
306
  since_seq: { type: 'integer', description: 'read: cursor from pagination.next_seq.' },
307
307
  limit: { type: 'integer', description: 'read: page size (default 200, max 1000).' },
308
308
  mode: { type: 'string', enum: ['off', 'semantic', 'trace'], description: 'configure: recording mode.' },
309
- clear: { type: 'boolean', description: 'configure: drop retained calls.' }
309
+ clear: { type: 'boolean', description: 'configure: drop retained calls.' },
310
+ reload: { type: 'boolean', description: 'configure: reload to record earlier draws.' }
310
311
  },
311
312
  required: ['operation']
312
313
  }
@@ -348,7 +349,7 @@ export const MCP_TOOLS = [
348
349
  {
349
350
  name: 'browse_repaint',
350
351
  title: 'Force repaint',
351
- description: "Force the compositor to redraw a tab's BrowserView when the window shows a stale page; returns repaint_count so the repaint is provable.",
352
+ description: "Force the compositor to redraw a tab's BrowserView when the window shows a stale page; returns repaint_count.",
352
353
  annotations: { readOnlyHint: false, destructiveHint: false, openWorldHint: false },
353
354
  inputSchema: {
354
355
  type: 'object',
@@ -92,7 +92,7 @@ import docCoverage from '../shared/doc_coverage.js';
92
92
  import refGuard from '../shared/ref_guard.cjs';
93
93
  // 错误日志:导航失败(界面会显示错误页)必须落盘 —— load_failed 只是内存里的
94
94
  // 一次广播,进程一退出就再也查不到"哪个 tab、哪个网址、什么错误码"。
95
- import { recordError } from './error_log.js';
95
+ import { recordError, flightBegin, flightEnd } from './error_log.js';
96
96
  // navigate 的完成信号(commit | domcontentloaded | load):默认不再是 load ——
97
97
  // SPA 永不 fire load,把它当完成信号等于把"页面可用"报成"超时"。
98
98
  import navWait from '../shared/nav_wait.cjs';
@@ -660,7 +660,7 @@ class PageManager {
660
660
  // 这里只防 unhandled。
661
661
  view.webContents.loadURL(url).catch(() => {});
662
662
  };
663
- // ⚠️ **必须等垫片登记完再导航**(2026-10-20 修,超星"进入学习"第二层)。
663
+ // ⚠️ **必须等垫片登记完再导航**(2026-10-20 修,某教学平台"进入学习"第二层)。
664
664
  //
665
665
  // 原来这里直接 loadURL。看上去时序够用(站点 ajax 往返几十毫秒,
666
666
  // 而 about:blank 的 did-finish-load 通常更早),但那是**赌**:
@@ -1197,7 +1197,7 @@ class PageManager {
1197
1197
  /**
1198
1198
  * 下载开始了 —— 如果"这个 tab 就是为它而开的",当场把它换成结果页。
1199
1199
  *
1200
- * 事故现场(2026-10-27,沧州教师继续教育网"证书下载"):站点用新标签打开
1200
+ * 事故现场(2026-10-27,省级教师继续教育平台"证书下载"):站点用新标签打开
1201
1201
  * `.../xxx.png`,服务端带 `Content-Disposition: attachment`,于是 Electron
1202
1202
  * 把它当下载 —— **导航永远不会提交**,那个标签页停在 loading.html 上:
1203
1203
  * 一句「正在打开…」+ 一坨 URL,永远不变。文件其实已经落盘,但界面上
@@ -1642,7 +1642,7 @@ class PageManager {
1642
1642
  * 每个跨进程帧里可见文字的字符数(帧那边在 frame_read_source 里已经算过)。
1643
1643
  *
1644
1644
  * 为什么必须分成"主文档 + 帧"两半:innerText 不跨 iframe,把两者混在一个
1645
- * 数里,任何一侧读漏都会被另一侧的平均值盖住 —— 泛雅那次就是这样,
1645
+ * 数里,任何一侧读漏都会被另一侧的平均值盖住 —— 某教学平台那次就是这样,
1646
1646
  * 主文档读得很好(外壳 100%),正文一个字没有,而没有任何数字表达这件事。
1647
1647
  */
1648
1648
  _annotateCoverage(res, frames, opts) {
@@ -1907,10 +1907,18 @@ class PageManager {
1907
1907
  const wc = view && view.webContents;
1908
1908
  if (!wc || wc.isDestroyed()) return null;
1909
1909
  let img = null;
1910
+ // 黑匣子:capturePage 是主进程里最"原生"的一条路(拿视图合成表面 → NSImage)。
1911
+ // 2026-11-28 那两次 objc_retain 段错误都在 JS 回调里,capturePage 与
1912
+ // addBrowserView 是两个头号嫌疑,谁都不标就永远只能猜。
1913
+ const flight = flightBegin('native:capturePage', {
1914
+ tab: (() => { try { return this._tabIdOfWebContents(wc); } catch { return null; } })(),
1915
+ });
1910
1916
  try {
1911
1917
  img = await withDeadline(wc.capturePage(), this._surfaceShotBudgetMs(), 'capturePage');
1912
1918
  } catch (_) {
1913
1919
  return null;
1920
+ } finally {
1921
+ flightEnd(flight);
1914
1922
  }
1915
1923
  if (!img || typeof img.isEmpty !== 'function' || img.isEmpty()) return null;
1916
1924
  let buf = null;
@@ -2280,7 +2288,7 @@ class PageManager {
2280
2288
  states: [],
2281
2289
  actions: [],
2282
2290
  // 门节点带上**绝对** src:树里出现的东西,调用方就应该能直接用。
2283
- // 相对地址(/mooc2-ans/...)没法喂给 ui.new_tab / ui.navigate,
2291
+ // 相对地址(/app/...)没法喂给 ui.new_tab / ui.navigate,
2284
2292
  // 等于把"我知道内容在哪"变成一句废话。
2285
2293
  ...(dto.url ? { src: dto.url } : {}),
2286
2294
  bounds: { x: 0, y: 0, width: 0, height: 0 },
@@ -4765,7 +4773,7 @@ return {ok:true,name:file.name,size:file.size,via:via,host_sel:hostSel,clicked:c
4765
4773
  // 这段等待原本是纯白的 about:blank。快站约 4s,慢站实测 70s(GitHub
4766
4774
  // OAuth 直到 ERR_CONNECTION_TIMED_OUT 才切到错误页)—— 用户和 agent
4767
4775
  // 看到的都是"弹出来一个空白页面",和"垫片没把导航发出去"那个老 bug
4768
- // (超星"进入学习")在现象上完全一样,无法区分。
4776
+ // (某教学平台"进入学习")在现象上完全一样,无法区分。
4769
4777
  // loading.html 只做展示(目标地址 + 转圈),不发请求不跳转,真实导航
4770
4778
  // 仍由上面的 proceed 发起。无目标 URL 的占位 tab(window.open("") 的
4771
4779
  // 老站模式)保持 about:blank:它本来就要停在这里等 location 赋值。
@@ -5531,10 +5539,16 @@ return {ok:true,name:file.name,size:file.size,via:via,host_sel:hostSel,clicked:c
5531
5539
  closeTab(tabId) {
5532
5540
  const view = this._getView(tabId);
5533
5541
  if (!view) return false;
5534
- this.window.removeBrowserView(view);
5535
- if (view.webContents && !view.webContents.isDestroyed()) {
5536
- try { view.webContents.debugger.detach(); } catch(e) {}
5537
- view.webContents.close();
5542
+ // 黑匣子:摘视图 + 销毁 webContents 是另一处"主进程动原生对象"的地方。
5543
+ const flight = flightBegin('native:closeTab', { tab: tabId });
5544
+ try {
5545
+ this.window.removeBrowserView(view);
5546
+ if (view.webContents && !view.webContents.isDestroyed()) {
5547
+ try { view.webContents.debugger.detach(); } catch(e) {}
5548
+ view.webContents.close();
5549
+ }
5550
+ } finally {
5551
+ flightEnd(flight);
5538
5552
  }
5539
5553
  this.tabs.delete(tabId);
5540
5554
  this._forgetTab(tabId);
@@ -5689,7 +5703,12 @@ return {ok:true,name:file.name,size:file.size,via:via,host_sel:hostSel,clicked:c
5689
5703
  if (!view || !this.window) return;
5690
5704
  try {
5691
5705
  const attached = this.window.getBrowserViews ? this.window.getBrowserViews() : [];
5692
- if (attached.indexOf(view) < 0) this.window.addBrowserView(view);
5706
+ if (attached.indexOf(view) < 0) {
5707
+ // 黑匣子:addBrowserView 是"把一个 NSView 挂进窗口",AppKit 这边一旦拿到
5708
+ // 失效对象就是 native 段错误,JS 侧什么都记不到。
5709
+ const flight = flightBegin('native:addBrowserView');
5710
+ try { this.window.addBrowserView(view); } finally { flightEnd(flight); }
5711
+ }
5693
5712
  } catch (_) { /* 窗口正在销毁 */ }
5694
5713
  }
5695
5714
 
@@ -1,12 +1,12 @@
1
1
  // window_open_shim_source.js — 注入页面主 world 的 window.open 兼容垫片源码
2
2
  //
3
- // 背景:站点惯用法(超星专技平台等大量老站)是
3
+ // 背景:站点惯用法(某网课平台等大量老站)是
4
4
  // var w = window.open("", "_blank"); // 先开一个新页面
5
5
  // w.location = res.url; // 再把真实地址赋给它
6
6
  // 主进程的 setWindowOpenHandler 对 window.open 一律 deny(改为自建 tab),
7
7
  // deny 之后 window.open 返回 null,页面再赋 w.location 直接抛 TypeError ——
8
8
  // 用户看到的就是一个光秃秃的 about:blank 标签,站点逻辑静默断裂。
9
- // (实测:pxsxzj.xidian.edu.cn「进入学习」,2026-10-19。)
9
+ // (实测:某网课平台点「进入学习」,2026-10-19。)
10
10
  //
11
11
  // ⚠️ 第二层根因(同一天发现,比第一层更隐蔽):光让 window.open 返回一个
12
12
  // 非 null 的对象还不够。真实 Window 的 location 是 [LegacyUnforgeable] +
@@ -10,7 +10,7 @@ import actParams from '../shared/act_params.cjs';
10
10
  import findRefUtil from '../shared/find_ref.cjs';
11
11
  // 错误日志:RPC 层异常必须落盘(此前只回一句 JSON-RPC error,现场永久丢失),
12
12
  // 每次调用的摘要进环形缓冲,作为崩溃时的上下文。
13
- import { recordError, noteCall, recentErrors } from './error_log.js';
13
+ import { recordError, noteCall, recentErrors, flightBegin, flightEnd } from './error_log.js';
14
14
  // 默认目标标签页的判据(explicit > session > active > first),理由与两条不可
15
15
  // 退让的约束见 shared/tab_route.cjs 顶部(多 agent 并用时"目标被别人改掉")。
16
16
  import tabRoute from '../shared/tab_route.cjs';
@@ -265,6 +265,15 @@ export function startWSServer(pageManager, port = config.wsPort, onQuit = null,
265
265
  };
266
266
 
267
267
  const t0 = Date.now();
268
+ // 黑匣子:native 崩溃(段错误)不给 JS 任何收尾机会,只有这个"当前在忙什么"
269
+ // 的小文件能留下指认证据。收尾在 finally 里,早退分支也覆盖到。
270
+ const flight = flightBegin('rpc:' + method, {
271
+ method,
272
+ tab: params.tab,
273
+ url: params.url,
274
+ target: params.target,
275
+ op: params.operation,
276
+ });
268
277
  // ---- 自动工作区 ----------------------------------------------------
269
278
  //
270
279
  // agent 第一次要动页面、而它还没指定过任何目标时,给它一页**自己的**空标签,
@@ -1106,6 +1115,10 @@ export function startWSServer(pageManager, port = config.wsPort, onQuit = null,
1106
1115
  stack: String((e && e.stack) || '').slice(0, 8000),
1107
1116
  });
1108
1117
  send({ jsonrpc: '2.0', id, error: { code: -32603, message: errMsg } });
1118
+ } finally {
1119
+ // 正常返回 / 异常返回 / 早退都算"这一句做完了";只有进程在这中间被
1120
+ // native 段错误打掉时,黑匣子才会停在 run 上。
1121
+ flightEnd(flight);
1109
1122
  }
1110
1123
  });
1111
1124
 
@@ -742,7 +742,7 @@ function extractTree() {
742
742
  opaqueFrames.push({
743
743
  id: el.id || null,
744
744
  // 绝对地址(el.src 会被解析成绝对 URL)。相对地址对调用方没用:
745
- // 树里写着 /mooc2-ans/xxx,agent 拿它去 navigate 只会失败。
745
+ // 树里写着 /app/xxx,agent 拿它去 navigate 只会失败。
746
746
  src: (el.src || '').trim() || el.getAttribute("src") || null,
747
747
  width: Math.round(ifrRect.width || 0),
748
748
  height: Math.round(ifrRect.height || 0)
@@ -1544,7 +1544,7 @@ function extractPageContext() {
1544
1544
  buttons: document.querySelectorAll("button").length,
1545
1545
  links: document.querySelectorAll("a[href]").length,
1546
1546
  // 没有 href 的锚点(onclick / JS 驱动)。它们仍然是可点目标,而 a[href]
1547
- // 数不到 —— 超星泛雅的章节条目就是这一类。只报 links 会让人以为这页
1547
+ // 数不到 —— 某教学平台的章节条目就是这一类。只报 links 会让人以为这页
1548
1548
  // 一个链接都没有(实测该页 links=2、links_without_href=6)。
1549
1549
  links_without_href: (function() {
1550
1550
  try { return document.querySelectorAll("a:not([href])").length; } catch(e) { return 0; }
@@ -6,7 +6,7 @@
6
6
  <!--
7
7
  download.html — 「下载结果」页。
8
8
 
9
- 为什么需要它(2026-10-27,沧州教师继续教育网"证书下载"):
9
+ 为什么需要它(2026-10-27,省级教师继续教育平台"证书下载"):
10
10
 
11
11
  站点用新标签打开一个 `Content-Disposition: attachment` 的地址(zip/dmg/exe,
12
12
  或者带 download 属性的图片)。这种导航**永远不会提交** —— 那个标签页于是
@@ -220,7 +220,7 @@ function buildIdentity(opts = {}) {
220
220
  // Function.prototype.toString 就能看见。所以它们默认**不开**,并且支持三种写法:
221
221
  // off / 0 / 空 → 全关
222
222
  // on / 1 / all → 全开
223
- // a.com,b.chaoxing.com → 只在这些域(含子域)开
223
+ // a.com,example.com → 只在这些域(含子域)开
224
224
  function parseHostSwitch(value) {
225
225
  const raw = (value === undefined || value === null) ? '' : String(value).trim();
226
226
  if (!raw) return { mode: 'off', hosts: [] };
@@ -1,7 +1,7 @@
1
1
  // src/shared/doc_coverage.js — 「这棵树读到了多少页面文字」的度量
2
2
  //
3
3
  // ============ 为什么要有它 ============
4
- // 2026-10-19 的泛雅事故里,默认语义树 27 个节点、13 个可操作,而整门课的章节
4
+ // 2026-10-19 的某教学平台事故里,默认语义树 27 个节点、13 个可操作,而整门课的章节
5
5
  // 列表一个字都不在树里。当时没有任何一个数字能表达这件事:调用方看到的是
6
6
  // "merged / frames_read:1",以及 capabilities 的一句"the UI is largely
7
7
  // canvas-rendered"。**"读到了"从来不是一个可测量的结论。**
@@ -27,7 +27,7 @@
27
27
  * 这些角色的 label 是**元数据**,不是页面上渲染出来的文字。
28
28
  *
29
29
  * 为什么必须排除:分母用 `innerText` 量(浏览器自己算的"看得见的字"),
30
- * 分子就得用同一把尺子。实测泛雅页面上:
30
+ * 分子就得用同一把尺子。实测某教学平台页面上:
31
31
  * - `<img alt="Logo">` 的 alt 不在 innerText 里;
32
32
  * - `<iframe name="frame_content-zj">` 的 name 更不在 —— 而树的合并逻辑
33
33
  * 会给同一个 iframe 建三个描述节点(iframe_body / iframe / Iframe 闸门),
@@ -76,7 +76,7 @@ export function sumLabelChars(tree) {
76
76
  //
77
77
  // 为什么不是"把所有 label 加起来":DOM 抽取器会给容器节点也写 label,而且
78
78
  // 那 label 就是它里面的全部文字(`<div>课程门户 链接</div>`)。全加一遍等于
79
- // 同一句话数了三次 —— 实测泛雅页 tree_chars 547 vs 页面 185,覆盖率直接
79
+ // 同一句话数了三次 —— 实测某教学平台页 tree_chars 547 vs 页面 185,覆盖率直接
80
80
  // 溢出到 100%,这个数字就废了。
81
81
  //
82
82
  // 为什么不是"只数叶子":图标链接 `<a>课程门户<i/></a>` 有子节点(空的 i),
@@ -107,7 +107,7 @@ const clamp01 = (x) => (x < 0 ? 0 : x > 1 ? 1 : x);
107
107
  /**
108
108
  * 分子超过分母这么多,就不是"读得好",是**分母漏了一块**。
109
109
  *
110
- * 为什么要留这个判据:这个指标的第一版就在这里撒过谎。泛雅页分子 547、分母 185,
110
+ * 为什么要留这个判据:这个指标的第一版就在这里撒过谎。某教学平台页分子 547、分母 185,
111
111
  * 我当时的处理是钳到 1、当没事发生。可"分子大于分母"本身就是一个**测量结论**:
112
112
  * 树里数出来的字比页面上能看见的还多,只可能是分母少统计了一个承载文字的
113
113
  * 表面(同源子帧 / shadow DOM / canvas),或者是分子在重复计数。
@@ -217,7 +217,7 @@ export const LOW_COVERAGE = 0.9;
217
217
  * 绝对缺口的下限(字)。只负责"别为一两个字打扰调用方",不负责判断严重程度 ——
218
218
  * 严重程度由比例闸门说。
219
219
  *
220
- * 这个数字的历史:最初是 `page_chars < 200 → 不提示`(把泛雅 185 字自己排除了),
220
+ * 这个数字的历史:最初是 `page_chars < 200 → 不提示`(把某教学平台 185 字自己排除了),
221
221
  * 后来是 20(把 /sr-only.html 的 73% 缺口静音了),现在 5。详见 missingEnough。
222
222
  */
223
223
  export const MIN_MISSING_CHARS = 5;
@@ -226,7 +226,7 @@ export const MIN_MISSING_CHARS = 5;
226
226
  * 这个页面"漏够了没有"。
227
227
  *
228
228
  * 这里换过三版判据,每一版都是被实测推翻的:
229
- * 1. `page_chars < 200 → 静音`:把泛雅(185 字)自己排除了。
229
+ * 1. `page_chars < 200 → 静音`:把某教学平台(185 字)自己排除了。
230
230
  * 2. `缺 ≥ 20 字`:把 /sr-only.html(22 字页面漏 16 字,漏 73%)静音了。
231
231
  * 3. 现在:比例闸门已经抬到 0.9,缺口天然是成比例的;绝对值只留一个
232
232
  * "别为一两个字打扰调用方"的下限。
@@ -43,7 +43,7 @@ function shouldAutoAx(summary) {
43
43
  /**
44
44
  * 把"读了几个帧、并进去多少东西、帧里还有多少字没进树"算成可核对的数字。
45
45
  *
46
- * 存在的理由(泛雅事故):describeAutoAx 的 `merged` 判据是
46
+ * 存在的理由(某教学平台事故):describeAutoAx 的 `merged` 判据是
47
47
  * `frames.length > 0` —— 也就是"我确实拼进去了一些节点"。实测那个页面上拼进
48
48
  * 去的只有一个搜索框,正文(章节列表)一个字都没有,回执却是
49
49
  * `{auto_ax:'merged', frames_read:1}`。调用方看到 merged 会认为"内容读到了",