@glittering0717/ai-browser 2.1.18 → 2.1.20

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 CHANGED
@@ -724,7 +724,7 @@ not bugs. The full write-up, including why the first measurement of this was wro
724
724
  ## Test & dev
725
725
 
726
726
  ```bash
727
- npm test # vitest — 411 tests across 27 files
727
+ npm test # vitest — 970 tests across 69 files
728
728
  npm run smoke # Electron contract layer, offline fixture — 31 checks
729
729
  npm run capabilities # text fields, canvas, page source, network, DOM editing — 54 checks
730
730
  npm run richtext # rich-text editors, nested menus, forms, errors, tags, upload — 117 checks
@@ -736,8 +736,14 @@ npm run audit # every advertised action must exist; wait/downloads/permis
736
736
  npm run nav # address bar + load-failure error page (the "white screen" report) — 19 checks
737
737
  npm run focus # no focus stealing + full capability while backgrounded — 32 checks
738
738
  npm run interact # trusted drag / key press / wheel (pointer gestures) — 31 checks
739
- npm run view # viewport repaint + snapshot/diff verification — 28 checks
740
- npm run e2e:all # 一次跑完上面全部套件(每个独立端口)+ 可信汇总 — 428 checks
739
+ npm run view # viewport repaint budget + snapshot/diff verification — 29 checks
740
+ npm run dialog # browser-level dialogs (native sheet blocks the renderer) — 15 checks
741
+ npm run wrapper # "in the tree but won't click" = matched a container, not a link — 13 checks
742
+ npm run paint # blank-page self-check: verdicts, bounded ladder, no false alarms — 23 checks
743
+ npm run layout # geometry invariants + "no twitching" (zero extra repaints on nav) — 25 checks
744
+ npm run flicker # frame-level: no frame may render the page shrunk (needs screen recording) — 6 checks
745
+ npm run e2e:all # 一次跑完上面全部 19 个套件(每个独立端口)+ 可信汇总 — 636 checks
746
+ npm run verify:app # boot the packaged /Applications app and assert on it — 22 checks
741
747
  npm run realsites # navigate/read/act against a matrix of real sites
742
748
  ```
743
749
 
package/package.json CHANGED
@@ -1,6 +1,6 @@
1
1
  {
2
2
  "name": "@glittering0717/ai-browser",
3
- "version": "2.1.18",
3
+ "version": "2.1.20",
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": {
@@ -78,13 +78,16 @@
78
78
  "winopen": "node e2e/window_open_ws.cjs",
79
79
  "coverage": "node tools/coverage_probe.cjs",
80
80
  "build": "node scripts/build_dmg.cjs",
81
+ "build:win": "node scripts/build_win.cjs",
82
+ "build:installer": "node scripts/build_installer.cjs",
81
83
  "verify:build": "node scripts/verify_build.cjs",
82
84
  "install:app": "node scripts/install_app.cjs",
83
85
  "dialog": "node e2e/dialog_ws.cjs",
84
86
  "verify:app": "node e2e/shipped_ws.cjs",
85
87
  "wrapper": "node e2e/wrapper_ws.cjs",
86
88
  "paint": "node e2e/paint_ws.cjs",
87
- "layout": "node e2e/layout_ws.cjs"
89
+ "layout": "node e2e/layout_ws.cjs",
90
+ "flicker": "node e2e/flicker_ws.cjs"
88
91
  },
89
92
  "dependencies": {
90
93
  "@modelcontextprotocol/sdk": "^1.29.0",
@@ -93,6 +96,7 @@
93
96
  },
94
97
  "devDependencies": {
95
98
  "@electron/packager": "^20.3.0",
99
+ "electron-winstaller": "^5.4.4",
96
100
  "jsdom": "^29.1.1",
97
101
  "vitest": "^2.0.0"
98
102
  }
