codex-control-chrome-mcp 1.1.0 → 1.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.
package/CHANGELOG.md CHANGED
@@ -6,6 +6,19 @@ This project follows semantic versioning.
6
6
 
7
7
  ## [Unreleased]
8
8
 
9
+ ## [1.2.0] - 2026-06-29
10
+
11
+ ### Added
12
+
13
+ - Microsoft Edge support as a first-class browser alongside Chrome. `install-native-host`, `uninstall-native-host`, and `status` accept `--browser <chrome|edge|all>`.
14
+ - Auto-detection: without `--browser`, `install-native-host` installs for every supported browser whose profile directory exists, `uninstall-native-host` targets every browser it previously installed for, and `status` reports both browsers.
15
+ - The MCP stdio server's self-heal now re-asserts the manifest for every browser it manages, not just Chrome.
16
+
17
+ ### Changed
18
+
19
+ - Native host install state is now stored per browser (`install-state.<browser>.json` / `config.<browser>.json`). Chrome keeps the original unsuffixed filenames, so existing installs remain valid; Edge no longer clobbers Chrome's restore and self-heal metadata.
20
+ - `status` output now nests install state under each browser (`install.chrome`, `install.edge`). The `chrome_status` MCP tool additionally reports `manifestPaths` for every supported browser.
21
+
9
22
  ## [1.1.0] - 2026-06-27
10
23
 
11
24
  ### Added
package/README.md CHANGED
@@ -20,7 +20,7 @@ This is an independent community project. It is not affiliated with OpenAI, Code
20
20
  The current implementation provides:
21
21
 
22
22
  - official `@modelcontextprotocol/sdk` stdio server
23
- - Chrome Native Messaging host mode
23
+ - Chrome and Microsoft Edge Native Messaging host mode
24
24
  - install/uninstall commands with manifest backup
25
25
  - JSON-RPC bridge socket under `/tmp/codex-browser-use`
26
26
  - Chrome tab, navigation, screenshot, CDP, and event MCP tools
@@ -36,16 +36,33 @@ The current implementation provides:
36
36
 
37
37
  Node.js 20 or newer is required. npm Trusted Publishing for releases uses Node.js 24 in GitHub Actions.
38
38
 
39
+ ## Browser Support
40
+
41
+ Both Chromium browsers use the same Codex extension and the same `chrome-extension://` origin, so a single manifest works for either.
42
+
43
+ | Browser | Status | Notes |
44
+ | --- | --- | --- |
45
+ | Google Chrome | Tested | Default target. |
46
+ | Microsoft Edge | Supported | Same extension and native-messaging mechanism; installs to the Edge `NativeMessagingHosts` directory. |
47
+
48
+ Commands accept `--browser <chrome\|edge\|all>`. Without the flag, `install-native-host` installs for every supported browser whose profile directory exists, `uninstall-native-host` targets every browser it previously installed for, and `status` reports both.
49
+
39
50
  ## Quick Start
40
51
 
