@seekskyworld/open-browser 0.0.0-stage → 0.2.0

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.
Files changed (125) hide show
  1. package/CONTRIBUTING.md +15 -0
  2. package/Docs/Agent/346/265/217/350/247/210/345/231/250/346/200/273/344/275/223/346/236/266/346/236/204.md +58 -0
  3. package/Docs/THIRD-PARTY-NOTICES.md +12 -0
  4. package/Docs/open-browser-api.d.ts +291 -0
  5. package/Docs/open-browser/344/273/273/345/212/241/350/257/204/346/265/213/346/214/207/345/215/227.md +59 -0
  6. package/Docs/open-browser/351/232/220/347/247/201/344/270/216/345/274/200/346/272/220/345/256/241/350/256/241.md +37 -0
  7. package/Docs//346/216/247/345/210/266/345/217/260/345/210/206/347/273/204/344/270/216/346/216/245/347/256/241/346/226/271/346/241/210.md +31 -0
  8. package/Docs//350/267/250/345/271/263/345/217/260/350/257/225/347/224/250/344/270/216/345/217/221/350/241/214.md +84 -0
  9. package/LICENSE +200 -0
  10. package/README.md +159 -2
  11. package/README.zh-CN.md +166 -0
  12. package/SECURITY.md +9 -0
  13. package/access-registry.mjs +156 -0
  14. package/action-execution.mjs +385 -0
  15. package/activity-notifier.mjs +34 -0
  16. package/api-contract.mjs +134 -0
  17. package/browser-extension/icons/open-browser-128.png +0 -0
  18. package/browser-extension/icons/open-browser-16.png +0 -0
  19. package/browser-extension/icons/open-browser-32.png +0 -0
  20. package/browser-extension/icons/open-browser-48.png +0 -0
  21. package/browser-extension/icons/open-browser-wordmark.png +0 -0
  22. package/browser-extension/manifest.json +35 -0
  23. package/browser-extension/newtab.css +26 -0
  24. package/browser-extension/newtab.html +19 -0
  25. package/browser-extension/newtab.js +174 -0
  26. package/browser-extension/phase-labels.js +9 -0
  27. package/browser-extension/popup.css +19 -0
  28. package/browser-extension/popup.html +56 -0
  29. package/browser-extension/popup.js +405 -0
  30. package/browser-extension/tab-action.js +138 -0
  31. package/browser-extension/worker.js +281 -0
  32. package/browser-extension/workspace-title.js +15 -0
  33. package/build-profile.mjs +23 -0
  34. package/capability-matrix.mjs +21 -0
  35. package/chromium-host.mjs +209 -0
  36. package/chromium-shell.mjs +179 -0
  37. package/cli.mjs +141 -0
  38. package/contract-validation.mjs +27 -0
  39. package/control.mjs +107 -0
  40. package/desktop/Info.plist +13 -0
  41. package/desktop/Launcher.m +117 -0
  42. package/desktop/OBControlBar.h +7 -0
  43. package/desktop/OBControlBar.m +217 -0
  44. package/desktop/OBPageView.h +6 -0
  45. package/desktop/OBPageView.m +348 -0
  46. package/desktop/WorkspacePanel.h +16 -0
  47. package/desktop/WorkspacePanel.m +916 -0
  48. package/desktop/archive-release.py +129 -0
  49. package/desktop/brand-keychain.py +111 -0
  50. package/desktop/brand-locales.py +93 -0
  51. package/desktop/brand-macos-icons.py +24 -0
  52. package/desktop/brand-windows-icons.mjs +48 -0
  53. package/desktop/build-macos.mjs +112 -0
  54. package/desktop/build-managed-input.mjs +37 -0
  55. package/desktop/build-portable.mjs +95 -0
  56. package/desktop/build-profile.mjs +6 -0
  57. package/desktop/build.mjs +13 -0
  58. package/desktop/create-shortcut.ps1 +9 -0
  59. package/desktop/generate-icons.py +39 -0
  60. package/desktop/icons/open-browser.icns +0 -0
  61. package/desktop/icons/open-browser.ico +0 -0
  62. package/desktop/install-menu-entry.mjs +24 -0
  63. package/desktop/macos-entitlements.plist +12 -0
  64. package/desktop/notarize-macos.mjs +145 -0
  65. package/desktop/package-assets.mjs +34 -0
  66. package/desktop/package-macos.mjs +54 -0
  67. package/desktop/patches/chromium-macos-keychain-service.patch +18 -0
  68. package/desktop/patches/chromium-managed-input.patch +144 -0
  69. package/desktop/portable-archive.py +22 -0
  70. package/desktop/sign.mjs +77 -0
  71. package/desktop/smoke-portable.mjs +65 -0
  72. package/desktop/start-profile.mjs +5 -0
  73. package/desktop/start.mjs +34 -0
  74. package/desktop/verify-macos-release.mjs +61 -0
  75. package/desktop/verify-upgrade.mjs +74 -0
  76. package/desktop/verify-version.mjs +12 -0
  77. package/desktop-page.mjs +211 -0
  78. package/diagnostics.mjs +37 -0
  79. package/downloads.mjs +110 -0
  80. package/engine-service.mjs +1158 -0
  81. package/hosted/README.md +74 -0
  82. package/hosted/cli.mjs +17 -0
  83. package/hosted/directory.mjs +261 -0
  84. package/hosted/init.mjs +37 -0
  85. package/hosted/server.mjs +129 -0
  86. package/managed-input.mjs +138 -0
  87. package/managed-popup.mjs +54 -0
  88. package/mcp-http.mjs +84 -0
  89. package/mcp-server.mjs +41 -0
  90. package/mcp.mjs +5 -0
  91. package/network-policy.mjs +107 -0
  92. package/output-store.mjs +96 -0
  93. package/package.json +77 -4
  94. package/page-activity.mjs +188 -0
  95. package/page-dialogs.mjs +53 -0
  96. package/page-observation.mjs +318 -0
  97. package/paths.mjs +22 -0
  98. package/privacy-config.mjs +95 -0
  99. package/receipt-store.mjs +198 -0
  100. package/runtime.mjs +53 -0
  101. package/scheduler.mjs +70 -0
  102. package/sdk.mjs +193 -0
  103. package/service.mjs +290 -0
  104. package/site-workflow.mjs +115 -0
  105. package/skill-links.mjs +90 -0
  106. package/skills/open-browser/SKILL.macos.md +112 -0
  107. package/skills/open-browser/SKILL.md +107 -0
  108. package/skills/open-browser/SKILL.windows.md +112 -0
  109. package/skills/open-browser/scripts/bootstrap.mjs +213 -0
  110. package/skills/open-browser/scripts/open-browser +21 -0
  111. package/skills/open-browser/scripts/open-browser.cmd +9 -0
  112. package/skills/open-browser/workflows/login-export.json +10 -0
  113. package/skills/open-browser/workflows/upload-verify.json +8 -0
  114. package/studio/demo-site.mjs +111 -0
  115. package/studio/demo.css +1 -0
  116. package/studio/index.html +66 -0
  117. package/studio/index.mjs +57 -0
  118. package/studio/native-demo.mjs +124 -0
  119. package/studio/studio.css +119 -0
  120. package/studio/studio.js +438 -0
  121. package/tab-adoption.mjs +77 -0
  122. package/uploads.mjs +63 -0
  123. package/visual-page.mjs +306 -0
  124. package/workspace-lifecycle.mjs +238 -0
  125. package/workspace-state.mjs +107 -0