@@ -0,0 +1,68 @@
1
+ 'use strict';
2
+ // scripts/build_installer.cjs — 用 electron-winstaller(Squirrel.Windows)把
3
+ // 已打包好的便携目录 dist/AI Browser-win32-x64 打成**单文件安装器** Setup.exe。
4
+ //
5
+ // 前提:先 `npm run build:win` 产出 dist/AI Browser-win32-x64/。
6
+ // 产出:dist/installer/AI-Browser-<version>-win32-x64-Setup.exe
7
+ // 用法:node scripts/build_installer.cjs
8
+ //
9
+ // Squirrel 安装到 %LOCALAPPDATA%\<name>,并创建开始菜单/桌面快捷方式;不写 HKLM,
10
+ // 无需管理员权限。noMsi: true → 只出 Setup.exe,不额外出 .msi。
11
+
12
+ const fs = require('node:fs');
13
+ const path = require('node:path');
14
+
15
+ const root = path.resolve(__dirname, '..');
16
+ const pkg = require('../package.json');
17
+
18
+ const APP_DIR = path.join(root, 'dist', 'AI Browser-win32-x64');
19
+ const OUT_DIR = path.join(root, 'dist', 'installer');
20
+ const EXE_NAME = 'AI Browser.exe';
21
+
22
+ function main() {
23
+ if (!fs.existsSync(path.join(APP_DIR, EXE_NAME))) {
24
+ console.error(`[installer] 找不到已打包目录:${APP_DIR}\\${EXE_NAME}\n 先运行: npm run build:win`);
25
+ process.exit(2);
26
+ }
27
+ fs.mkdirSync(OUT_DIR, { recursive: true });
28
+
29
+ const icoPath = path.join(root, 'build', 'icon.ico');
30
+ const setupExe = `AI-Browser-${pkg.version}-win32-x64-Setup.exe`;
31
+
32
+ const { createWindowsInstaller } = require('electron-winstaller');
33
+
34
+ console.log(`[installer] ${pkg.version} — Squirrel Setup.exe`);
35
+ console.log(`[installer] appDirectory: ${APP_DIR}`);
36
+ console.log(`[installer] outputDirectory: ${OUT_DIR}`);
37
+
38
+ return createWindowsInstaller({
39
+ appDirectory: APP_DIR,
40
+ outputDirectory: OUT_DIR,
41
+ authors: 'Glittering',
42
+ exe: EXE_NAME,
43
+ // name 用作 %LOCALAPPDATA%\ 下的安装目录与包标识,用无空格名更稳
44
+ name: 'AIBrowser',
45
+ title: 'AI Browser',
46
+ description: 'AI-native browser — semantic-tree API for agents',
47
+ version: pkg.version,
48
+ setupExe,
49
+ noMsi: true,
50
+ // 有 build/icon.ico 就用作 Setup.exe 图标;没有则用默认
51
+ setupIcon: fs.existsSync(icoPath) ? icoPath : undefined,
52
+ }).then(() => {
53
+ const out = path.join(OUT_DIR, setupExe);
54
+ const ok = fs.existsSync(out);
55
+ if (ok) {
56
+ const mb = (fs.statSync(out).size / 1024 / 1024).toFixed(1);
57
+ console.log(`[installer] 完成:${out}(${mb} MB)`);
58
+ } else {
59
+ // electron-winstaller 有时会把 setupExe 名字改成默认,扫一下产物
60
+ const files = fs.readdirSync(OUT_DIR).filter((n) => /Setup\.exe$/i.test(n));
61
+ console.log('[installer] 预期文件名未出现,目录内 Setup.exe:', files);
62
+ if (!files.length) process.exit(1);
63
+ }
64
+ return out;
65
+ });
66
+ }
67
+
68
+ main().catch((e) => { console.error('[installer] 失败:', (e && e.stack) || e); process.exit(1); });
@@ -0,0 +1,98 @@
1
+ 'use strict';
2
+ // scripts/build_win.cjs — Windows 便携包(win32-x64)构建。
3
+ //
4
+ // 为什么单独一份而不是复用 build_dmg.cjs:后者整条链路都是 macOS 专属
5
+ // (ditto / sips / iconutil / PlistBuddy / *.app / *.dmg),在 Windows 上
6
+ // 没有可用的等价物。这里只复用它的**打包语义**(name / IGNORE 黑名单 /
7
+ // prune / asar),把平台换成 win32/x64,产物是带 AI Browser.exe 的便携目录。
8
+ //
9
+ // 产出:dist/AI Browser-win32-x64/AI Browser.exe
10
+ // 用法:node scripts/build_win.cjs
11
+ //
12
+ // 注意:Windows 版可执行文件的图标需要 .ico(项目只有 icon.icns / icon.svg),
13
+ // 未提供时会使用 Electron 默认图标;要换图标请先把 build/icon.svg 转出
14
+ // build/icon.ico,再在下面的 icon 选项里指向它。
15
+
16
+ const fs = require('node:fs');
17
+ const os = require('node:os');
18
+ const path = require('node:path');
19
+
20
+ const root = path.resolve(__dirname, '..');
21
+ const pkg = require('../package.json');
22
+
23
+ const APP_NAME = 'AI Browser';
24
+ const OUT_DIR = path.join(root, 'dist');
25
+
26
+ // 与 build_dmg.cjs 完全一致的黑名单:测试/文档/构建产物/Electron 发行版/图标母版
27
+ // 都不进安装包(src 里 from 'electron' 由 Electron 内置模块解析,不经 node_modules)。
28
+ const IGNORE = new RegExp(
29
+ '(^|\\/)(\\.git|outputs|docs|e2e|tests|dist|build|node_modules\\/\\.cache|node_modules\\/\\.bin|node_modules\\/electron|tools\\/_oneoff)(\\/|$)'
30
+ );
31
+
32
+ // 复用本地已下载好的 electron-v<version>-win32-x64.zip,避免每次联网从 GitHub 拉
33
+ // (README 与 build_dmg 都提到这条:见到本地 zip 就 electronZipDir 指过去,完全不联网)。
34
+ function findElectronZipDir(version, platform, arch) {
35
+ const zipName = `electron-v${version}-${platform}-${arch}.zip`;
36
+ const roots = [];
37
+ if (process.env.LOCALAPPDATA) roots.push(path.join(process.env.LOCALAPPDATA, 'electron', 'Cache'));
38
+ roots.push(path.join(os.homedir(), 'AppData', 'Local', 'electron', 'Cache'));
39
+ roots.push(path.join(os.homedir(), 'Library', 'Caches', 'electron'));
40
+ for (const cacheRoot of roots) {
41
+ let entries = [];
42
+ try { entries = fs.readdirSync(cacheRoot, { withFileTypes: true }); } catch (_) { continue; }
43
+ for (const e of entries) {
44
+ if (!e.isDirectory()) continue;
45
+ const dir = path.join(cacheRoot, e.name);
46
+ if (fs.existsSync(path.join(dir, zipName))) return dir;
47
+ }
48
+ }
49
+ return null;
50
+ }
51
+
52
+ function main() {
53
+ // @electron/packager v20 是纯 ESM,必须动态 import;导出是命名 `packager`。
54
+ import('@electron/packager')
55
+ .then((mod) => build(mod.packager))
56
+ .catch((e) => { console.error('[build:win] 失败:', (e && e.stack) || e); process.exit(1); });
57
+ }
58
+
59
+ function build(packager) {
60
+ const electronVersion = require('electron/package.json').version;
61
+ const zipDir = findElectronZipDir(electronVersion, 'win32', 'x64');
62
+
63
+ console.log(`[build:win] ${APP_NAME} ${pkg.version} — win32/x64`);
64
+ console.log(`[build:win] ignore: ${IGNORE}`);
65
+ console.log(`[build:win] electron zip: ${zipDir ? '本地缓存 ' + zipDir : '本地无缓存,将从 GitHub 下载 v' + electronVersion}`);
66
+
67
+ const icoPath = path.join(root, 'build', 'icon.ico');
68
+
69
+ return packager({
70
+ dir: root,
71
+ name: APP_NAME,
72
+ platform: 'win32',
73
+ arch: 'x64',
74
+ out: OUT_DIR,
75
+ overwrite: true,
76
+ ignore: IGNORE,
77
+ electronZipDir: zipDir || undefined,
78
+ prune: true,
79
+ asar: true,
80
+ // 有 icon.ico 就用(会经 rcedit 写进 exe 资源);没有则使用 Electron 默认图标。
81
+ icon: fs.existsSync(icoPath) ? icoPath : undefined,
82
+ win32metadata: {
83
+ CompanyName: 'Glittering',
84
+ FileDescription: APP_NAME,
85
+ ProductName: APP_NAME,
86
+ },
87
+ }).then((paths) => {
88
+ const out = paths[0];
89
+ const exe = path.join(out, `${APP_NAME}.exe`);
90
+ const ok = fs.existsSync(exe);
91
+ console.log(`[build:win] 产物目录:${out}`);
92
+ console.log(`[build:win] 可执行文件:${ok ? exe : '(未找到 ' + exe + ')'}`);
93
+ if (!ok) process.exit(1);
94
+ return paths;
95
+ });
96
+ }
97
+
98
+ main();
package/src/main/index.js CHANGED
@@ -676,6 +676,15 @@ function showInitialWindow() {
676
676
  } catch (e) {
677
677
  try { mainWindow.show(); } catch (e2) { /* 窗口已销毁 */ }
678
678
  }
