@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.
@@ -12,7 +12,7 @@
12
12
  // [role=button],a[href]
13
13
  // 它是一份**表单控件读取器**,为「B站图文编辑器住在 OOPIF 里」那一次事故写的。
14
14
  // 于是:
15
- // 1. `a[href]` 漏掉一切 JS 驱动的链接。超星泛雅的章节条目就是
15
+ // 1. `a[href]` 漏掉一切 JS 驱动的链接。某教学平台的章节条目就是
16
16
  // `<a onclick=...>` 且 href 为 null —— 实测该帧里 a 有 8 个、a[href] 只有 2 个,
17
17
  // 章节列表整整 6 条一个都进不了树。
18
18
  // 2. 纯文本/列表/表格结构完全没有采集通路。就算把锚点补齐,一个「没有可点
@@ -128,7 +128,7 @@ function frameRead(prefix) {
128
128
  continue;
129
129
  }
130
130
 
131
- // 内容块:用 innerText(含后代文字)。**不能用"只取直接文本"**:超星的
131
+ // 内容块:用 innerText(含后代文字)。**不能用"只取直接文本"**:某教学平台的
132
132
  // "已完成任务点: <span>0</span>/4" 是 <h3> 里套 span,只取直接文本会得到
133
133
  // "已完成任务点: /4" —— 数字丢了,而这正是这一行唯一有用的信息。
134
134
  // 祖先重复的问题不靠这里解决,靠下面第二趟"祖先让位给后代"。