41
- Install and enable the [Codex Chrome Extension](https://chromewebstore.google.com/detail/hehggadaopoacecdllhhajmbjkdcmajg) in the Chrome profile you want to automate.
52
+ Install and enable the [Codex Chrome Extension](https://chromewebstore.google.com/detail/hehggadaopoacecdllhhajmbjkdcmajg) in the Chrome or Edge profile you want to automate.
42
53
 
43
- Install the Chrome native host:
54
+ Install the native host (auto-detects the browsers present):
44
55
 
45
56
  ```bash
46
57
  npx -y codex-control-chrome-mcp@latest install-native-host
47
58
  ```
48
59
 
60
+ To target one browser explicitly:
61
+
62
+ ```bash
63
+ npx -y codex-control-chrome-mcp@latest install-native-host --browser edge
64
+ ```
65
+
49
66
  Configure your Agent to use the MCP stdio server:
50
67
 
51
68
  ```json
@@ -144,7 +161,7 @@ node ./bin/codex-control-chrome-mcp.js --native-host
144
161
 
145
162
  ## Troubleshooting
146
163
 
147
- `status` reports a `registered` flag and a `classification` of the live manifest. When `registered` is `false` and `classification.kind` is `official-openai`, a Codex update has reclaimed the manifest (see below). `classification` identifies OpenAI's genuine host by stable signals — the `com.openai.codexextension` name, the official extension origin, the bundle path, the binary format, and (on macOS) the OpenAI code signature — not by filename.
164
+ `status` reports, per browser (under `install.chrome` / `install.edge`), a `registered` flag and a `classification` of the live manifest. When `registered` is `false` and `classification.kind` is `official-openai`, a Codex update has reclaimed that browser's manifest (see below). `classification` identifies OpenAI's genuine host by stable signals — the `com.openai.codexextension` name, the official extension origin, the bundle path, the binary format, and (on macOS) the OpenAI code signature — not by filename.
148
165
 
149
166
  ### A Codex update stopped the bridge
150
167
 
package/docs/install.md CHANGED
@@ -24,35 +24,47 @@ This is an independent community project. It is not affiliated with OpenAI, Code
24
24
  | Platform | Status | Notes |
25
25
  | --- | --- | --- |
26
26
  | macOS | Tested | Primary supported platform. |
27
- | Linux | Experimental | Uses the Google Chrome user-level Native Messaging host directory. |
28
- | Windows | Unsupported | Chrome Native Messaging registration uses registry keys on Windows and is not implemented yet. |
27
+ | Linux | Experimental | Uses the browser's user-level Native Messaging host directory. |
28
+ | Windows | Unsupported | Native Messaging registration uses registry keys on Windows and is not implemented yet. |
29
+
30
+ ## Browser Support
31
+
32
+ | Browser | Status | Notes |
33
+ | --- | --- | --- |
34
+ | Google Chrome | Tested | Default target. |
35
+ | Microsoft Edge | Supported | Same Codex extension and `chrome-extension://` origin; installs to Edge's `NativeMessagingHosts` directory. |
36
+
37
+ Commands accept `--browser <chrome|edge|all>`. Without it, `install-native-host` auto-detects the browsers present on the machine, `uninstall-native-host` targets every browser it previously installed for, and `status` reports both browsers.
29
38
 
30
39
  ## Install
31
40
 
32
- First install and enable the [Codex Chrome Extension](https://chromewebstore.google.com/detail/hehggadaopoacecdllhhajmbjkdcmajg) in the Chrome profile you want to automate.
41
+ First install and enable the [Codex Chrome Extension](https://chromewebstore.google.com/detail/hehggadaopoacecdllhhajmbjkdcmajg) in the Chrome or Edge profile you want to automate.
33
42
 
34
43
  ```bash
35
44
  npx -y codex-control-chrome-mcp@latest install-native-host
36
45
  ```
37
46
 
38
- This writes a stable launcher:
47
+ Without `--browser`, this installs for every supported browser whose profile directory exists. Pass `--browser <chrome|edge|all>` to target one explicitly.
48
+
49
+ This writes a stable per-browser launcher (Edge uses the `-edge` suffix):
39
50
 
40
51
  ```text
41
52
  ~/.codex-control-chrome-mcp/native-host-launcher
53
+ ~/.codex-control-chrome-mcp/native-host-launcher-edge
42
54
  ```
43
55
 
44
- The launcher invokes:
56
+ The launcher invokes (the `--browser` flag tells the host which browser's config to read for proxy mode):
45
57
 
46
58
  ```bash
47
- npx -y codex-control-chrome-mcp@1.0.0 --native-host "$@"
59
+ npx -y codex-control-chrome-mcp@latest --native-host --browser chrome "$@"
48
60
  ```
49
61
 
50
- The installer:
62
+ For each selected browser the installer:
51
63
 
52
- 1. Reads the existing `com.openai.codexextension.json`.
64
+ 1. Reads the existing `com.openai.codexextension.json` in that browser's directory.
53
65
  2. Backs it up in the same directory with a timestamped suffix.
54
66
  3. Writes a new manifest pointing to this project's CLI.
55
- 4. Records restore metadata in `~/.codex-control-chrome-mcp/install-state.json`.
67
+ 4. Records restore metadata in `~/.codex-control-chrome-mcp/install-state.json` (Chrome) or `install-state.<browser>.json` (other browsers), so browsers never clobber each other's state.
56
68
  5. Records the genuine OpenAI host path for proxy mode when available.
57
69
 
58
70
  ### Identifying the official host
@@ -70,16 +82,18 @@ When choosing the proxy target it prefers the **live** manifest (most up to date
70
82
  skips paths that no longer exist, so a renamed or removed host is never recorded as the
71
83
  official target. `status` reports these signals under `classification`.
72
84
 
73
- Example manifest path on macOS:
85
+ Example manifest paths on macOS:
74
86
 
75
87
  ```text
76
88
  ~/Library/Application Support/Google/Chrome/NativeMessagingHosts/com.openai.codexextension.json
89
+ ~/Library/Application Support/Microsoft Edge/NativeMessagingHosts/com.openai.codexextension.json
77
90
  ```
78
91
 
79
- Example manifest path on Linux:
92
+ Example manifest paths on Linux:
80
93
 
81
94
  ```text
82
95
  ~/.config/google-chrome/NativeMessagingHosts/com.openai.codexextension.json
96
+ ~/.config/microsoft-edge/NativeMessagingHosts/com.openai.codexextension.json
83
97
  ```
84
98
 
85
99
  ## MCP Client Config
@@ -120,7 +134,7 @@ For local development:
120
134
  npx -y codex-control-chrome-mcp@latest uninstall-native-host
121
135
  ```
122
136
 
123
- This restores the backed-up official manifest if one was recorded.
137
+ This restores the backed-up official manifest if one was recorded. Without `--browser` it uninstalls from every browser it previously installed for; pass `--browser <chrome|edge|all>` to scope it.
124
138
 
125
139
  Use `--force` only if the current manifest was manually edited and you still want to restore/remove it:
126
140
 
@@ -134,11 +148,13 @@ npx -y codex-control-chrome-mcp@latest uninstall-native-host --force
134
148
  npx -y codex-control-chrome-mcp@latest status
135
149
  ```
136
150
 
137
- This prints:
151
+ This prints, per browser under `install.chrome` / `install.edge`:
138
152
 
139
153
  - active native host manifest
140
154
  - saved install state
141
- - discovered bridge sockets under `/tmp/codex-browser-use`
155
+ - the `registered` flag and live-manifest `classification`
156
+
157
+ and the discovered bridge sockets under `/tmp/codex-browser-use`. Pass `--browser` to scope it to one browser.
142
158
 
143
159
  ## Operational Notes
144
160
 
@@ -167,8 +183,8 @@ If `status` shows no sockets:
167
183
  1. Confirm Chrome is running with the profile where the extension is installed.
168
184
  2. Reload or disable/enable the Codex Chrome Extension.
169
185
  3. Run `npx -y codex-control-chrome-mcp@latest status`.
170
- 4. Check `registered`. If it is `false` and `classification.kind` is `official-openai`, a Codex update reclaimed the manifest. The stdio server re-asserts it on next startup; reload the extension or restart Chrome to reconnect (or run `install-native-host` to repair immediately).
171
- 5. When `registered` is `true`, the active manifest points to `~/.codex-control-chrome-mcp/native-host-launcher` (or your local launcher) and the extension just needs to connect.
186
+ 4. Check `install.<browser>.registered`. If it is `false` and `classification.kind` is `official-openai`, a Codex update reclaimed that browser's manifest. The stdio server re-asserts it on next startup; reload the extension or restart the browser to reconnect (or run `install-native-host` to repair immediately).
187
+ 5. When `registered` is `true`, the active manifest points to `~/.codex-control-chrome-mcp/native-host-launcher` (or the `-edge` variant, or your local launcher) and the extension just needs to connect.
172
188
 
173
189
  If Codex App integration is affected, uninstall this project:
174
190
 
package/package.json CHANGED
@@ -1,6 +1,6 @@
1
1
  {
2
2
  "name": "codex-control-chrome-mcp",
3
- "version": "1.1.0",
3
+ "version": "1.2.0",
4
4
  "description": "MCP server and native host bridge for controlling Chrome through the Codex Chrome extension.",
5
5
  "license": "MIT",
6
6
  "type": "module",
package/src/cli.js CHANGED
@@ -1,6 +1,13 @@
1
1
  import { runMcpServer } from "./mcp-server.js";
2
2
  import { runNativeHost } from "./native-host.js";
3
- import { installNativeHost, nativeHostInstallStatus, uninstallNativeHost } from "./installer.js";
3
+ import {
4
+ detectInstalledBrowsers,
5
+ detectManagedBrowsers,
6
+ installNativeHost,
7
+ nativeHostInstallStatus,
8
+ uninstallNativeHost,
9
+ } from "./installer.js";
10
+ import { DEFAULT_BROWSER, SUPPORTED_BROWSERS } from "./constants.js";
4
11
  import { listBridgeSockets } from "./bridge-client.js";
5
12
  import { probeLengthPrefixedSocket } from "./probe.js";
6
13
 
@@ -14,7 +21,10 @@ export async function runCli(argv) {
14
21
  }
15
22
 
16
23
  if (args.includes("--native-host") || looksLikeChromeOrigin(command)) {
17
- await runNativeHost({ origin: looksLikeChromeOrigin(command) ? command : argv[3] });
24
+ // Chrome/Edge append the extension origin as a positional arg, so find it
25
+ // by shape rather than position (the `--browser` flag shifts the indices).
26
+ const origin = args.find(looksLikeChromeOrigin) ?? argv[3];
27
+ await runNativeHost({ origin, browser: normalizeBrowser(readOption(args, "--browser")) });
18
28
  return;
19
29
  }
20
30
 
@@ -22,20 +32,31 @@ export async function runCli(argv) {
22
32
  case "install-native-host": {
23
33
  const binPath = readOption(args, "--bin");
24
34
  const noProxy = args.includes("--no-proxy");
25
- const result = await installNativeHost({ binPath, proxy: !noProxy });
35
+ const browsers = await resolveBrowsers(readOption(args, "--browser"), "install");
36
+ const result = {};
37
+ for (const browser of browsers) {
38
+ result[browser] = await installNativeHost({ binPath, proxy: !noProxy, browser });
39
+ }
26
40
  printJson(result);
27
41
  return;
28
42
  }
29
43
  case "uninstall-native-host": {
30
- const result = await uninstallNativeHost({ force: args.includes("--force") });
44
+ const force = args.includes("--force");
45
+ const browsers = await resolveBrowsers(readOption(args, "--browser"), "uninstall");
46
+ const result = {};
47
+ for (const browser of browsers) {
48
+ result[browser] = await uninstallNativeHost({ force, browser });
49
+ }
31
50
  printJson(result);
32
51
  return;
33
52
  }
34
53
  case "status": {
35
- printJson({
36
- install: await nativeHostInstallStatus(),
37
- sockets: await listBridgeSockets(),
38
- });
54
+ const browsers = await resolveBrowsers(readOption(args, "--browser"), "status");
55
+ const install = {};
56
+ for (const browser of browsers) {
57
+ install[browser] = await nativeHostInstallStatus({ browser });
58
+ }
59
+ printJson({ install, sockets: await listBridgeSockets() });
39
60
  return;
40
61
  }
41
62
  case "probe-socket": {
@@ -66,6 +87,39 @@ function readOption(args, name) {
66
87
  return index >= 0 ? args[index + 1] : undefined;
67
88
  }
68
89
 
90
+ function normalizeBrowser(value) {
91
+ if (value == null) return DEFAULT_BROWSER;
92
+ const browser = String(value).toLowerCase();
93
+ if (!SUPPORTED_BROWSERS.includes(browser)) {
94
+ throw new Error(
95
+ `Unsupported browser: ${value}. Supported values: ${SUPPORTED_BROWSERS.join(", ")}, all.`,
96
+ );
97
+ }
98
+ return browser;
99
+ }
100
+
101
+ /**
102
+ * Map an optional `--browser` selector to the list of browsers a command acts
103
+ * on. With no selector each command auto-detects: install targets browsers
104
+ * present on the machine, uninstall targets browsers we previously installed,
105
+ * and status reports every supported browser.
106
+ */
107
+ async function resolveBrowsers(selector, mode) {
108
+ if (selector && selector !== "all") {
109
+ return [normalizeBrowser(selector)];
110
+ }
111
+ if (selector === "all" || mode === "status") {
112
+ return [...SUPPORTED_BROWSERS];
113
+ }
114
+ if (mode === "install") {
115
+ const present = await detectInstalledBrowsers();
116
+ return present.length ? present : [DEFAULT_BROWSER];
117
+ }
118
+ // uninstall
119
+ const managed = await detectManagedBrowsers();
120
+ return managed.length ? managed : [DEFAULT_BROWSER];
121
+ }
122
+
69
123
  function printJson(value) {
70
124
  process.stdout.write(`${JSON.stringify(value, null, 2)}\n`);
71
125
  }
@@ -76,14 +130,16 @@ function printHelp() {
76
130
  Usage:
77
131
  codex-control-chrome-mcp --stdio
78
132
  codex-control-chrome-mcp --native-host
79
- codex-control-chrome-mcp install-native-host [--bin /path/to/codex-control-chrome-mcp] [--no-proxy]
80
- codex-control-chrome-mcp uninstall-native-host [--force]
81
- codex-control-chrome-mcp status
133
+ codex-control-chrome-mcp install-native-host [--bin /path/to/codex-control-chrome-mcp] [--no-proxy] [--browser <chrome|edge|all>]
134
+ codex-control-chrome-mcp uninstall-native-host [--force] [--browser <chrome|edge|all>]
135
+ codex-control-chrome-mcp status [--browser <chrome|edge|all>]
82
136
  codex-control-chrome-mcp probe-socket <socket-path>
83
137
 
84
138
  Notes:
85
139
  --stdio is the MCP server mode for Agent tools.
86
- --native-host is normally launched by Chrome through Native Messaging.
140
+ --native-host is normally launched by Chrome/Edge through Native Messaging.
87
141
  install-native-host without --bin writes a stable launcher that runs npx.
142
+ --browser selects a browser. Without it, install/uninstall auto-detect the
143
+ browsers present (or previously installed) and status reports both.
88
144
  `);
89
145
  }
package/src/constants.js CHANGED
@@ -10,38 +10,61 @@ export const APP_STATE_DIR = path.join(os.homedir(), ".codex-control-chrome-mcp"
10
10
  export const APP_CONFIG_PATH = path.join(APP_STATE_DIR, "config.json");
11
11
  export const INSTALL_STATE_PATH = path.join(APP_STATE_DIR, "install-state.json");
12
12
 
13
- export function nativeHostManifestPath() {
14
- const home = os.homedir();
15
- switch (process.platform) {
16
- case "darwin":
17
- return path.join(
18
- home,
19
- "Library",
20
- "Application Support",
21
- "Google",
22
- "Chrome",
23
- "NativeMessagingHosts",
24
- `${CODEX_NATIVE_HOST_NAME}.json`,
25
- );
26
- case "linux":
27
- return path.join(
28
- home,
29
- ".config",
30
- "google-chrome",
31
- "NativeMessagingHosts",
32
- `${CODEX_NATIVE_HOST_NAME}.json`,
33
- );
34
- case "win32":
35
- return path.join(
36
- home,
37
- "AppData",
38
- "Local",
39
- "Google",
40
- "Chrome",
41
- "NativeMessagingHosts",
42
- `${CODEX_NATIVE_HOST_NAME}.json`,
43
- );
44
- default:
45
- throw new Error(`Unsupported platform: ${process.platform}`);
13
+ // Chromium browsers that ship the Codex extension and use the same Native
14
+ // Messaging mechanism. Edge installs Chrome Web Store extensions under the
15
+ // same `chrome-extension://<id>` origin, so one manifest works for both.
16
+ export const DEFAULT_BROWSER = "chrome";
17
+ export const SUPPORTED_BROWSERS = ["chrome", "edge"];
18
+
19
+ // Per-platform location of each browser's user profile directory. The Native
20
+ // Messaging host manifest lives in a `NativeMessagingHosts` subdirectory, and
21
+ // the profile directory's existence is our "is this browser installed" signal.
22
+ // (On Windows native hosts are registered through the registry, not a file in
23
+ // this directory, which is why Windows is unsupported for now.)
24
+ const BROWSER_PROFILE_SEGMENTS = {
25
+ chrome: {
26
+ darwin: ["Library", "Application Support", "Google", "Chrome"],
27
+ linux: [".config", "google-chrome"],
28
+ win32: ["AppData", "Local", "Google", "Chrome"],
29
+ },
30
+ edge: {
31
+ darwin: ["Library", "Application Support", "Microsoft Edge"],
32
+ linux: [".config", "microsoft-edge"],
33
+ win32: ["AppData", "Local", "Microsoft", "Edge"],
34
+ },
35
+ };
36
+
37
+ export function browserProfileDir(browser = DEFAULT_BROWSER) {
38
+ const perPlatform = BROWSER_PROFILE_SEGMENTS[browser];
39
+ if (!perPlatform) {
40
+ throw new Error(`Unsupported browser: ${browser}`);
41
+ }
42
+ const segments = perPlatform[process.platform];
43
+ if (!segments) {
44
+ throw new Error(`Unsupported platform: ${process.platform}`);
46
45
  }
46
+ return path.join(os.homedir(), ...segments);
47
+ }
48
+
49
+ export function nativeHostManifestPath(browser = DEFAULT_BROWSER) {
50
+ return path.join(
51
+ browserProfileDir(browser),
52
+ "NativeMessagingHosts",
53
+ `${CODEX_NATIVE_HOST_NAME}.json`,
54
+ );
55
+ }
56
+
57
+ // Chrome keeps the original unsuffixed state filenames so installs from before
58
+ // multi-browser support remain valid; other browsers get a per-browser suffix
59
+ // so a second install never clobbers the first one's restore/self-heal metadata.
60
+ export function configPathFor(browser = DEFAULT_BROWSER) {
61
+ return browser === DEFAULT_BROWSER
62
+ ? APP_CONFIG_PATH
63
+ : path.join(APP_STATE_DIR, `config.${browser}.json`);
64
+ }
65
+
66
+ export function installStatePathFor(browser = DEFAULT_BROWSER) {
67
+ return browser === DEFAULT_BROWSER
68
+ ? INSTALL_STATE_PATH
69
+ : path.join(APP_STATE_DIR, `install-state.${browser}.json`);
47
70
  }
package/src/installer.js CHANGED
@@ -1,11 +1,14 @@
1
1
  import fs from "node:fs/promises";
2
2
  import path from "node:path";
3
3
  import {
4
- APP_CONFIG_PATH,
5
4
  APP_STATE_DIR,
6
5
  CODEX_EXTENSION_ID,
7
6
  CODEX_NATIVE_HOST_NAME,
8
- INSTALL_STATE_PATH,
7
+ DEFAULT_BROWSER,
8
+ SUPPORTED_BROWSERS,
9
+ browserProfileDir,
10
+ configPathFor,
11
+ installStatePathFor,
9
12
  nativeHostManifestPath,
10
13
  } from "./constants.js";
11
14
  import {
@@ -18,14 +21,20 @@ import {
18
21
  } from "./host-identity.js";
19
22
  import { PACKAGE_NAME, PACKAGE_VERSION } from "./package-meta.js";
20
23
 
21
- export async function installNativeHost({ binPath, proxy = true, paths = defaultInstallPaths() } = {}) {
24
+ export async function installNativeHost({
25
+ binPath,
26
+ proxy = true,
27
+ browser = DEFAULT_BROWSER,
28
+ paths = defaultInstallPaths(browser),
29
+ } = {}) {
22
30
  const { manifestPath, appStateDir, configPath, installStatePath } = paths;
31
+ const browserId = paths.browser ?? browser;
23
32
  await fs.mkdir(path.dirname(manifestPath), { recursive: true });
24
33
  await fs.mkdir(appStateDir, { recursive: true });
25
34
 
26
35
  const hostPath = binPath
27
- ? await createLocalLauncher(path.resolve(binPath), appStateDir)
28
- : await createNpxLauncher(appStateDir);
36
+ ? await createLocalLauncher(path.resolve(binPath), appStateDir, browserId)
37
+ : await createNpxLauncher(appStateDir, browserId);
29
38
  const existing = await readJsonIfExists(manifestPath);
30
39
  const previousState = await readJsonIfExists(installStatePath);
31
40
  const previousBackup = previousState?.backupPath
@@ -55,6 +64,7 @@ export async function installNativeHost({ binPath, proxy = true, paths = default
55
64
 
56
65
  const config = {
57
66
  installedAt: new Date().toISOString(),
67
+ browser: browserId,
58
68
  manifestPath,
59
69
  hostPath,
60
70
  binPath: binPath ? path.resolve(binPath) : null,
@@ -113,7 +123,10 @@ async function resolveOfficialHostPath({ existing, existingIsOurs, previousState
113
123
  * startup so a Codex update that reclaims the manifest self-heals without a
114
124
  * manual `install-native-host`. Never bootstraps a fresh install silently.
115
125
  */
116
- export async function ensureNativeHostRegistered({ paths = defaultInstallPaths() } = {}) {
126
+ export async function ensureNativeHostRegistered({
127
+ browser = DEFAULT_BROWSER,
128
+ paths = defaultInstallPaths(browser),
129
+ } = {}) {
117
130
  const { manifestPath, installStatePath } = paths;
118
131
  const state = await readJsonIfExists(installStatePath);
119
132
  if (!state || typeof state.hostPath !== "string") {
@@ -144,7 +157,11 @@ export async function ensureNativeHostRegistered({ paths = defaultInstallPaths()
144
157
  };
145
158
  }
146
159
 
147
- export async function uninstallNativeHost({ force = false, paths = defaultInstallPaths() } = {}) {
160
+ export async function uninstallNativeHost({
161
+ force = false,
162
+ browser = DEFAULT_BROWSER,
163
+ paths = defaultInstallPaths(browser),
164
+ } = {}) {
148
165
  const { manifestPath, installStatePath } = paths;
149
166
  const state = await readJsonIfExists(installStatePath);
150
167
  const manifest = await readJsonIfExists(manifestPath);
@@ -168,8 +185,11 @@ export async function uninstallNativeHost({ force = false, paths = defaultInstal
168
185
  return { ok: true, action: "removed", manifestPath };
169
186
  }
170
187
 
171
- export async function nativeHostInstallStatus() {
172
- const { manifestPath, installStatePath } = defaultInstallPaths();
188
+ export async function nativeHostInstallStatus({
189
+ browser = DEFAULT_BROWSER,
190
+ paths = defaultInstallPaths(browser),
191
+ } = {}) {
192
+ const { manifestPath, installStatePath } = paths;
173
193
  const manifest = await readJsonIfExists(manifestPath);
174
194
  const state = await readJsonIfExists(installStatePath);
175
195
  const classification = await classifyHost({ manifest, hostPath: manifest?.path });
@@ -178,15 +198,47 @@ export async function nativeHostInstallStatus() {
178
198
  typeof state?.hostPath === "string" &&
179
199
  typeof manifest?.path === "string" &&
180
200
  path.resolve(manifest.path) === path.resolve(state.hostPath);
181
- return { manifestPath, manifest, state, registered, classification };
201
+ return { browser: paths.browser ?? browser, manifestPath, manifest, state, registered, classification };
202
+ }
203
+
204
+ /** Browsers whose user profile directory exists on this machine (install targets). */
205
+ export async function detectInstalledBrowsers() {
206
+ const present = [];
207
+ for (const browser of SUPPORTED_BROWSERS) {
208
+ let dir;
209
+ try {
210
+ dir = browserProfileDir(browser);
211
+ } catch {
212
+ continue; // unsupported platform for this browser
213
+ }
214
+ try {
215
+ await fs.access(dir);
216
+ present.push(browser);
217
+ } catch {
218
+ // profile directory absent -> browser not installed (or never launched)
219
+ }
220
+ }
221
+ return present;
182
222
  }
183
223
 
184
- function defaultInstallPaths() {
224
+ /** Browsers we have previously installed for (an install-state file exists). */
225
+ export async function detectManagedBrowsers() {
226
+ const managed = [];
227
+ for (const browser of SUPPORTED_BROWSERS) {
228
+ if (await readJsonIfExists(installStatePathFor(browser))) {
229
+ managed.push(browser);
230
+ }
231
+ }
232
+ return managed;
233
+ }
234
+
235
+ function defaultInstallPaths(browser = DEFAULT_BROWSER) {
185
236
  return {
186
- manifestPath: nativeHostManifestPath(),
237
+ browser,
238
+ manifestPath: nativeHostManifestPath(browser),
187
239
  appStateDir: APP_STATE_DIR,
188
- configPath: APP_CONFIG_PATH,
189
- installStatePath: INSTALL_STATE_PATH,
240
+ configPath: configPathFor(browser),
241
+ installStatePath: installStatePathFor(browser),
190
242
  };
191
243
  }
192
244
 
@@ -200,29 +252,36 @@ async function backupManifest(manifestPath) {
200
252
  return backupPath;
201
253
  }
202
254
 
203
- async function createNpxLauncher(appStateDir) {
255
+ // Each browser gets its own launcher so the native host knows which browser's
256
+ // config to read for proxy mode. Chrome keeps the original unsuffixed filename
257
+ // so manifests written before multi-browser support still resolve.
258
+ function launcherFileName(base, browser) {
259
+ return browser === DEFAULT_BROWSER ? base : `${base}-${browser}`;
260
+ }
261
+
262
+ async function createNpxLauncher(appStateDir, browser = DEFAULT_BROWSER) {
204
263
  if (process.platform === "win32") {
205
264
  throw new Error("NPX native host launcher installation is not implemented for Windows yet.");
206
265
  }
207
- const launcherPath = path.join(appStateDir, "native-host-launcher");
266
+ const launcherPath = path.join(appStateDir, launcherFileName("native-host-launcher", browser));
208
267
  const script = `#!/usr/bin/env sh
209
- exec npx -y ${PACKAGE_NAME}@${PACKAGE_VERSION} --native-host "$@"
268
+ exec npx -y ${PACKAGE_NAME}@${PACKAGE_VERSION} --native-host --browser ${browser} "$@"
210
269
  `;
211
270
  await fs.writeFile(launcherPath, script, { encoding: "utf8", mode: 0o755 });
212
271
  await fs.chmod(launcherPath, 0o755);
213
272
  return launcherPath;
214
273
  }
215
274
 
216
- async function createLocalLauncher(binPath, appStateDir) {
275
+ async function createLocalLauncher(binPath, appStateDir, browser = DEFAULT_BROWSER) {
217
276
  if (process.platform === "win32") {
218
277
  return binPath;
219
278
  }
220
279
  if (!binPath.endsWith(".js")) {
221
280
  return binPath;
222
281
  }
223
- const launcherPath = path.join(appStateDir, "native-host-local-launcher");
282
+ const launcherPath = path.join(appStateDir, launcherFileName("native-host-local-launcher", browser));
224
283
  const script = `#!/usr/bin/env sh
225
- exec ${shellQuote(process.execPath)} ${shellQuote(binPath)} "$@"
284
+ exec ${shellQuote(process.execPath)} ${shellQuote(binPath)} --browser ${browser} "$@"
226
285
  `;
227
286
  await fs.writeFile(launcherPath, script, { encoding: "utf8", mode: 0o755 });
228
287
  await fs.chmod(launcherPath, 0o755);
package/src/mcp-server.js CHANGED
@@ -3,8 +3,8 @@ import { McpServer } from "@modelcontextprotocol/sdk/server/mcp.js";
3
3
  import { StdioServerTransport } from "@modelcontextprotocol/sdk/server/stdio.js";
4
4
  import { z } from "zod";
5
5
  import { connectBridge, listBridgeSockets } from "./bridge-client.js";
6
- import { nativeHostManifestPath } from "./constants.js";
7
- import { ensureNativeHostRegistered } from "./installer.js";
6
+ import { SUPPORTED_BROWSERS, nativeHostManifestPath } from "./constants.js";
7
+ import { detectManagedBrowsers, ensureNativeHostRegistered } from "./installer.js";
8
8
  import { PACKAGE_NAME, PACKAGE_VERSION } from "./package-meta.js";
9
9
 
10
10
  export async function runMcpServer() {
@@ -32,21 +32,34 @@ export async function runMcpServer() {
32
32
  */
33
33
  async function autoRegisterNativeHost() {
34
34
  if (process.env.CODEX_CONTROL_CHROME_NO_AUTO_REGISTER === "1") return;
35
+ let browsers = [];
35
36
  try {
36
- const result = await ensureNativeHostRegistered();
37
- if (result.action === "re-registered") {
37
+ browsers = await detectManagedBrowsers();
38
+ } catch {
39
+ browsers = [];
40
+ }
41
+ for (const browser of browsers) {
42
+ try {
43
+ const result = await ensureNativeHostRegistered({ browser });
44
+ if (result.action === "re-registered") {
45
+ process.stderr.write(
46
+ `[codex-control-chrome-mcp] native host manifest for ${browser} was ${result.reason}; ` +
47
+ `re-registered it. Reload the Codex extension (or restart ${browserLabel(browser)}) ` +
48
+ "to reconnect the bridge.\n",
49
+ );
50
+ }
51
+ } catch (error) {
38
52
  process.stderr.write(
39
- `[codex-control-chrome-mcp] native host manifest was ${result.reason}; re-registered it. ` +
40
- "Reload the Codex Chrome extension (or restart Chrome) to reconnect the bridge.\n",
53
+ `[codex-control-chrome-mcp] auto-register (${browser}) skipped: ${error?.message ?? error}\n`,
41
54
  );
42
55
  }
43
- } catch (error) {
44
- process.stderr.write(
45
- `[codex-control-chrome-mcp] auto-register skipped: ${error?.message ?? error}\n`,
46
- );
47
56
  }
48
57
  }
49
58
 
59
+ function browserLabel(browser) {
60
+ return browser === "edge" ? "Edge" : "Chrome";
61
+ }
62
+
50
63
  class ChromeUseRuntime {
51
64
  constructor() {
52
65
  this.sessionId = `codex-control-chrome-mcp-${crypto.randomUUID()}`;
@@ -83,11 +96,14 @@ function registerTools(server, runtime) {
83
96
  server.registerTool(
84
97
  "chrome_status",
85
98
  {
86
- description: "Show native host manifest path and discovered bridge sockets.",
99
+ description: "Show native host manifest paths and discovered bridge sockets.",
87
100
  inputSchema: {},
88
101
  },
89
102
  async () => toolResult({
90
103
  manifestPath: nativeHostManifestPath(),
104
+ manifestPaths: Object.fromEntries(
105
+ SUPPORTED_BROWSERS.map((browser) => [browser, nativeHostManifestPath(browser)]),
106
+ ),
91
107
  sockets: await listBridgeSockets(),
92
108
  }),
93
109
  );
@@ -3,12 +3,17 @@ import fs from "node:fs/promises";
3
3
  import net from "node:net";
4
4
  import path from "node:path";
5
5
  import { spawn } from "node:child_process";
6
- import { APP_CONFIG_PATH, BRIDGE_SOCKET_DIR, BRIDGE_SOCKET_PREFIX } from "./constants.js";
6
+ import {
7
+ BRIDGE_SOCKET_DIR,
8
+ BRIDGE_SOCKET_PREFIX,
9
+ DEFAULT_BROWSER,
10
+ configPathFor,
11
+ } from "./constants.js";
7
12
  import { LengthPrefixedJsonPeer } from "./framing.js";
8
13
 
9
14
  const LOCAL_ID_PREFIX = "codex-control-chrome-mcp:";
10
15
 
11
- export async function runNativeHost({ origin = process.argv[2] } = {}) {
16
+ export async function runNativeHost({ origin = process.argv[2], browser = DEFAULT_BROWSER } = {}) {
12
17
  await fs.mkdir(BRIDGE_SOCKET_DIR, { recursive: true });
13
18
  const socketPath = path.join(
14
19
  BRIDGE_SOCKET_DIR,
@@ -21,7 +26,7 @@ export async function runNativeHost({ origin = process.argv[2] } = {}) {
21
26
  name: "chrome-extension",
22
27
  });
23
28
 
24
- const proxyPeer = await maybeStartOfficialProxy(origin);
29
+ const proxyPeer = await maybeStartOfficialProxy(origin, browser);
25
30
  const bridge = new NativeHostBridge({ extensionPeer, proxyPeer });
26
31
  await bridge.listen(socketPath);
27
32
 
@@ -201,8 +206,8 @@ class NativeHostBridge {
201
206
  }
202
207
  }
203
208
 
204
- async function maybeStartOfficialProxy(origin) {
205
- const config = await readJsonIfExists(APP_CONFIG_PATH);
209
+ async function maybeStartOfficialProxy(origin, browser = DEFAULT_BROWSER) {
210
+ const config = await readJsonIfExists(configPathFor(browser));
206
211
  const officialHostPath = config?.officialHostPath;
207
212
  if (typeof officialHostPath !== "string" || officialHostPath.length === 0) {
208
213
  return null;