@glittering0717/ai-browser 2.3.0 → 2.3.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/package.json CHANGED
@@ -1,6 +1,6 @@
1
1
  {
2
2
  "name": "@glittering0717/ai-browser",
3
- "version": "2.3.0",
3
+ "version": "2.3.1",
4
4
  "description": "AI-native browser — renders pixels for humans, structured semantic-tree API for agents. No screenshots, no OCR, no coordinate guessing.",
5
5
  "main": "src/main/index.js",
6
6
  "bin": {
@@ -43,6 +43,7 @@ import { MediaInline } from './media_inline.js';
43
43
  // 切到人眼前"的策略。见 shared/tab_route.cjs 顶部(多 agent 并用的三条事故)。
44
44
  import tabRoute, { shouldShowChildTab } from '../shared/tab_route.cjs';
45
45
  import tabGroup from '../shared/tab_group.cjs';
46
+ import placeholder from '../shared/placeholder.cjs';
46
47
  import { probeCapabilities } from './capability_probe.js';
47
48
  import valueContract from '../shared/value_contract.cjs';
48
49
  // 输入成功与否的判定口径(纯函数,独立模块便于单测)。详见文件内注释:
@@ -878,15 +879,18 @@ class PageManager {
878
879
  showDownloadResult(tabId, rec) {
879
880
  const view = this.tabs.get(tabId);
880
881
  if (!view || view.webContents.isDestroyed()) return false;
881
- const q = new URLSearchParams();
882
- q.set('id', rec.id || '');
883
- q.set('name', rec.filename || 'download');
884
- q.set('path', rec.path || '');
885
- q.set('mime', rec.mime || '');
886
- q.set('size', String(rec.total_bytes || 0));
887
- q.set('url', rec.url || '');
888
882
  const pagePath = path.join(__dirname, '../renderer/download.html');
889
- const target = 'file://' + pagePath + '?' + q.toString();
883
+ // 一律走 shared/placeholder.cjs 的构造器:手拼 'file://' + path 在打包后
884
+ // (/Applications/AI Browser.app 含空格)加载不出来。
885
+ const target = placeholder.fileUrlWithQuery(pagePath, {
886
+ id: rec.id || '',
887
+ name: rec.filename || 'download',
888
+ path: rec.path || '',
889
+ mime: rec.mime || '',
890
+ size: String(rec.total_bytes || 0),
891
+ url: rec.url || '',
892
+ });
893
+ if (!target) return false;
890
894
  view.webContents.loadURL(target).catch(() => {});
891
895
  return true;
892
896
  }
@@ -3778,13 +3782,10 @@ return {ok:true,name:file.name,size:file.size,via:via,host_sel:hostSel,clicked:c
3778
3782
  // 等它终于 resolve,下面这行 loadURL(启动页) 又把页面盖回去 ——
3779
3783
  // 表现是"打开的是目标页,下一刻自己跳回首页",读到的树也成了首页的。
3780
3784
  // 判据只看一句:现在还在占位页上吗?不在就什么都不做。
3781
- // 判据要宽松:空 / about:blank 都还算"还没开始",只有**明确导航
3782
- // 到别处**(另一个 http/file 地址)才放弃 —— 收紧成"必须等于占位页"
3783
- // 会在占位页刚发起、getURL() 还返回 about:blank 的那一瞬误判,
3784
- // 结果是新标签页永远停在占位页(wrapper 套件当场 red)。
3785
- const cur = wc0.getURL();
3786
- const stillMine = !cur || cur === 'about:blank' || cur === placeholderUrl;
3787
- if (!stillMine) return;
3785
+ // 注意判据在 shared/placeholder.cjs 里(按文件名,不按字符串相等)——
3786
+ // 这里踩过两次:收紧成"必须等于占位页"会让新标签页永远卡住,
3787
+ // 而字符串相等在打包路径含空格时恒为 false。
3788
+ if (!placeholder.isPlaceholderUrl(wc0.getURL())) return;
3788
3789
  // 让"正在加载"可被观测:白屏最贵的地方不是慢,是慢得无法和
3789
3790
  // "开错了"区分(见 listTabs 的 state 字段)。
3790
3791
  this._tabNavState.set(tabId, 'loading');
@@ -3897,13 +3898,14 @@ return {ok:true,name:file.name,size:file.size,via:via,host_sel:hostSel,clicked:c
3897
3898
  pagePath = path.join(__dirname, '../renderer/error_page.html');
3898
3899
  } catch (_) { return; }
3899
3900
 
3900
- const q = new URLSearchParams({
3901
+ const target = placeholder.fileUrlWithQuery(pagePath, {
3901
3902
  url: String(validatedURL || ''),
3902
3903
  code: String(errorCode),
3903
3904
  text: String(errorDescription || ''),
3904
3905
  });
3905
3906
  try {
3906
- view.webContents.loadURL('file://' + pagePath + '?' + q.toString());
3907
+ if (!target) throw new Error('bad page path');
3908
+ view.webContents.loadURL(target);
3907
3909
  } catch (e) {
3908
3910
  console.error('[page_manager] error page load failed:', e.message);
3909
3911
  this._failureGuard.delete(tabId);
@@ -5346,14 +5348,11 @@ return {ok:true,name:file.name,size:file.size,via:via,host_sel:hostSel,clicked:c
5346
5348
  // "正在打开 <url>"),无目标地址时保持 about:blank(window.open("") 的
5347
5349
  // 占位 tab 要停在这里等站点赋 location,不能显示成"正在打开")。
5348
5350
  _loadingPlaceholderUrl(targetUrl) {
5349
- if (!targetUrl) return 'about:blank';
5350
- try {
5351
- const pagePath = path.join(__dirname, '../renderer/loading.html');
5352
- const q = new URLSearchParams({ url: String(targetUrl) });
5353
- return 'file://' + pagePath + '?' + q.toString();
5354
- } catch (_e) {
5355
- return 'about:blank';
5356
- }
5351
+ // 用 pathToFileURL 而不是 'file://' + path:打包后的路径含空格
5352
+ // (/Applications/AI Browser.app/...),手拼出来的 URL 与 Chromium 报回来的
5353
+ // 一个是字面空格、一个是 %20,任何"字符串相等"的判据都会失效。详见
5354
+ // shared/placeholder.cjs 顶部(v2.3.0 的事故)。
5355
+ return placeholder.placeholderUrlFor(path.join(__dirname, '../renderer/loading.html'), targetUrl);
5357
5356
  }
5358
5357
 
5359
5358
  _ensureWindowOpenShim(tabId, view) {
@@ -0,0 +1,70 @@
1
+ // shared/placeholder.cjs — 新标签页的"占位页"地址与判定。
2
+ //
3
+ // 为什么单独一个模块:这段逻辑出过一个只在打包后暴露的事故(2026-10-28)。
4
+ // 占位页 URL 用字符串拼 `'file://' + path`,而打包后的路径是
5
+ // `/Applications/AI Browser.app/...`(有空格)—— 拼出来的 URL 带一个字面空格,
6
+ // Chromium 报回来的是 `%20`。判据写成 `getURL() === placeholderUrl` 就永远不成立,
7
+ // 于是"垫片装好后去加载真正目标"的那一步被当成"这一页已经被导航走了"而跳过,
8
+ // 新标签页永久停在占位页。开发树上跑得通(路径没空格),打包后必然挂。
9
+ //
10
+ // 两条教训固化成代码:
11
+ // 1. **不要手拼 file:// URL**,用 pathToFileURL(它会正确转义)。
12
+ // 2. **不要用 URL 字符串相等判断"是不是同一页"**,按文件名判据。
13
+ 'use strict';
14
+
15
+ const path = require('node:path');
16
+ const { pathToFileURL } = require('node:url');
17
+
18
+ /** 占位页文件名。改文件名时这里和 renderer/ 目录要一起改。 */
19
+ const PLACEHOLDER_FILE = 'loading.html';
20
+
21
+ /**
22
+ * 把本地页面 + query 拼成合法的 file:// URL。
23
+ *
24
+ * 全项目**只有这一处**允许拼 file URL:手拼 `'file://' + path` 在打包后必炸
25
+ * (路径含空格 → Chromium 报 %20,任何字符串比较都会失效)。错误页、下载结果页
26
+ * 一度也是手拼的,它们在 /Applications 里同样加载不出来。
27
+ */
28
+ function fileUrlWithQuery(pagePath, params) {
29
+ try {
30
+ const q = new URLSearchParams(params || {});
31
+ const base = pathToFileURL(String(pagePath)).href;
32
+ const qs = q.toString();
33
+ return qs ? base + '?' + qs : base;
34
+ } catch (_e) {
35
+ return null;
36
+ }
37
+ }
38
+
39
+ /**
40
+ * 造占位页 URL。`targetUrl` 为空时返回 about:blank(window.open("") 的老站模式
41
+ * 本来就要停在空白页等站点赋 location)。
42
+ */
43
+ function placeholderUrlFor(pagePath, targetUrl) {
44
+ if (!targetUrl) return 'about:blank';
45
+ // pathToFileURL 会处理空格、中文、#、? 等一切需要在 URL 里转义的字符。
46
+ return fileUrlWithQuery(pagePath, { url: String(targetUrl) }) || 'about:blank';
47
+ }
48
+
49
+ /**
50
+ * 这个地址还是不是"我的占位页"。
51
+ *
52
+ * 空 / about:blank 也算 —— 占位页刚发起的那一瞬 getURL() 还是空,把它判成
53
+ * "已经导航走了"会让新标签页永远卡住(这条也踩过)。
54
+ */
55
+ function isPlaceholderUrl(url) {
56
+ const u = String(url || '');
57
+ if (!u || u === 'about:blank') return true;
58
+ // 网络页面一律不是占位页 —— 否则一个恰好叫 loading.html 的站点页面会被
59
+ // 当成"还没开始导航",真正的目标就再也加载不出来了。
60
+ if (/^https?:/i.test(u)) return false;
61
+ try {
62
+ // 去掉 query 看文件名,不要拿整串比:编码、尾斜杠、query 顺序都不可控。
63
+ const bare = u.split('?')[0].split('#')[0];
64
+ return path.posix.basename(decodeURIComponent(bare)) === PLACEHOLDER_FILE;
65
+ } catch (_e) {
66
+ return /\/loading\.html(\?|$)/.test(u);
67
+ }
68
+ }
69
+
70
+ module.exports = { PLACEHOLDER_FILE, fileUrlWithQuery, placeholderUrlFor, isPlaceholderUrl };
@@ -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.3.0';
5
+ export const VERSION = '2.3.1';