@seekskyworld/open-browser 0.1.0 → 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 (61) hide show
  1. package/Docs/open-browser-api.d.ts +23 -5
  2. 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 +51 -3
  3. package/README.md +14 -5
  4. package/README.zh-CN.md +16 -5
  5. package/access-registry.mjs +5 -0
  6. package/action-execution.mjs +32 -21
  7. package/api-contract.mjs +14 -2
  8. package/browser-extension/manifest.json +1 -4
  9. package/browser-extension/newtab.css +6 -0
  10. package/browser-extension/newtab.js +53 -2
  11. package/browser-extension/phase-labels.js +1 -1
  12. package/browser-extension/popup.css +1 -1
  13. package/browser-extension/popup.html +14 -4
  14. package/browser-extension/popup.js +101 -20
  15. package/browser-extension/tab-action.js +3 -2
  16. package/browser-extension/worker.js +102 -9
  17. package/build-profile.mjs +23 -0
  18. package/capability-matrix.mjs +3 -3
  19. package/chromium-host.mjs +78 -18
  20. package/chromium-shell.mjs +77 -48
  21. package/cli.mjs +59 -1
  22. package/contract-validation.mjs +1 -1
  23. package/desktop/Info.plist +1 -1
  24. package/desktop/OBControlBar.m +7 -3
  25. package/desktop/WorkspacePanel.m +2 -1
  26. package/desktop/brand-keychain.py +20 -4
  27. package/desktop/build-macos.mjs +26 -10
  28. package/desktop/build-managed-input.mjs +37 -0
  29. package/desktop/build-profile.mjs +6 -0
  30. package/desktop/build.mjs +8 -0
  31. package/desktop/macos-entitlements.plist +12 -0
  32. package/desktop/notarize-macos.mjs +145 -0
  33. package/desktop/package-macos.mjs +54 -0
  34. package/desktop/patches/chromium-managed-input.patch +144 -0
  35. package/desktop/sign.mjs +48 -4
  36. package/desktop/start-profile.mjs +5 -0
  37. package/desktop/start.mjs +25 -3
  38. package/desktop/verify-macos-release.mjs +61 -0
  39. package/diagnostics.mjs +9 -0
  40. package/engine-service.mjs +174 -18
  41. package/managed-input.mjs +138 -0
  42. package/mcp-http.mjs +84 -0
  43. package/mcp-server.mjs +41 -0
  44. package/mcp.mjs +2 -40
  45. package/package.json +22 -2
  46. package/page-activity.mjs +95 -28
  47. package/page-observation.mjs +41 -3
  48. package/paths.mjs +5 -3
  49. package/receipt-store.mjs +9 -2
  50. package/runtime.mjs +10 -1
  51. package/sdk.mjs +32 -15
  52. package/service.mjs +21 -2
  53. package/skill-links.mjs +90 -0
  54. package/skills/open-browser/SKILL.macos.md +112 -0
  55. package/skills/open-browser/SKILL.md +24 -3
  56. package/skills/open-browser/SKILL.windows.md +112 -0
  57. package/skills/open-browser/scripts/bootstrap.mjs +80 -1
  58. package/tab-adoption.mjs +77 -0
  59. package/uploads.mjs +4 -4
  60. package/workspace-lifecycle.mjs +74 -6
  61. package/workspace-state.mjs +14 -2
@@ -6,27 +6,34 @@ import { fileURLToPath } from 'node:url';
6
6
  import { copyApplication } from './package-assets.mjs';
7
7
  import { engineExecutable } from '../runtime.mjs';
8
8
  import { signBundle, signingIdentity, verifyUpgrade } from './sign.mjs';
9
+ import { isDevelopmentBuild } from '../build-profile.mjs';
9
10
 
10
11
  const root = fileURLToPath(new URL('../', import.meta.url));