679
+ // Windows:show() 之后原生标题栏/边框才真正应用,content 高度会比"隐藏时"少
680
+ // 几十像素(实测 800 外框:隐藏时 content≈761,显示后 735)。但外框尺寸没变 →
681
+ // **不触发 resize** → 页面视图仍按显示前的 content 高度布局,底部溢出约 26px
682
+ // (页面最后一截被窗口底边裁掉)。这里在显示后补一次重排,并再延迟兜底两次,
683
+ // 确保边框真正应用后视图收敛到"视图几何 == 内容区"(layout 套件 G1 断言)。
684
+ const relayoutAfterShow = () => { try { layoutWithBanner(); } catch (_) { /* 窗口已销毁 */ } };
685
+ relayoutAfterShow();
686
+ setTimeout(relayoutAfterShow, 150);
687
+ setTimeout(relayoutAfterShow, 450);
679
688
  };
680
689
 
681
690
  // 等首屏内容就绪。上限 3s:网络再慢也不该让窗口迟迟不出现(人看不到窗口
@@ -1040,7 +1040,18 @@ class PageManager {
1040
1040
  captureBeyondViewport: o.fullPage,
1041
1041
  };
1042
1042
  if (o.quality !== undefined) params.quality = o.quality;
1043
- if (o.clip) params.clip = o.clip;
1043
+ // clip.scale < 1("给我一张缩略概览")**绝不交给合成器**:带 clip.scale 的
1044
+ // 截图会让 Chromium 按该比例临时重建 surface,窗口恰好在合成时就会贴上那张
1045
+ // 缩小的图 1–3 帧(见 SPEC「取帧两条铁律」,2026-10-25 实锤)。
1046
+ // 现在按 scale=1 抓、用 nativeImage 在我们自己这边缩 —— 输出尺寸一致,
1047
+ // 但不再碰合成器。scale>1(放大取值)仍交给 Chromium:本地放大得不到像素。
1048
+ let localScale = 1;
1049
+ if (o.clip && typeof o.clip.scale === 'number' && o.clip.scale > 0 && o.clip.scale < 1) {
1050
+ localScale = o.clip.scale;
1051
+ params.clip = { ...o.clip, scale: 1 };
1052
+ } else if (o.clip) {
1053
+ params.clip = o.clip;
1054
+ }
1044
1055
  const shot = await withDeadline(
1045
1056
  dbg.sendCommand('Page.captureScreenshot', params),
1046
1057
  20000, 'captureScreenshot'
@@ -1048,6 +1059,21 @@ class PageManager {
1048
1059
  if (!shot || typeof shot.data !== 'string') {
1049
1060
  return { ok: false, error: 'empty screenshot result', tab: tid };
1050
1061
  }
1062
+ // 需要缩小就自己做(见上:不把缩放交给合成器)。
1063
+ let imgData = shot.data;
1064
+ if (localScale !== 1) {
1065
+ try {
1066
+ const img0 = nativeImage.createFromBuffer(Buffer.from(shot.data, 'base64'));
1067
+ if (!img0.isEmpty()) {
1068
+ const sz = img0.getSize();
1069
+ const w = Math.max(1, Math.round(sz.width * localScale));
1070
+ const resized = img0.resize({ width: w });
1071
+ imgData = o.format === 'jpeg'
1072
+ ? resized.toJPEG(typeof o.quality === 'number' ? o.quality : 80).toString('base64')
1073
+ : resized.toPNG().toString('base64');
1074
+ }
1075
+ } catch (_) { /* 缩失败就用原图(宁可图大,不要空图) */ }
1076
+ }
1051
1077
 
1052
1078
  const mime = 'image/' + (o.format === 'jpeg' ? 'jpeg' : o.format);
1053
1079
  // 一次 evaluate 拿两样东西:可见密码框(截图不脱敏,泄密了得让调用方
@@ -1070,7 +1096,7 @@ class PageManager {
1070
1096
  const summary = screenshotOpts.describeShot({
1071
1097
  format: o.format,
1072
1098
  mime,
1073
- bytes: Buffer.byteLength(shot.data, 'base64'),
1099
+ bytes: Buffer.byteLength(imgData, 'base64'),
1074
1100
  width: meta.width,
1075
1101
  height: meta.height,
1076
1102
  url: (this._getView(tid) && this._getView(tid).webContents.getURL()) || undefined,
@@ -1082,7 +1108,7 @@ class PageManager {
1082
1108
  if (o.path) {
1083
1109
  try {
1084
1110
  fs.mkdirSync(path.dirname(o.path), { recursive: true });
1085
- fs.writeFileSync(o.path, Buffer.from(shot.data, 'base64'));
1111
+ fs.writeFileSync(o.path, Buffer.from(imgData, 'base64'));
1086
1112
  filePath = o.path;
1087
1113
  } catch (e) {
1088
1114
  return { ok: false, tab: tid, error: 'screenshot captured but writing to ' + o.path + ' failed: ' + ((e && e.message) || e), ...summary };
@@ -1095,7 +1121,7 @@ class PageManager {
1095
1121
  ok: true,
1096
1122
  tab: tid,
1097
1123
  // data 是 base64 裸数据(不带 data: 前缀)—— 调用方按需自己拼。
1098
- data: shot.data,
1124
+ data: imgData,
1099
1125
  mime,
1100
1126
  ...(filePath ? { path: filePath } : {}),
1101
1127
  ...(ignored.length ? { ignored_params: ignored } : {}),
@@ -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.1.18';
5
+ export const VERSION = '2.1.20';