@@ -146,7 +146,7 @@ function frameRead(prefix) {
146
146
 
147
147
  // 第二趟:祖先让位给后代 —— 谁更具体谁留下。
148
148
  //
149
- // 实测(超星泛雅章节行):一行是
149
+ // 实测(某教学平台章节行):一行是
150
150
  // <div role="link" tabindex="0" class="catalog_title">1.1 标题 <b>1</b></div>
151
151
  // └─ <a class="clicktitle">1.1 标题</a>
152
152
  // 两个都能点、文字几乎一样。全留下 = 6 个章节变成 12 个节点,全是噪声。
@@ -239,7 +239,7 @@ function frameRead(prefix) {
239
239
  text_chars: bodyChars,
240
240
  kept_chars: keptChars,
241
241
  // 覆盖率:这一帧**看得见的文字**里,有多少进了树。1 = 全进;
242
- // 0.01 = 树里只有一个搜索框,正文一个字都没读到(泛雅事故现场)。
242
+ // 0.01 = 树里只有一个搜索框,正文一个字都没读到(某教学平台事故现场)。
243
243
  coverage: bodyChars
244
244
  ? Math.round(Math.min(1, keptChars / bodyChars) * 100) / 100
245
245
  : (out.length ? 1 : 0),
@@ -2,7 +2,7 @@
2
2
  //
3
3
  // # 为什么需要它(2026-10-27 用户报"点证书下载 → 正在打开… → 一坨 png 链接")
4
4
  //
5
- // 沧州教师继续教育网的证书地址回的是:
5
+ // 省级教师继续教育平台的证书地址回的是:
6
6
  // Content-Type: image/png
7
7
  // Content-Disposition: attachment;filename=<uuid>.png
8
8
  // 站点用新标签打开它,于是 Electron 把它当下载处理 —— **导航永远不会提交**,
@@ -28,7 +28,7 @@ export function pickOpenedTab(entry, startedAt) {
28
28
 
29
29
  // ── 「等一下再收」的宽限窗口 ──────────────────────────────────────────────
30
30
  //
31
- // 2026-10-19 实测(西电专技课程页点「进入学习」,站点代码是
31
+ // 2026-10-19 实测(某网课平台课程页点「进入学习」,站点代码是
32
32
  // `var w = window.open("","_blank"); w.location = res.url;`):
33
33
  //
34
34
  // act 返回 10~15 ms
@@ -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.5.6';
5
+ export const VERSION = '2.5.9';
@@ -71,4 +71,34 @@ function liveness(view) {
71
71
  } catch (_) { return 'unknown'; }
72
72
  }
73
73
 
74
- module.exports = { isAlive, liveness };
74
+ /**
75
+ * webContents 还活着,但它的主框架已经没了 —— 渲染进程崩溃后的第二种形态。
76
+ *
77
+ * 为什么单独一个函数:`isAlive` 只回答"对象还在不在",而执行脚本要的是
78
+ * "这一帧能不能收消息"。渲染进程崩溃(render-process-gone: crashed/killed)之后
79
+ * `webContents.isDestroyed()` 仍是 false、`mainFrame` 仍在,但 `detached === true`,
80
+ * 此时 executeJavaScript 必然失败:
81
+ * Error sending from webFrameMain: Render frame was disposed before
82
+ * WebFrameMain could be accessed
83
+ *
84
+ * 2026-11-28 现场:stderr.log 里这条错误累积了 3482 条 —— 两个定时器
85
+ * (refreshTabBar 2s / pushNavState 1.5s)一直往一个死框架里撞,而
86
+ * `ensureTabBarAlive` 因为 isAlive 为真,从来没有重建过标签栏。
87
+ *
88
+ * @param {object} view 可能是 BrowserView 的东西
89
+ * @returns {boolean} 主框架是否还能接收脚本
90
+ */
91
+ function frameAlive(view) {
92
+ try {
93
+ const wc = view && view.webContents;
94
+ if (!wc || typeof wc.isDestroyed !== 'function' || wc.isDestroyed()) return false;
95
+ const mf = wc.mainFrame;
96
+ if (!mf) return false;
97
+ // detached 是 WebFrameMain 的只读属性;老版本没有就按"还活着"处理。
98
+ return mf.detached !== true;
99
+ } catch (_) {
100
+ return false;
101
+ }
102
+ }
103
+
104
+ module.exports = { isAlive, liveness, frameAlive };
@@ -81,7 +81,7 @@ const sleep = (ms) => new Promise((r) => setTimeout(r, ms));
81
81
  // noIdChain 自己和整条祖先链都没有 id → **真缺口**
82
82
  // 真缺口 = ambiguous + noIdChain。
83
83
  const COUNT_JS = `(function(){
84
- // a[href] 换成 a:无 href 的锚点(onclick 驱动)也是可点目标。超星泛雅的章节
84
+ // a[href] 换成 a:无 href 的锚点(onclick 驱动)也是可点目标。某教学平台的章节
85
85
  // 条目就是 <a onclick>,href 为 null —— 只认 a[href] 会把它们从**分母**里删掉,
86
86
  // 于是覆盖率虚高。帧读取器(shared/frame_read_source.js)早先踩过同一个坑。
87
87
  var INTER = 'a,button,input,select,textarea,summary,details,[role=button],[role=link],[role=checkbox],[role=radio],[role=tab],[role=menuitem],[contenteditable=true]';
@@ -92,7 +92,7 @@ const COUNT_JS = `(function(){
92
92
  // 只算**可见的、最内层的**可交互元素:
93
93
  // - 不可见的(隐藏 input、0×0 的埋点控件)不是人能看到的目标;
94
94
  // - 最内层的(不再包含别的可交互元素)才是真正的动作目标,外面那层是包装。
95
- // 不这么筛,"这一行里到底有几个可点的东西"永远数不清 —— 实测超星章节行
95
+ // 不这么筛,"这一行里到底有几个可点的东西"永远数不清 —— 实测某教学平台章节行
96
96
  // 里同时有 2 个隐藏 input + 行容器 div[role=link] + 标题 a,共 4 个命中,
97
97
  // 于是"唯一可交互后代"这个前提永远不成立,6 个章节被永久误报成真缺口。
98
98
  var live = [];
@@ -125,7 +125,7 @@ const COUNT_JS = `(function(){
125
125
  // 只看交集/内层面积会把"大卡片里放个小链接"误判成壳子(点卡片 ≠ 点那个链接)。
126
126
  if (inter / (b.width * b.height) >= 0.9 && inter / (r.width * r.height) >= 0.9) return true;
127
127
  // 判据二(文本):外层的文字**就是**这一个链接的文字(可能多个角标)。
128
- // 2026-10-19 实测(超星泛雅章节行):外层是整行
128
+ // 2026-10-19 实测(某教学平台章节行):外层是整行
129
129
  // <div class="chapter_item" role="link">1.1 标题 <b>1</b></div>
130
130
  // 内层是 <a>1.1 标题</a>,宽 996 / 行宽 1100 —— 几何上差 5% 不过线,于是
131
131
  // 6 个章节被报成"真缺口"。但点内层 a 会冒泡到整行,实测
@@ -223,7 +223,7 @@ const COUNT_JS = `(function(){
223
223
  const raw2 = JSON.parse(String(r.value));
224
224
 
225
225
  // ---- 跨进程帧:分母必须包含它们,否则这个数字会骗人 ----
226
- // 2026-10-19 实测(超星泛雅学习页):本工具报「可点目标 4,可用率 100%、
226
+ // 2026-10-19 实测(某教学平台学习页):本工具报「可点目标 4,可用率 100%、
227
227
  // 真缺口 0」,而**整门课程的章节列表一个都没进树** —— 因为那 6 个条目住在
228
228
  // 跨进程 iframe 里,而 COUNT_JS 只在顶层 document 里数。
229
229
  // 100% 覆盖了 4 个按钮,同时 100% 看不见正文。
@@ -1,52 +0,0 @@
1
- ---
2
- name: web-network-monitor
3
- description: >-
4
- 适用于监控页面发出的网络请求、抓取指定 API 的响应体、验证请求参数/返回值、或查看页面 JS 错误的排查任务。触发词:抓包、网络请求、接口响应、接口返回了什么、response body、看下这个接口、js error、请求参数。
5
- 仅当任务需要"网络层信息"时使用;普通点击/读写页面请直接用 browse_act / browse_get_tree。
6
- ---
7
-
8
- # 网络 / 接口监控(web-network-monitor)
9
-
10
- 用**两个**工具就够,不需要订阅、不需要写脚本:
11
-
12
- | 想做什么 | 调用 |
13
- |---|---|
14
- | 看页面发了哪些请求 | `browse_network {operation:"list"}` |
15
- | 按 URL 找某个请求 | `browse_network {operation:"list", filters:{url_contains:"/api/user"}}` |
16
- | 看某条请求的详情 + 响应体 | `browse_network {operation:"get", network_id:"<从 list 拿>", include:{response_body:true}}` |
17
- | 清空已记录请求 | `browse_network {operation:"clear"}` |
18
- | 看页面 JS 报错 | `browse_errors` |
19
-
20
- ## 标准四步
21
-
22
- 1. `browse_network {operation:"clear"}` —— 先清,避免混进旧请求。
23
- 2. 触发请求:`browse_act {action:"click", target:"<按钮 data-ai-id>"}`。
24
- 3. `browse_network {operation:"list", filters:{url_contains:"<关键字>"}}`
25
- → 每条带 `id`、`method`、`url`、`status`、`state`。
26
- 4. `browse_network {operation:"get", network_id:"<id>", include:{response_body:true, request_body:true}}`
27
- → 拿 headers 与 body。大 body 用 `body_offset` 翻页。
28
-
29
- ## 关键事实(不按这个来会白等)
30
-
31
- - **网络记录是按"从现在起"累积的**,`clear` 只清当前 tab 的记录。
32
- - `list` 默认返回 50 条(最多 200);更多用 `filters.before_seq` 翻页。
33
- - `response_body` 只在请求**已完成**后才有;`state:"pending"` 时先 `browse_wait {condition:"text_contains"}` 或稍等再 `get`。
34
- - 敏感 header(Cookie/Authorization)默认打码,需要时由人设置 `AI_BROWSER_NETWORK_SENSITIVE=1` 并重启。
35
- - 请求体/响应体可能很大:先用 `filters` 收窄,再 `include.body_limit` 控制。
36
-
37
- ## 示例
38
-
39
- 用户:"我点提交之后到底调了哪个接口、返回了什么?"
40
-
41
- ```
42
- browse_network {operation:"clear"}
43
- browse_act {action:"click", target:"e:button-7"}
44
- browse_network {operation:"list", filters:{method:["POST"]}}
45
- browse_network {operation:"get", network_id:"<上一步的 id>", include:{response_body:true}}
46
- ```
47
-
48
- ## 边界
49
-
50
- - 页面关闭后该 tab 的记录一起没了;跨 tab 各自独立。
51
- - `browse_evaluate` 不能替代:它只看得到页面 JS 上下文,看不到网络层。
52
- - 拿不到 body 时先确认 `state` 是否为 `finished`,再确认请求是否真的发生过(`list` 里有没有它)。