12
+ const archOption = process.argv.findIndex(value => value === '--arch');
13
+ const requestedArch = archOption >= 0 ? process.argv[archOption + 1] : process.env.OPEN_BROWSER_TARGET_ARCH || process.arch;
11
14
  const sums = {
12
15
  arm64: 'e7131995759b61a0170b646010d2ad35a5d37b4cb0d471f3e8317eac6f742f3d',
13
16
  x64: 'c53383238206b9ae4db23c5d8a63645e2e753bec8ab51a49cc81939aa64e9422',
14
17
  };
15
- if (process.platform !== 'darwin' || !sums[process.arch]) throw new Error('macOS arm64 or x64 required');
18
+ if (process.platform !== 'darwin' || !sums[requestedArch]) throw new Error('macOS 构建目标架构必须是 arm64 或 x64。');
19
+ if (archOption >= 0 && !requestedArch) throw new Error('--arch 需要 arm64 或 x64。');
20
+ if (requestedArch !== process.arch)
21
+ throw new Error(`当前 Node 是 ${process.arch},不能伪造 ${requestedArch} 架构构建。请在对应架构的 macOS、Rosetta 下的 x64 Node,或 x64 CI runner 上运行。`);
22
+ process.env.OPEN_BROWSER_TARGET_ARCH = requestedArch;
16
23
  const identity = signingIdentity();
17
24
  await engineExecutable();
18
25
  const out = path.join(root, 'dist');
19
26
  const cache = path.join(root, '.open-browser', 'build-cache');
20
27
  await mkdir(out, { recursive: true });
21
28
  await mkdir(cache, { recursive: true });
22
- const filename = 'node-v22.23.5-darwin-' + process.arch + '.tar.gz';
29
+ const filename = 'node-v22.23.5-darwin-' + requestedArch + '.tar.gz';
23
30
  const archive = path.join(cache, filename);
24
31
  const checksum = async p => createHash('sha256').update(await readFile(p)).digest('hex');