@@ -0,0 +1,6 @@
1
+ #!/usr/bin/env node
2
+ const [profile, ...args] = process.argv.slice(2);
3
+ if (!['dev', 'stable'].includes(profile)) throw new Error('usage: build-profile.mjs <dev|stable> [build arguments]');
4
+ process.env.OPEN_BROWSER_BUILD_PROFILE = profile;
5
+ process.argv = [process.argv[0], process.argv[1], ...args];
6
+ await import('./build.mjs');
@@ -0,0 +1,13 @@
1
+ const profileIndex = process.argv.findIndex(value => value === '--profile');
2
+ if (profileIndex >= 0) {
3
+ const profile = process.argv[profileIndex + 1];
4
+ if (!['dev', 'stable'].includes(profile)) throw new Error('--profile must be dev or stable');
5
+ process.env.OPEN_BROWSER_BUILD_PROFILE = profile;
6
+ }
7
+ const archIndex = process.argv.findIndex(value => value === '--arch');
8
+ if (archIndex >= 0) process.env.OPEN_BROWSER_TARGET_ARCH = process.argv[archIndex + 1];
9
+ if (process.platform === 'darwin') {
10
+ await import('./build-macos.mjs');
11
+ } else {
12
+ await import('./build-portable.mjs');
13
+ }
@@ -0,0 +1,9 @@
1
+ $ErrorActionPreference = 'Stop'
2
+ $desktop = [Environment]::GetFolderPath('DesktopDirectory')
3
+ $link = (New-Object -ComObject WScript.Shell).CreateShortcut((Join-Path $desktop 'open-browser.lnk'))
4
+ $link.TargetPath = Join-Path $PSScriptRoot 'node\node.exe'
5
+ $link.Arguments = '"' + (Join-Path $PSScriptRoot 'app\service.mjs') + '" --chromium'
6
+ $link.WorkingDirectory = $PSScriptRoot
7
+ $link.IconLocation = (Join-Path $PSScriptRoot 'open-browser.ico') + ',0'
8
+ $link.WindowStyle = 7
9
+ $link.Save()
@@ -0,0 +1,39 @@
1
+ """Regenerate checked-in desktop and extension icons on macOS from the README artwork."""
2
+ from pathlib import Path
3
+ from tempfile import TemporaryDirectory
4
+ import struct
5
+ import subprocess
6
+
7
+ root = Path(__file__).resolve().parents[1]
8
+ source = root / 'Docs/assets/open-browser-logo.png'
9
+ desktop = root / 'desktop/icons'
10
+ extension = root / 'browser-extension/icons'
11
+ for directory in (desktop, extension):
12
+ directory.mkdir(exist_ok=True)
13
+
14
+
15
+ def resize(image, size, destination):
16
+ subprocess.run(['sips', '-Z', str(size), str(image), '--out', str(destination)],
17
+ check=True, stdout=subprocess.DEVNULL)
18
+
19
+
20
+ with TemporaryDirectory() as temp:
21
+ iconset = Path(temp) / 'open-browser.iconset'
22
+ iconset.mkdir()
23
+ for size in (16, 32, 128, 256, 512):
24
+ for scale, suffix in ((1, ''), (2, '@2x')):
25
+ resize(source, size * scale, iconset / f'icon_{size}x{size}{suffix}.png')
26
+ subprocess.run(['iconutil', '-c', 'icns', str(iconset), '-o', str(desktop / 'open-browser.icns')], check=True)
27
+
28
+ sizes = (16, 32, 48, 128, 256)
29
+ entries, images = [], []
30
+ offset = 6 + 16 * len(sizes)
31
+ for size in sizes:
32
+ png = (extension if size <= 128 else Path(temp)) / f'open-browser-{size}.png'
33
+ resize(source, size, png)
34
+ data = png.read_bytes()
35
+ entries.append(struct.pack('<BBBBHHII', size % 256, size % 256, 0, 0, 1, 32, len(data), offset))
36
+ images.append(data)
37
+ offset += len(data)
38
+ (desktop / 'open-browser.ico').write_bytes(struct.pack('<HHH', 0, 1, len(sizes)) + b''.join(entries + images))
39
+ resize(root / 'Docs/assets/open-browser-wordmark.png', 576, extension / 'open-browser-wordmark.png')
Binary file
Binary file
@@ -0,0 +1,24 @@
1
+ // Install the portable package at its current location in the user's Linux menu.
2
+ import { chmod, mkdir, rename, writeFile } from 'node:fs/promises';
3
+ import { homedir } from 'node:os';
4
+ import path from 'node:path';
5
+ import { fileURLToPath } from 'node:url';
6
+
7
+ const folder = path.dirname(fileURLToPath(import.meta.url));
8
+ const menu = path.join(process.env.XDG_DATA_HOME || path.join(homedir(), '.local/share'), 'applications');
9
+ const entry = path.join(menu, 'open-browser.desktop');
10
+ // Exec has its own quoting rules in addition to desktop-entry string escaping.
11
+ const escapeValue = value => value.replaceAll('\\', '\\\\').replaceAll('\n', '\\n').replaceAll('\r', '\\r').replaceAll('\t', '\\t');
12
+ const executable = path.join(folder, 'open-browser').replace(/["`$\\]/g, '\\$&').replaceAll('%', '%%');
13
+ const icon = path.join(folder, 'app/browser-extension/icons/open-browser-128.png');
14
+ const content = [
15
+ '[Desktop Entry]', 'Type=Application', 'Name=open-browser',
16
+ 'Exec="' + escapeValue(executable) + '"', 'Icon=' + escapeValue(icon),
17
+ 'Terminal=false', 'Categories=Network;WebBrowser;', 'StartupWMClass=open-browser', '',
18
+ ].join('\n');
19
+ await mkdir(menu, { recursive: true });
20
+ const temporary = entry + '.' + process.pid;
21
+ await writeFile(temporary, content, { flag: 'wx' });
22
+ await chmod(temporary, 0o755);
23
+ await rename(temporary, entry);
24
+ console.log(entry);
@@ -0,0 +1,12 @@
1
+ <?xml version="1.0" encoding="UTF-8"?>
2
+ <!DOCTYPE plist PUBLIC "-//Apple//DTD PLIST 1.0//EN" "http://www.apple.com/DTDs/PropertyList-1.0.dtd">
3
+ <plist version="1.0">
4
+ <dict>
5
+ <key>com.apple.security.cs.allow-jit</key>
6
+ <true/>
7
+ <key>com.apple.security.cs.allow-unsigned-executable-memory</key>
8
+ <true/>
9
+ <key>com.apple.security.cs.disable-library-validation</key>
10
+ <true/>
11
+ </dict>
12
+ </plist>
@@ -0,0 +1,145 @@
1
+ import { execFileSync } from 'node:child_process';
2
+ import { createHash } from 'node:crypto';
3
+ import { access, readFile, writeFile } from 'node:fs/promises';
4
+ import path from 'node:path';
5
+ import { fileURLToPath } from 'node:url';
6
+
7
+ const root = fileURLToPath(new URL('../', import.meta.url));
8
+ const defaultApp = path.join(root, 'dist', 'open-browser.app');
9
+
10
+ function usage() {
11
+ console.log(`用法:node desktop/notarize-macos.mjs [app-path] [--zip zip-path]
12
+
13
+ 提交并公证 macOS 应用,固化票据后生成可上传的 GitHub ZIP。
14
+ 凭据优先使用 OPEN_BROWSER_NOTARY_PROFILE,其次使用 App Store Connect API Key,
15
+ 最后使用 Apple ID 加应用专用密码。凭据只从环境变量或本机钥匙串读取。`);
16
+ }
17
+
18
+ function parseArgs(argv) {
19
+ let app = process.env.OPEN_BROWSER_APP_PATH || defaultApp;
20
+ let zip = process.env.OPEN_BROWSER_NOTARY_ZIP;
21
+ for (let index = 0; index < argv.length; index += 1) {
22
+ const value = argv[index];
23
+ if (value === '--help' || value === '-h') return { help: true };
24
+ if (value === '--zip') {
25
+ zip = argv[++index];
26
+ if (!zip) throw new Error('--zip 需要文件路径。');
27
+ continue;
28
+ }
29
+ if (value.startsWith('--')) throw new Error('未知参数:' + value);
30
+ if (app !== defaultApp && app !== process.env.OPEN_BROWSER_APP_PATH)
31
+ throw new Error('只能指定一个应用路径。');
32
+ app = value;
33
+ }
34
+ const appArch = app.endsWith('-x64.app') ? 'x64' : app.endsWith('-arm64.app') ? 'arm64' : process.arch;
35
+ if (!zip) zip = path.join(path.dirname(app), `open-browser-macos-${appArch}.zip`);
36
+ return { app: path.resolve(app), zip: path.resolve(zip), help: false };
37
+ }
38
+
39
+ function run(command, args, options = {}) {
40
+ return execFileSync(command, args, { stdio: 'inherit', ...options });
41
+ }
42
+
43
+ function commandPath(name, fallback) {
44
+ try {
45
+ return execFileSync('/usr/bin/xcrun', ['--find', name], { encoding: 'utf8' }).trim();
46
+ } catch {
47
+ return fallback;
48
+ }
49
+ }
50
+
51
+ async function requirePath(target, label) {
52
+ try {
53
+ await access(target);
54
+ } catch {
55
+ throw new Error(`${label}不存在:${target}`);
56
+ }
57
+ }
58
+
59
+ function notaryCredentials() {
60
+ const profile = process.env.OPEN_BROWSER_NOTARY_PROFILE;
61
+ const key = process.env.OPEN_BROWSER_NOTARY_KEY || process.env.APPLE_API_KEY_PATH;
62
+ const keyId = process.env.OPEN_BROWSER_NOTARY_KEY_ID || process.env.APPLE_API_KEY;
63
+ const issuer = process.env.OPEN_BROWSER_NOTARY_ISSUER || process.env.APPLE_API_ISSUER;
64
+ const appleId = process.env.OPEN_BROWSER_NOTARY_APPLE_ID || process.env.APPLE_ID;
65
+ const teamId = process.env.OPEN_BROWSER_NOTARY_TEAM_ID || process.env.APPLE_TEAM_ID;
66
+ const password = process.env.OPEN_BROWSER_NOTARY_PASSWORD || process.env.APPLE_PASSWORD;
67
+
68
+ const apiKeyFields = [key, keyId, issuer].filter(Boolean).length;
69
+ const hasApiKey = Boolean(key || keyId || issuer);
70
+ const hasAppleId = Boolean(appleId || password);
71
+ if (profile && (hasApiKey || hasAppleId || teamId))
72
+ throw new Error('OPEN_BROWSER_NOTARY_PROFILE 不能和其他凭据模式同时设置。');
73
+ if (hasApiKey && hasAppleId)
74
+ throw new Error('API Key 和 Apple ID 公证凭据不能混用。');
75
+ if (profile) return ['--keychain-profile', profile];
76
+ if (hasApiKey) {
77
+ if (!key || !keyId) throw new Error('API Key 模式需要 OPEN_BROWSER_NOTARY_KEY 和 OPEN_BROWSER_NOTARY_KEY_ID。');
78
+ if (!issuer && apiKeyFields === 3) throw new Error('团队 API Key 模式需要 OPEN_BROWSER_NOTARY_ISSUER。');
79
+ const args = ['--key', key, '--key-id', keyId];
80
+ if (issuer) args.push('--issuer', issuer);
81
+ return args;
82
+ }
83
+ if (!appleId && !teamId && !password) {
84
+ throw new Error('缺少公证凭据。优先设置 OPEN_BROWSER_NOTARY_PROFILE,或提供 API Key,' +
85
+ '或设置 OPEN_BROWSER_NOTARY_APPLE_ID、OPEN_BROWSER_NOTARY_TEAM_ID 和应用专用密码。');
86
+ }
87
+ if (!appleId || !teamId) throw new Error('Apple ID 模式需要 OPEN_BROWSER_NOTARY_APPLE_ID 和 OPEN_BROWSER_NOTARY_TEAM_ID。');
88
+ let resolvedPassword = password;
89
+ if (!resolvedPassword) {
90
+ const service = process.env.OPEN_BROWSER_NOTARY_PASSWORD_SERVICE || 'open-browser-notary';
91
+ try {
92
+ resolvedPassword = execFileSync('/usr/bin/security', [
93
+ 'find-generic-password', '-a', appleId, '-s', service, '-w'
94
+ ], { encoding: 'utf8' }).trim();
95
+ } catch {
96
+ throw new Error(`未找到 Apple ID 应用专用密码。请将密码保存到钥匙串服务 ${service},或设置 OPEN_BROWSER_NOTARY_PASSWORD。`);
97
+ }
98
+ }
99
+ if (!resolvedPassword) throw new Error('Apple ID 应用专用密码为空。');
100
+ return ['--apple-id', appleId, '--team-id', teamId, '--password', resolvedPassword];
101
+ }
102
+
103
+ async function sha256(file) {
104
+ return createHash('sha256').update(await readFile(file)).digest('hex');
105
+ }
106
+
107
+ async function main() {
108
+ const parsed = parseArgs(process.argv.slice(2));
109
+ if (parsed.help) {
110
+ usage();
111
+ return;
112
+ }
113
+ if (process.platform !== 'darwin') throw new Error('macOS 公证只能在 macOS 构建机执行。');
114
+ await requirePath(parsed.app, '应用');
115
+ if (!parsed.app.endsWith('.app')) throw new Error('公证输入必须是 .app 应用包。');
116
+ await requirePath('/usr/bin/codesign', 'codesign');
117
+ await requirePath('/usr/bin/xcrun', 'xcrun');
118
+
119
+ const notarytool = commandPath('notarytool', '/usr/bin/xcrun');
120
+ const stapler = commandPath('stapler', '/usr/bin/xcrun');
121
+ const spctl = commandPath('spctl', '/usr/sbin/spctl');
122
+ run('/usr/bin/codesign', ['--verify', '--strict', '--deep', '--verbose=2', parsed.app]);
123
+
124
+ run('/usr/bin/ditto', ['-c', '-k', '--keepParent', '--sequesterRsrc', parsed.app, parsed.zip]);
125
+ const credentials = notaryCredentials();
126
+ run(notarytool, notarytool === '/usr/bin/xcrun'
127
+ ? ['notarytool', 'submit', parsed.zip, '--wait', ...credentials]
128
+ : ['submit', parsed.zip, '--wait', ...credentials]);
129
+
130
+ run(stapler, stapler === '/usr/bin/xcrun' ? ['stapler', 'staple', parsed.app] : ['staple', parsed.app]);
131
+ run(stapler, stapler === '/usr/bin/xcrun' ? ['stapler', 'validate', parsed.app] : ['validate', parsed.app]);
132
+ run(spctl, ['--assess', '--type', 'execute', '--verbose=4', parsed.app]);
133
+
134
+ // The first archive is the notarization input. Recreate it after stapling so
135
+ // the GitHub download contains the ticket and passes offline Gatekeeper checks.
136
+ run('/usr/bin/ditto', ['-c', '-k', '--keepParent', '--sequesterRsrc', parsed.app, parsed.zip]);
137
+ const digest = await sha256(parsed.zip);
138
+ await writeFile(parsed.zip + '.sha256', `${digest} ${path.basename(parsed.zip)}\n`);
139
+ console.log(`${parsed.zip}\nSHA-256 ${digest}`);
140
+ }
141
+
142
+ main().catch(error => {
143
+ console.error(error instanceof Error ? error.message : error);
144
+ process.exitCode = 1;
145
+ });
@@ -0,0 +1,34 @@
1
+ import { copyFile, cp, mkdir, readFile, readdir, writeFile } from 'node:fs/promises';
2
+ import path from 'node:path';
3
+ import { fileURLToPath } from 'node:url';
4
+
5
+ export const root = fileURLToPath(new URL('../', import.meta.url));
6
+
7
+ export async function copyApplication(app) {
8
+ await mkdir(app, { recursive: true });
9
+ const code = (await readdir(root)).filter(name => name.endsWith('.mjs') && !name.endsWith('.test.mjs'));
10
+ for (const name of [...code, 'package.json', 'package-lock.json'])
11
+ await copyFile(path.join(root, name), path.join(app, name));
12
+ for (const name of ['browser-extension', 'studio', 'skills'])
13
+ await cp(path.join(root, name), path.join(app, name), { recursive: true, filter: file => !file.endsWith('.test.mjs') });
14
+ const lock = JSON.parse(await readFile(path.join(root, 'package-lock.json'), 'utf8'));
15
+ await cp(path.join(root, 'node_modules'), path.join(app, 'node_modules'), {
16
+ recursive: true, verbatimSymlinks: true, filter: file => path.basename(file) !== '.bin' &&
17
+ !lock.packages[path.relative(root, file).split(path.sep).join('/')]?.dev,
18
+ });
19
+ await copyFile(path.join(root, 'Docs/THIRD-PARTY-NOTICES.md'), path.join(app, 'THIRD-PARTY-NOTICES.md'));
20
+ await copyFile(path.join(root, 'LICENSE'), path.join(app, 'LICENSE'));
21
+ const licenses = [];
22
+ for (const [location, info] of Object.entries(lock.packages)) {
23
+ if (!location || info.dev) continue;
24
+ const entries = await readdir(path.join(app, location)).catch(error => {
25
+ if (info.optional && error.code === 'ENOENT') return [];
26
+ throw error;
27
+ });
28
+ if (entries.length) licenses.push({
29
+ location, version: info.version, license: info.license || 'see package',
30
+ notices: entries.filter(file => /license|copying|notice|copyright/i.test(file)).sort(),
31
+ });
32
+ }
33
+ await writeFile(path.join(app, 'third-party-packages.json'), JSON.stringify(licenses, null, 2) + '\n');
34
+ }
@@ -0,0 +1,54 @@
1
+ #!/usr/bin/env node
2
+
3
+ import { execFileSync } from 'node:child_process';
4
+ import { createHash } from 'node:crypto';
5
+ import { mkdtemp, readFile, rm, writeFile } from 'node:fs/promises';
6
+ import path from 'node:path';
7
+ import { fileURLToPath } from 'node:url';
8
+
9
+ const root = fileURLToPath(new URL('../', import.meta.url));
10
+ const packageInfo = JSON.parse(await readFile(path.join(root, 'package.json'), 'utf8'));
11
+ const output = path.join(root, 'dist');
12
+
13
+ function option(name, fallback) {
14
+ const index = process.argv.indexOf(name);
15
+ return index >= 0 ? process.argv[index + 1] : fallback;
16
+ }
17
+
18
+ const arch = option('--arch', process.arch);
19
+ const format = option('--format', 'both');
20
+ if (!['arm64', 'x64'].includes(arch)) throw new Error('--arch must be arm64 or x64');
21
+ if (!['dmg', 'zip', 'both'].includes(format)) throw new Error('--format must be dmg, zip or both');
22
+ if (process.platform !== 'darwin') throw new Error('macOS packages must be created on macOS');
23
+
24
+ const appName = arch === 'x64' ? 'open-browser-x64.app' : 'open-browser.app';
25
+ const app = path.join(output, appName);
26
+ const baseName = `open-browser-macos-${arch}`;
27
+ const digest = async file => createHash('sha256').update(await readFile(file)).digest('hex');
28
+ const packagePath = kind => path.join(output, `${baseName}.${kind}`);
29
+
30
+ execFileSync('/usr/bin/codesign', ['--verify', '--strict', '--deep', app], { stdio: 'inherit' });
31
+
32
+ if (format === 'zip' || format === 'both') {
33
+ const zip = packagePath('zip');
34
+ execFileSync('/usr/bin/ditto', ['-c', '-k', '--keepParent', '--sequesterRsrc', app, zip], { stdio: 'inherit' });
35
+ await writeFile(zip + '.sha256', `${await digest(zip)} ${path.basename(zip)}\n`);
36
+ console.log(zip);
37
+ }
38
+
39
+ if (format === 'dmg' || format === 'both') {
40
+ const staging = await mkdtemp(path.join(output, '.open-browser-dmg-'));
41
+ const volume = path.join(staging, `open-browser ${packageInfo.version}`);
42
+ try {
43
+ execFileSync('/bin/mkdir', ['-p', volume]);
44
+ execFileSync('/usr/bin/ditto', [app, path.join(volume, appName)], { stdio: 'inherit' });
45
+ execFileSync('/bin/ln', ['-s', '/Applications', path.join(volume, 'Applications')]);
46
+ const dmg = packagePath('dmg');
47
+ execFileSync('/usr/bin/hdiutil', ['create', '-volname', `open-browser ${packageInfo.version}`, '-srcfolder', volume,
48
+ '-ov', '-format', 'UDZO', dmg], { stdio: 'inherit' });
49
+ await writeFile(dmg + '.sha256', `${await digest(dmg)} ${path.basename(dmg)}\n`);
50
+ console.log(dmg);
51
+ } finally {
52
+ await rm(staging, { recursive: true, force: true });
53
+ }
54
+ }
@@ -0,0 +1,18 @@
1
+ Chromium 159.0.8154.6 (98a2592026af8d673b9fa83b626ac68bdf4ae78a)
2
+ https://chromium.googlesource.com/chromium/src/+/98a2592026af8d673b9fa83b626ac68bdf4ae78a/components/os_crypt/common/keychain_password_mac.mm
3
+
4
+ Use open-browser's stable service name for macOS encrypted profile storage.
5
+ The account selector and KeychainV2 implementation stay upstream.
6
+
7
+ diff --git a/components/os_crypt/common/keychain_password_mac.mm b/components/os_crypt/common/keychain_password_mac.mm
8
+ --- a/components/os_crypt/common/keychain_password_mac.mm
9
+ +++ b/components/os_crypt/common/keychain_password_mac.mm
10
+ @@ -35,7 +35,7 @@
11
+ const char kDefaultServiceName[] = "Chrome Safe Storage";
12
+ const char kDefaultAccountName[] = "Chrome";
13
+ #else
14
+ -const char kDefaultServiceName[] = "Chromium Safe Storage";
15
+ +const char kDefaultServiceName[] = "open-browser Keychain";
16
+ const char kDefaultAccountName[] = "Chromium";
17
+ #endif
18
+
@@ -0,0 +1,144 @@
1
+ diff --git a/content/browser/devtools/protocol/devtools_protocol_browsertest.cc b/content/browser/devtools/protocol/devtools_protocol_browsertest.cc
2
+ index 7f8f784..053c4c2 100644
3
+ --- a/content/browser/devtools/protocol/devtools_protocol_browsertest.cc
4
+ +++ b/content/browser/devtools/protocol/devtools_protocol_browsertest.cc
5
+ @@ -504,6 +504,38 @@ IN_PROC_BROWSER_TEST_F(SyntheticKeyEventTest, DISABLED_KeyboardEventAck) {
6
+ EXPECT_EQ(3, received_responses_count());
7
+ }
8
+
9
+ +IN_PROC_BROWSER_TEST_F(SyntheticMouseEventTest, OpenBrowserInputGuard) {
10
+ + NavigateToURLBlockUntilNavigationsComplete(shell(), GURL("about:blank"), 1);
11
+ + Attach();
12
+ + auto* contents = shell()->web_contents();
13
+ + ASSERT_TRUE(ExecJs(contents, "window.count = 0; onclick = () => ++count;"));
14
+ + auto physical_click = [&]() {
15
+ + SimulateMouseClickAt(contents, 0, blink::WebMouseEvent::Button::kLeft,
16
+ + gfx::Point(15, 15));
17
+ + };
18
+ + physical_click();
19
+ + ASSERT_TRUE(base::test::RunUntil([&] {
20
+ + return EvalJs(contents, "count").ExtractInt() == 1;
21
+ + }));
22
+ + base::DictValue params;
23
+ + params.Set("enabled", true);
24
+ + ASSERT_TRUE(
25
+ + SendCommandSync("Input.setOpenBrowserInputGuard", std::move(params)));
26
+ + for (int i = 0; i < 100; ++i) {
27
+ + physical_click();
28
+ + WaitForNotification("Input.openBrowserInputBlocked", true);
29
+ + EXPECT_EQ(i + 1, EvalJs(contents, "count"));
30
+ + SendMouseEvent("mousePressed", 15, 15, "left", true);
31
+ + SendMouseEvent("mouseReleased", 15, 15, "left", true);
32
+ + ASSERT_EQ(i + 2, EvalJs(contents, "count"));
33
+ + }
34
+ + Detach();
35
+ + physical_click();
36
+ + EXPECT_TRUE(base::test::RunUntil([&] {
37
+ + return EvalJs(contents, "count").ExtractInt() == 102;
38
+ + }));
39
+ +}
40
+ +
41
+ // Flaky: https://crbug.com/1263461
42
+ IN_PROC_BROWSER_TEST_F(SyntheticMouseEventTest, DISABLED_MouseEventAck) {
43
+ NavigateToURLBlockUntilNavigationsComplete(shell(), GURL("about:blank"), 1);
44
+ diff --git a/content/browser/devtools/protocol/input_handler.cc b/content/browser/devtools/protocol/input_handler.cc
45
+ index a769abe..754cb9b 100644
46
+ --- a/content/browser/devtools/protocol/input_handler.cc
47
+ +++ b/content/browser/devtools/protocol/input_handler.cc
48
+ @@ -1173,6 +1173,12 @@ void InputHandler::SetRenderer(int process_host_id,
49
+ host_ = frame_host;
50
+ web_contents_ = WebContentsImpl::FromRenderFrameHostImpl(host_);
51
+
52
+ + if (guard_requested_ && old_web_contents != web_contents_) {
53
+ + input_guard_.reset();
54
+ + if (web_contents_) {
55
+ + SetOpenBrowserInputGuard(true);
56
+ + }
57
+ + }
58
+ if (ignore_input_events_ && old_web_contents != web_contents_) {
59
+ if (web_contents_) {
60
+ scoped_ignore_input_events_ =
61
+ @@ -1192,6 +1198,8 @@ Response InputHandler::Disable() {
62
+ ClearInputState();
63
+ scoped_ignore_input_events_.reset();
64
+ ignore_input_events_ = false;
65
+ + input_guard_.reset();
66
+ + guard_requested_ = false;
67
+ pointer_ids_.clear();
68
+ touch_points_.clear();
69
+ return Response::Success();
70
+ @@ -2095,6 +2103,32 @@ Response InputHandler::EmulateTouchFromMouseEvent(
71
+ return Response::Success();
72
+ }
73
+
74
+ +bool InputHandler::AllowGuardedInput(const blink::WebInputEvent& event) {
75
+ + if (event.GetModifiers() & blink::WebInputEvent::kFromDebugger) {
76
+ + return true;
77
+ + }
78
+ + if (event.GetType() == blink::WebInputEvent::Type::kMouseDown ||
79
+ + event.GetType() == blink::WebInputEvent::Type::kTouchStart) {
80
+ + frontend_->OpenBrowserInputBlocked();
81
+ + }
82
+ + return false;
83
+ +}
84
+ +
85
+ +Response InputHandler::SetOpenBrowserInputGuard(bool enabled) {
86
+ + if (enabled && !web_contents_) {
87
+ + return Response::ServerError("No attached WebContents");
88
+ + }
89
+ + guard_requested_ = enabled;
90
+ + if (!enabled) {
91
+ + input_guard_.reset();
92
+ + } else if (!input_guard_) {
93
+ + // The callback is removed with the session-owned token.
94
+ + input_guard_ = web_contents_->IgnoreInputEvents(base::BindRepeating(
95
+ + &InputHandler::AllowGuardedInput, base::Unretained(this)));
96
+ + }
97
+ + return Response::Success();
98
+ +}
99
+ +
100
+ Response InputHandler::SetIgnoreInputEvents(bool ignore) {
101
+ ignore_input_events_ = ignore;
102
+ if (!ignore) {
103
+ diff --git a/content/browser/devtools/protocol/input_handler.h b/content/browser/devtools/protocol/input_handler.h
104
+ index 4c25a8c..ed48dfa 100644
105
+ --- a/content/browser/devtools/protocol/input_handler.h
106
+ +++ b/content/browser/devtools/protocol/input_handler.h
107
+ @@ -153,6 +153,7 @@ class InputHandler : public DevToolsDomainHandler, public Input::Backend {
108
+ std::optional<int> modifiers,
109
+ std::optional<int> click_count) override;
110
+
111
+ + Response SetOpenBrowserInputGuard(bool enabled) override;
112
+ Response SetIgnoreInputEvents(bool ignore) override;
113
+ Response SetInterceptDrags(bool enabled) override;
114
+
115
+ @@ -358,6 +359,9 @@ class InputHandler : public DevToolsDomainHandler, public Input::Backend {
116
+ bool ignore_input_events_ = false;
117
+ std::optional<content::WebContents::ScopedIgnoreInputEvents>
118
+ scoped_ignore_input_events_;
119
+ + bool guard_requested_ = false;
120
+ + std::optional<content::WebContents::ScopedIgnoreInputEvents> input_guard_;
121
+ + bool AllowGuardedInput(const blink::WebInputEvent& event);
122
+ bool intercept_drags_ = false;
123
+ DragController drag_controller_;
124
+ const bool allow_file_access_;
125
+ diff --git a/third_party/blink/public/devtools_protocol/domains/Input.pdl b/third_party/blink/public/devtools_protocol/domains/Input.pdl
126
+ index 815bf7c..3e8a22d 100644
127
+ --- a/third_party/blink/public/devtools_protocol/domains/Input.pdl
128
+ +++ b/third_party/blink/public/devtools_protocol/domains/Input.pdl
129
+ @@ -256,6 +256,15 @@ domain Input
130
+ # Number of times the mouse button was clicked (default: 0).
131
+ optional integer clickCount
132
+
133
+ + # Session-scoped guard for a managed WebContents. Browser toolbar events
134
+ + # remain outside this target. Ends automatically on detach.
135
+ + experimental command setOpenBrowserInputGuard
136
+ + parameters
137
+ + boolean enabled
138
+ +
139
+ + # A physical press was ignored. No page coordinates or input are exposed.
140
+ + experimental event openBrowserInputBlocked
141
+ +
142
+ # Ignores input events (useful while auditing page).
143
+ command setIgnoreInputEvents
144
+ parameters
@@ -0,0 +1,22 @@
1
+ """Archive Windows packages and unpack checksum-verified upstream ZIPs."""
2
+ import os
3
+ import sys
4
+ from pathlib import Path
5
+ from zipfile import ZIP_DEFLATED, ZipFile
6
+
7
+ mode, source, destination = sys.argv[1:]
8
+ if mode == 'extract':
9
+ with ZipFile(source) as archive:
10
+ for entry in archive.infolist():
11
+ target = Path(archive.extract(entry, destination))
12
+ permissions = (entry.external_attr >> 16) & 0o777
13
+ if permissions and os.name != 'nt':
14
+ target.chmod(permissions)
15
+ elif mode == 'pack':
16
+ root = Path(source)
17
+ with ZipFile(destination, 'w', compression=ZIP_DEFLATED, compresslevel=4) as archive:
18
+ for file in sorted(root.rglob('*')):
19
+ if file.is_file():
20
+ archive.write(file, file.relative_to(root.parent))
21
+ else:
22
+ raise SystemExit('expected pack or extract')
@@ -0,0 +1,77 @@
1
+ import { execFileSync } from 'node:child_process';
2
+ import { fileURLToPath } from 'node:url';
3
+
4
+ const entitlements = process.env.OPEN_BROWSER_MACOS_ENTITLEMENTS ||
5
+ fileURLToPath(new URL('./macos-entitlements.plist', import.meta.url));
6
+
7
+ function nestedCodePaths(bundle) {
8
+ const files = execFileSync('/usr/bin/find', [bundle, '-type', 'f', '-print0']);
9
+ const candidates = files.toString('utf8').split('\0').filter(Boolean);
10
+ const machO = candidates.filter(file => {
11
+ try {
12
+ return execFileSync('/usr/bin/file', ['-b', file], { encoding: 'utf8' }).includes('Mach-O');
13
+ } catch {
14
+ return false;
15
+ }
16
+ });
17
+ const bundles = new Set();
18
+ for (const file of machO) {
19
+ let current = file;
20
+ while (current.startsWith(bundle + '/') && current !== bundle) {
21
+ if (/\.(app|framework|xpc|bundle)$/.test(current)) bundles.add(current);
22
+ current = current.slice(0, current.lastIndexOf('/'));
23
+ }
24
+ }
25
+ return [
26
+ ...machO.sort((a, b) => b.length - a.length),
27
+ ...[...bundles].sort((a, b) => b.length - a.length),
28
+ ];
29
+ }
30
+
31
+ function signCode(path, identity, preserveEntitlements = false) {
32
+ const timestamp = process.env.OPEN_BROWSER_CODESIGN_TIMESTAMP === 'none'
33
+ ? '--timestamp=none'
34
+ : '--timestamp';
35
+ const args = ['--force', timestamp, '--options', 'runtime', '--entitlements', entitlements, '--sign', identity];
36
+ if (preserveEntitlements) args.push('--preserve-metadata=entitlements');
37
+ for (let attempt = 0; ; attempt += 1) {
38
+ try {
39
+ execFileSync('/usr/bin/codesign', [...args, path], { stdio: 'inherit' });
40
+ return;
41
+ } catch (error) {
42
+ if (timestamp === '--timestamp=none' || attempt >= 2) throw error;
43
+ execFileSync('/bin/sleep', ['1']);
44
+ }
45
+ }
46
+ }
47
+
48
+ export function signingIdentity(requested = process.env.OPEN_BROWSER_SIGN_IDENTITY || process.env.APPLE_SIGNING_IDENTITY) {
49
+ const listing = execFileSync('/usr/bin/security', ['find-identity', '-v', '-p', 'codesigning'], { encoding: 'utf8' });
50
+ const identities = [...listing.matchAll(/^\s*\d+\) ([0-9A-F]{40}) "([^"]+)"\s*$/gm)];
51
+ const matches = identities.filter(([, hash, name]) => name.startsWith('Developer ID Application:') &&
52
+ (!requested || hash === requested.trim().toUpperCase() || name === requested.trim()));
53
+ if (matches.length !== 1) throw new Error(
54
+ 'macOS 构建需要稳定的签名身份。请在构建钥匙串中安装有效的 Developer ID Application 证书及配对私钥。' +
55
+ '可用 security find-identity -v -p codesigning 查看身份。' +
56
+ '有多项 Developer ID Application 身份时,请将 OPEN_BROWSER_SIGN_IDENTITY 设为完整证书名称或其 40 位 SHA-1。');
57
+ return matches[0][1];
58
+ }
59
+
60
+ export function signBundle(bundle, identity, nested = false) {
61
+ for (const path of nestedCodePaths(bundle)) signCode(path, identity);
62
+ signCode(bundle, identity, nested);
63
+ execFileSync('/usr/bin/codesign', ['--verify', '--strict', '--deep', bundle], { stdio: 'inherit' });
64
+ }
65
+
66
+ export function verifyUpgrade(previous, candidate) {
67
+ // Keychain ACLs use the requesting executable's designated requirement.
68
+ // Validate each bundle against the other build, including certificate renewals
69
+ // where the team and bundle identifier remain the same.
70
+ for (const [origin, target] of [[previous, candidate], [candidate, previous]]) {
71
+ const output = execFileSync('/usr/bin/codesign', ['-d', '-r-', origin], { encoding: 'utf8' });
72
+ const line = output.split('\n').find(value => value.startsWith('designated => '));
73
+ if (!line) throw new Error('无法读取现有版本的签名要求。');
74
+ const requirement = line.slice('designated => '.length);
75
+ execFileSync('/usr/bin/codesign', ['--verify', '-R', '=' + requirement, target], { stdio: 'inherit' });
76
+ }
77
+ }