@glittering0717/ai-browser 2.4.1 → 2.4.3

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.
@@ -77,6 +77,11 @@ export const VALID_METHODS = [
77
77
  'ui.snapshot',
78
78
  'ui.diff',
79
79
  'ui.capabilities',
80
+ // 「这个画布应用的对象模型在哪、里面有什么」。
81
+ // capabilities 扫的是 window:实例关在闭包里时它会给出**假阴性**(实测
82
+ // suxieban=fabric、yunser=DrawBoard 都被判成"没有模型")。这条补那一步,
83
+ // 也作为 capabilities{deep:true} 的实现。
84
+ 'ui.app_model',
80
85
  'ui.evaluate',
81
86
  'ui.subscribe',
82
87
  'ui.unsubscribe',
@@ -2,4 +2,4 @@
2
2
  // Kept in JS (not imported from package.json) to avoid Node import-attribute
3
3
  // (JSON module) compatibility issues inside Electron. package.json "version"
4
4
  // is manually synced to this value; tests assert they match.
5
- export const VERSION = '2.4.1';
5
+ export const VERSION = '2.4.3';
@@ -0,0 +1,74 @@
1
+ // shared/view_liveness.cjs — "这个 BrowserView 现在还能不能碰"的唯一判定口径。
2
+ //
3
+ // 事故(2026-10-30,用户报"又白屏了",截图:标题栏正常、内容全白、底部一条深红横幅、
4
+ // 左侧露一小块橙棕):主进程在 22 次 uncaught_exception 里反复抛
5
+ // Cannot read properties of undefined (reading 'isDestroyed')
6
+ // at pushNavState (index.js) ← setInterval(pushNavState, 1500)
7
+ //
8
+ // 根因是 Electron 的一个反直觉行为(用真 Electron 探针实测,见 git 提交说明):
9
+ // - webContents.close() / destroy() 之后,BrowserView 对象**还在**,但
10
+ // view.webContents 变成 undefined —— 此时 `view.webContents.isDestroyed()`
11
+ // 直接抛 TypeError。
12
+ // - 渲染进程崩溃(render-process-gone)之后,view.webContents**还在**,
13
+ // isDestroyed() 也返回 false,但内容不再渲染(视图区域空白),reload() 能救回。
14
+ //
15
+ // 也就是说"视图可能失效"有两种形态,任何一处裸写 `view.webContents.isDestroyed()`
16
+ // 都会在第一种形态下击穿主进程。而这个 HK 项目的地址栏/标题由 setInterval 每 1.5s
17
+ // 无条件重推一次 —— 一旦 tabBarView 悬空,就变成每 1.5s 崩一次的死亡螺旋:
18
+ // 崩溃 → uncaughtException → reportFatal → showErrorBanner → layoutWithBanner
19
+ // → 又碰到悬空视图 → 二次崩溃 → 进程半死(端口还在 listen 但 WS 握手完不成)。
20
+ //
21
+ // 这份模块只做一件事:给一个"可能是 BrowserView"的对象,回答
22
+ // "它现在有没有一个活着、可安全调用的 webContents?"
23
+ // 判定与"怎么救"分开 —— 救(重建/reload/收横幅)有副作用,属于调用方职责,
24
+ // 且必须有上限,不能在纯函数里做。
25
+ //
26
+ // 为什么必须是纯函数:node:electron 在 vitest 里 import 会炸,index.js 整份没法单测。
27
+ // 把这条判定抽出来,才能用假对象把"undefined / 抛异常 / isDestroyed=true"三种形态
28
+ // 一次性钉死 —— 否则这类 bug 永远只能靠真机偶发复现。
29
+
30
+ 'use strict';
31
+
32
+ /**
33
+ * 视图是否"活着且可安全使用"。
34
+ *
35
+ * 覆盖三种失效形态(都用真 Electron 或等价假对象实测):
36
+ * 1. view 本身是 null/undefined → false
37
+ * 2. view.webContents 是 undefined/null → false(close/destroy 后,正是事故形态)
38
+ * 3. webContents.isDestroyed() === true → false
39
+ * 4. 读取 webContents / 调 isDestroyed 抛异常 → false(宁可判死,绝不让异常冒出去)
40
+ *
41
+ * @param {object} view 可能是 BrowserView 的东西
42
+ * @returns {boolean}
43
+ */
44
+ function isAlive(view) {
45
+ if (!view) return false;
46
+ try {
47
+ const wc = view.webContents;
48
+ if (!wc) return false;
49
+ if (typeof wc.isDestroyed !== 'function') return false;
50
+ return !wc.isDestroyed();
51
+ } catch (_) {
52
+ return false;
53
+ }
54
+ }
55
+
56
+ /**
57
+ * 失效的"原因",供日志/回执区分"悬空"与"已销毁",避免把两种形态混为一谈
58
+ * (它们的救法不同:悬空必须重建 BrowserView,已销毁可考虑 reload)。
59
+ *
60
+ * @param {object} view
61
+ * @returns {'ok'|'no-view'|'no-webcontents'|'destroyed'|'unknown'}
62
+ */
63
+ function liveness(view) {
64
+ if (!view) return 'no-view';
65
+ let wc;
66
+ try { wc = view.webContents; } catch (_) { return 'unknown'; }
67
+ if (!wc) return 'no-webcontents';
68
+ try {
69
+ if (typeof wc.isDestroyed !== 'function') return 'unknown';
70
+ return wc.isDestroyed() ? 'destroyed' : 'ok';
71
+ } catch (_) { return 'unknown'; }
72
+ }
73
+
74
+ module.exports = { isAlive, liveness };