25
- if ((await checksum(archive).catch(() => '')) !== sums[process.arch]) {
32
+ if ((await checksum(archive).catch(() => '')) !== sums[requestedArch]) {
26
33
  const temp = archive + '.' + process.pid;
27
34
  execFileSync('curl', ['--fail', '--location', '--retry', '2', '--output', temp,
28
35
  'https://nodejs.org/dist/v22.23.5/' + filename], { stdio: 'inherit' });
29
- if (await checksum(temp) !== sums[process.arch]) throw new Error('Node archive integrity check failed');
36
+ if (await checksum(temp) !== sums[requestedArch]) throw new Error('Node archive integrity check failed');
30
37
  await rename(temp, archive);
31
38
  }
32
39
 
@@ -45,11 +52,18 @@ try {
45
52
  execFileSync('tar', ['-xzf', archive, '-C', node, '--strip-components', '1',
46
53
  prefix + '/bin/node', prefix + '/LICENSE']);
47
54
  await copyFile(path.join(root, 'desktop/Info.plist'), path.join(contents, 'Info.plist'));
48
- execFileSync('xcrun', ['clang', '-fobjc-arc', '-O2', '-framework', 'AppKit', '-framework', 'CoreGraphics',
55
+ if (isDevelopmentBuild) {
56
+ const outerInfo = path.join(contents, 'Info.plist');
57
+ execFileSync('plutil', ['-replace', 'CFBundleIdentifier', '-string', 'local.open-browser.desktop-dev', outerInfo]);
58
+ execFileSync('plutil', ['-replace', 'CFBundleName', '-string', 'open-browser Dev', outerInfo]);
59
+ execFileSync('plutil', ['-replace', 'CFBundleDisplayName', '-string', 'open-browser Dev', outerInfo]);
60
+ }
61
+ execFileSync('xcrun', ['clang', '-arch', requestedArch, '-fobjc-arc', '-O2', '-framework', 'AppKit', '-framework', 'CoreGraphics',
49
62
  path.join(root, 'desktop/Launcher.m'), path.join(root, 'desktop/OBControlBar.m'),
50
63
  '-o', path.join(contents, 'MacOS/open-browser')], { stdio: 'inherit' });
51
64
  await copyFile(path.join(root, 'desktop/icons/open-browser.icns'), path.join(resources, 'open-browser.icns'));
52
65
  await copyApplication(app);
66
+ await writeFile(path.join(app, '.open-browser-build-profile'), (isDevelopmentBuild ? 'dev' : 'stable') + '\n');
53
67
  const engine = path.join(app, '.open-browser', 'engine');
54
68
  await mkdir(engine, { recursive: true });
55
69
  const sourceEngine = path.join(root, '.open-browser', 'engine');
@@ -59,30 +73,32 @@ try {
59
73
  // Brand the packaged browser, which owns the visible window and Dock entry.
60
74
  const originalBinary = path.join(engine, executable);
61
75
  const originalBundle = path.resolve(path.dirname(originalBinary), '../..');
62
- const browserBundle = path.join(path.dirname(originalBundle), 'open-browser.app');
76
+ const browserName = isDevelopmentBuild ? 'open-browser-dev.app' : 'open-browser.app';
77
+ const browserBundle = path.join(path.dirname(originalBundle), browserName);
63
78
  await rename(originalBundle, browserBundle);
64
79
  const binary = path.join(browserBundle, 'Contents/MacOS/open-browser');
65
80
  await rename(path.join(path.dirname(binary), path.basename(originalBinary)), binary);
66
81
  const plist = path.join(browserBundle, 'Contents/Info.plist');
67
82
  for (const key of ['CFBundleName', 'CFBundleDisplayName', 'CFBundleExecutable'])
68
83
  execFileSync('plutil', ['-replace', key, '-string', 'open-browser', plist]);
69
- execFileSync('plutil', ['-replace', 'CFBundleIdentifier', '-string', 'local.open-browser.chromium', plist]);
84
+ execFileSync('plutil', ['-replace', 'CFBundleIdentifier', '-string', isDevelopmentBuild ? 'local.open-browser-dev.chromium' : 'local.open-browser.chromium', plist]);
70
85
  execFileSync('python3', [path.join(root, 'desktop/brand-locales.py'), browserBundle], { stdio: 'inherit' });
71
86
  execFileSync('python3', [path.join(root, 'desktop/brand-keychain.py'), browserBundle], { stdio: 'inherit' });
72
87
  execFileSync('python3', [path.join(root, 'desktop/brand-macos-icons.py'), browserBundle], { stdio: 'inherit' });
73
88
  signBundle(browserBundle, identity, true);
74
89
  const packageInfo = JSON.parse(await readFile(path.join(root, 'node_modules/playwright-core/package.json'), 'utf8'));
75
- const manifest = 'engine-' + packageInfo.version + '-' + process.platform + '-' + process.arch + '.json';
90
+ const manifest = 'engine-' + packageInfo.version + '-' + process.platform + '-' + requestedArch + '.json';
76
91
  await writeFile(path.join(engine, manifest), JSON.stringify({ executable: path.relative(engine, binary), profileVersion: 2 }) + '\n');
77
92
  signBundle(bundle, identity);
78
- const target = path.join(out, 'open-browser.app');
93
+ const outputName = isDevelopmentBuild ? 'open-browser-dev.app' : requestedArch === 'arm64' ? 'open-browser.app' : 'open-browser-x64.app';
94
+ const target = path.join(out, outputName);
79
95
  const priorEngine = path.join(target, 'Contents/Resources/app/.open-browser/engine');
80
96
  const entries = await readdir(priorEngine).catch(e => { if (e.code === 'ENOENT') return []; throw e; });
81
97
  for (const entry of entries.filter(name => /^engine-.*-darwin-(arm64|x64)\.json$/.test(name))) {
82
98
  const prior = JSON.parse(await readFile(path.join(priorEngine, entry), 'utf8'));
83
99
  if (prior.profileVersion !== 2) continue;
84
100
  const previousBrowser = path.resolve(priorEngine, prior.executable, '../../..');
85
- if (!previousBrowser.startsWith(priorEngine + path.sep) || path.basename(previousBrowser) !== 'open-browser.app')
101
+ if (!previousBrowser.startsWith(priorEngine + path.sep) || !['open-browser.app', 'open-browser-x64.app', 'open-browser-dev.app'].includes(path.basename(previousBrowser)))
86
102
  throw new Error('旧版本 Chromium 路径无效。');
87
103
  verifyUpgrade(previousBrowser, browserBundle);
88
104
  }
@@ -0,0 +1,37 @@
1
+ // Build the Dev engine in an already synced Chromium checkout on its native OS.
2
+ import { execFileSync } from 'node:child_process';
3
+ import { existsSync, realpathSync } from 'node:fs';
4
+ import path from 'node:path';
5
+ import { fileURLToPath } from 'node:url';
6
+
7
+ const revision = '98a2592026af8d673b9fa83b626ac68bdf4ae78a';
8
+ const patch = fileURLToPath(new URL('./patches/chromium-managed-input.patch', import.meta.url));
9
+ const arg = process.argv[2];
10
+ if (!arg || process.argv.length !== 3) throw Error('Usage: node desktop/build-managed-input.mjs <chromium-src>');
11
+ const src = realpathSync(arg);
12
+ const run = (file, args, options = {}) => execFileSync(file, args, {cwd:src, stdio:'inherit', ...options});
13
+ const head = run('git', ['rev-parse', 'HEAD'], {stdio:'pipe', encoding:'utf8'}).trim();
14
+ if (head !== revision) throw Error('Input guard requires Chromium revision ' + revision);
15
+ try { run('git', ['apply', '--reverse', '--check', patch], {stdio:'pipe'}); }
16
+ catch {
17
+ run('git', ['apply', '--check', patch]);
18
+ run('git', ['apply', patch]);
19
+ }
20
+ const out = 'out/OpenBrowserInput';
21
+ const args = 'is_debug=false is_component_build=false symbol_level=0';
22
+ const windows = process.platform === 'win32';
23
+ // On Windows depot_tools ships GN as a batch wrapper. Pass only fixed arguments
24
+ // through cmd.exe, with the checkout supplied as cwd.
25
+ if (windows) {
26
+ run('cmd.exe', ['/d', '/c', 'gn gen out/OpenBrowserInput "--args=' + args + '"']);
27
+ run('cmd.exe', ['/d', '/c', 'autoninja -C out/OpenBrowserInput chrome content_browsertests']);
28
+ } else {
29
+ run('gn', ['gen', out, '--args=' + args]);
30
+ run('autoninja', ['-C', out, 'chrome', 'content_browsertests']);
31
+ }
32
+ const tests = path.join(src, out, windows ? 'content_browsertests.exe' : 'content_browsertests');
33
+ run(tests, ['--gtest_filter=SyntheticMouseEventTest.OpenBrowserInputGuard']);
34
+ const engine = path.join(src, out, windows ? 'chrome.exe' : process.platform === 'darwin'
35
+ ? 'Chromium.app/Contents/MacOS/Chromium' : 'chrome');
36
+ if (!existsSync(engine)) throw Error('Chromium build did not produce ' + engine);
37
+ console.log('Dev engine for OPEN_BROWSER_DEV_CHROMIUM:', engine);
@@ -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');
package/desktop/build.mjs CHANGED
@@ -1,3 +1,11 @@
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];
1
9
  if (process.platform === 'darwin') {
2
10
  await import('./build-macos.mjs');
3
11
  } else {
@@ -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,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,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
package/desktop/sign.mjs CHANGED
@@ -1,6 +1,51 @@
1
1
  import { execFileSync } from 'node:child_process';
2
+ import { fileURLToPath } from 'node:url';
2
3
 
3
- export function signingIdentity(requested = process.env.OPEN_BROWSER_SIGN_IDENTITY) {
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) {
4
49
  const listing = execFileSync('/usr/bin/security', ['find-identity', '-v', '-p', 'codesigning'], { encoding: 'utf8' });
5
50
  const identities = [...listing.matchAll(/^\s*\d+\) ([0-9A-F]{40}) "([^"]+)"\s*$/gm)];
6
51
  const matches = identities.filter(([, hash, name]) => name.startsWith('Developer ID Application:') &&
@@ -13,9 +58,8 @@ export function signingIdentity(requested = process.env.OPEN_BROWSER_SIGN_IDENTI
13
58
  }
14
59
 
15
60
  export function signBundle(bundle, identity, nested = false) {
16
- const args = ['--force', '--timestamp=none', '--sign', identity];
17
- if (nested) args.push('--deep', '--preserve-metadata=entitlements');
18
- execFileSync('/usr/bin/codesign', [...args, bundle], { stdio: 'inherit' });
61
+ for (const path of nestedCodePaths(bundle)) signCode(path, identity);
62
+ signCode(bundle, identity, nested);
19
63
  execFileSync('/usr/bin/codesign', ['--verify', '--strict', '--deep', bundle], { stdio: 'inherit' });
20
64
  }
21
65
 
@@ -0,0 +1,5 @@
1
+ #!/usr/bin/env node
2
+ const [profile] = process.argv.slice(2);
3
+ if (!['dev', 'stable'].includes(profile)) throw new Error('usage: start-profile.mjs <dev|stable>');
4
+ process.env.OPEN_BROWSER_BUILD_PROFILE = profile;
5
+ await import('./start.mjs');
package/desktop/start.mjs CHANGED
@@ -1,9 +1,31 @@
1
1
  import { execFileSync } from 'node:child_process';
2
- import { existsSync } from 'node:fs';
2
+ import { existsSync, readFileSync } from 'node:fs';
3
3
  import { fileURLToPath } from 'node:url';
4
+ import net from 'node:net';
5
+ import { pidPath, socketPath } from '../paths.mjs';
6
+ import { isDevelopmentBuild } from '../build-profile.mjs';
4
7
 
5
- if (process.platform === 'darwin') {
6
- const bundle = fileURLToPath(new URL('../dist/open-browser.app', import.meta.url));
8
+ async function wakeExisting() {
9
+ try {
10
+ const pid = Number(readFileSync(pidPath, 'utf8').trim());
11
+ if (!Number.isSafeInteger(pid) || pid <= 0) return false;
12
+ process.kill(pid, 0);
13
+ const active = await new Promise(resolve => {
14
+ const probe = net.connect(socketPath);
15
+ probe.once('connect', () => { probe.destroy(); resolve(true); });
16
+ probe.once('error', () => resolve(false));
17
+ });
18
+ if (!active) return false;
19
+ process.kill(pid, 'SIGUSR2');
20
+ return true;
21
+ } catch { return false; }
22
+ }
23
+
24
+ if (await wakeExisting()) process.exit(0);
25
+
26
+ if (process.platform === 'darwin' && !(isDevelopmentBuild && process.env.OPEN_BROWSER_DEV_CHROMIUM)) {
27
+ const bundleName = isDevelopmentBuild ? 'open-browser-dev.app' : process.arch === 'x64' ? 'open-browser-x64.app' : 'open-browser.app';
28
+ const bundle = fileURLToPath(new URL('../dist/' + bundleName, import.meta.url));
7
29
  if (!existsSync(bundle)) await import('./build.mjs');
8
30
  execFileSync('open', [bundle], { stdio: 'inherit' });
9
31
  } else {