@ricsam/browser-mcp 0.3.6 → 0.3.7
This diff represents the content of publicly available package versions that have been released to one of the supported registries. The information contained in this diff is provided for informational purposes only and reflects changes between package versions as they appear in their respective public registries.
- package/README.md +32 -1
- package/dist/{chunk-9kd368ja.js → chunk-rshfr4hg.js} +95 -51
- package/dist/main.js +4 -3
- package/package.json +1 -1
package/README.md
CHANGED
|
@@ -4,7 +4,7 @@ Native Chrome companion. Requires Node >=22.14.0 and an installed
|
|
|
4
4
|
Google Chrome. No browser download or startup occurs during npm installation.
|
|
5
5
|
|
|
6
6
|
```sh
|
|
7
|
-
npm install -g @ricsam/browser-mcp
|
|
7
|
+
npm install -g @ricsam/browser-mcp@0.3.7
|
|
8
8
|
browser-mcp browser start --server https://browser-mcp.click --profile work
|
|
9
9
|
browser-mcp browser status --profile work
|
|
10
10
|
browser-mcp browser pause --profile work
|
|
@@ -32,6 +32,37 @@ Crash locks are deliberately not removed automatically: verify the exact prior
|
|
|
32
32
|
owner and Chrome processes are stopped before operator recovery. Retained crash
|
|
33
33
|
files are not automatically scavenged. Never remove directories by name prefix.
|
|
34
34
|
|
|
35
|
+
### Multiple browsers
|
|
36
|
+
|
|
37
|
+
Use a different profile for each browser. Repeat `--profile` to launch two or
|
|
38
|
+
more isolated Chrome instances in one foreground command (CLI 0.3.7 or newer):
|
|
39
|
+
|
|
40
|
+
```sh
|
|
41
|
+
browser-mcp browser start --server https://browser-mcp.click --profile work --profile personal --profile testing
|
|
42
|
+
# From another terminal, control only the chosen browser:
|
|
43
|
+
browser-mcp browser pause --profile work
|
|
44
|
+
browser-mcp browser status --profile personal
|
|
45
|
+
browser-mcp browser stop --profile work
|
|
46
|
+
```
|
|
47
|
+
|
|
48
|
+
Each profile has separate sign-ins, pairing credentials, local controls and a
|
|
49
|
+
browser registration in the dashboard. Approve each new profile's labeled link,
|
|
50
|
+
then configure its own MCP URL/token. Closing or stopping one browser leaves the
|
|
51
|
+
others running. Ctrl-C closes all browsers started by that command, and the CLI
|
|
52
|
+
exits after the last browser stops. A launch/runtime failure stops the group and
|
|
53
|
+
waits for cleanup; it never takes over an existing profile.
|
|
54
|
+
|
|
55
|
+
`--server`, `--chrome-path`, `--ephemeral` and `--live-view` apply to all profiles
|
|
56
|
+
in that invocation. With `--ephemeral`, each profile name still identifies its
|
|
57
|
+
pairing and local controls, but its Chrome data is throw-away. Omitting
|
|
58
|
+
`--profile` selects `default`; duplicate profile names are rejected.
|
|
59
|
+
|
|
60
|
+
Alternatively, run separate `browser start` commands with different profiles in
|
|
61
|
+
separate terminals (also supported in 0.3.6). This lets you choose different
|
|
62
|
+
options and independent CLI lifetimes. Never launch two owners of the same
|
|
63
|
+
profile; use `--profile personal` rather than deleting a busy profile's lock.
|
|
64
|
+
Local control and recovery commands accept one profile at a time.
|
|
65
|
+
|
|
35
66
|
### Explicit crash recovery
|
|
36
67
|
|
|
37
68
|
After stopping the prior host and its dedicated Chrome, run:
|
|
@@ -17,6 +17,7 @@ import"./chunk-1sjcwr28.js";
|
|
|
17
17
|
import fs9 from "node:fs/promises";
|
|
18
18
|
import path8 from "node:path";
|
|
19
19
|
import net2 from "node:net";
|
|
20
|
+
import { setMaxListeners } from "node:events";
|
|
20
21
|
|
|
21
22
|
// cli/src/browser/lifecycle.ts
|
|
22
23
|
import fs2 from "node:fs/promises";
|
|
@@ -265,7 +266,7 @@ async function launchDedicated(options = {}) {
|
|
|
265
266
|
} catch (error) {
|
|
266
267
|
if (error.code !== "EEXIST")
|
|
267
268
|
throw error;
|
|
268
|
-
throw new Error(`Profile already locked: ${lockPath}. After stopping the previous CLI and Chrome, run browser-mcp browser recover --profile ${name}. Recovery refuses live or uncertain owners; never blindly remove locks or sockets.`);
|
|
269
|
+
throw new Error(`Profile already locked: ${lockPath}. Use a different --profile to launch another browser. After stopping the previous CLI and Chrome, run browser-mcp browser recover --profile ${name}. Recovery refuses live or uncertain owners; never blindly remove locks or sockets.`);
|
|
269
270
|
}
|
|
270
271
|
const lockStat = await lock.stat();
|
|
271
272
|
const runPath = path2.join(profile, `run-${instanceId}`);
|
|
@@ -451,7 +452,7 @@ ${profile}`).digest("hex").slice(0, 24)}.json`);
|
|
|
451
452
|
const verification = new URL(grant.verificationUrl);
|
|
452
453
|
if (verification.origin !== server)
|
|
453
454
|
throw new Error("Pairing origin mismatch");
|
|
454
|
-
console.error(`Approve this dedicated browser: ${verification.href}`);
|
|
455
|
+
console.error(`Approve this dedicated browser (${profile}): ${verification.href}`);
|
|
455
456
|
const deadline = Date.now() + Math.min(600, Number(grant.expiresIn)) * 1000;
|
|
456
457
|
while (Date.now() < deadline) {
|
|
457
458
|
await delay(Math.max(3, Number(grant.interval)) * 1000, undefined, { signal });
|
|
@@ -4514,7 +4515,7 @@ class Relay {
|
|
|
4514
4515
|
heartbeat.unref();
|
|
4515
4516
|
socket.once("open", () => {
|
|
4516
4517
|
this.state = "authenticating";
|
|
4517
|
-
socket.send(JSON.stringify({ type: "auth", token: this.token, client: { protocol: 3, version: "0.3.
|
|
4518
|
+
socket.send(JSON.stringify({ type: "auth", token: this.token, client: { protocol: 3, version: "0.3.7", instanceId: this.runtime.instanceId, operations: [...BROWSER_OPERATIONS, ...this.runtime.plugins.flatMap((p) => p.operations), "session_end", "release_tab"], capabilities: ["browser-controls.v1", "screenshot-ids.v1", "webmcp.page-context.v1", "clipboard.native.v1", "native-transfers.v1", "secrets.v1", "forwarding.v1", "live-view.v1"], liveView: { enabled: this.liveEnabled } } }));
|
|
4518
4519
|
});
|
|
4519
4520
|
socket.on("message", (bytes, binary) => {
|
|
4520
4521
|
if (binary || Buffer.byteLength(bytes.toString()) > LIMIT) {
|
|
@@ -5177,17 +5178,21 @@ function createForwardPlugin(options) {
|
|
|
5177
5178
|
|
|
5178
5179
|
// cli/src/browser/main.ts
|
|
5179
5180
|
function parse(args) {
|
|
5180
|
-
const options = {};
|
|
5181
|
+
const options = { profiles: [] };
|
|
5181
5182
|
for (let i = 0;i < args.length; i++) {
|
|
5182
5183
|
const key = args[i];
|
|
5183
5184
|
if (key === "--ephemeral")
|
|
5184
5185
|
options.ephemeral = true;
|
|
5185
5186
|
else if (key === "--live-view")
|
|
5186
5187
|
options.liveView = true;
|
|
5187
|
-
else if (
|
|
5188
|
+
else if (key === "--profile" || key === "--server" || key === "--chrome-path") {
|
|
5188
5189
|
if (!args[i + 1] || args[i + 1].startsWith("--"))
|
|
5189
5190
|
throw new Error(`Missing ${key} value`);
|
|
5190
|
-
|
|
5191
|
+
const value = args[++i];
|
|
5192
|
+
if (key === "--profile")
|
|
5193
|
+
options.profiles.push(value);
|
|
5194
|
+
else
|
|
5195
|
+
options[key === "--server" ? "server" : "chrome-path"] = value;
|
|
5191
5196
|
} else
|
|
5192
5197
|
throw new Error(`Unknown browser option ${key}`);
|
|
5193
5198
|
}
|
|
@@ -5196,20 +5201,93 @@ function parse(args) {
|
|
|
5196
5201
|
async function runBrowser(args) {
|
|
5197
5202
|
const command = args.shift() ?? "help";
|
|
5198
5203
|
if (command === "help" || command === "--help" || args.includes("--help")) {
|
|
5199
|
-
console.log(`browser-mcp browser start [--server https://browser-mcp.click] [--profile work] [--ephemeral] [--chrome-path /path/to/chrome] [--live-view]
|
|
5204
|
+
console.log(`browser-mcp browser start [--server https://browser-mcp.click] [--profile work] [--profile personal ...] [--ephemeral] [--chrome-path /path/to/chrome] [--live-view]
|
|
5200
5205
|
browser-mcp browser status|pause|resume|stop|recover [--profile work]
|
|
5206
|
+
Repeat --profile to launch multiple isolated browsers. Without --profile, uses default. Approve each new profile separately. Local controls target one profile; Ctrl-C closes all browsers started by this command. A launch/runtime failure stops the group.
|
|
5201
5207
|
Dedicated Chrome only. Foreground pipe lifecycle: stopping the CLI closes Chrome; no detach/reattach. recover removes only verified stale lock/socket artifacts, never profile data. Live view requires local --live-view opt-in (screenshots may expose secrets). Windows browser host is not yet supported.`);
|
|
5202
5208
|
return;
|
|
5203
5209
|
}
|
|
5204
|
-
|
|
5205
|
-
|
|
5206
|
-
|
|
5210
|
+
if (!["start", "status", "pause", "resume", "stop", "recover"].includes(command))
|
|
5211
|
+
throw new Error("Unknown browser command");
|
|
5212
|
+
const options = parse(args), profiles = options.profiles.length ? options.profiles : ["default"];
|
|
5213
|
+
for (const profile of profiles)
|
|
5214
|
+
if (!/^[a-zA-Z0-9][a-zA-Z0-9_-]{0,47}$/.test(profile))
|
|
5215
|
+
throw new Error("Invalid profile name");
|
|
5216
|
+
if (new Set(profiles).size !== profiles.length)
|
|
5217
|
+
throw new Error("Duplicate profile names: use a different --profile for each browser");
|
|
5218
|
+
if (command !== "start" && profiles.length !== 1)
|
|
5219
|
+
throw new Error(`${command} accepts one --profile; run local controls separately for each browser`);
|
|
5220
|
+
const abort = new AbortController;
|
|
5221
|
+
setMaxListeners(0, abort.signal);
|
|
5222
|
+
const requestStop = () => abort.abort(new Error("Browser startup interrupted"));
|
|
5223
|
+
const signals = ["SIGINT", "SIGTERM", "SIGHUP"];
|
|
5224
|
+
if (command === "start")
|
|
5225
|
+
for (const signal of signals)
|
|
5226
|
+
process.on(signal, requestStop);
|
|
5227
|
+
try {
|
|
5228
|
+
const root = await privateDirectory(installationRoot());
|
|
5229
|
+
if (command !== "start") {
|
|
5230
|
+
const profile = profiles[0], controlPath = controlSocketPath(root, profile);
|
|
5231
|
+
if (command === "recover") {
|
|
5232
|
+
await recoverProfile(root, profile);
|
|
5233
|
+
console.log(`Verified stale lock/socket cleanup complete for profile ${profile}; profile data retained.`);
|
|
5234
|
+
return;
|
|
5235
|
+
}
|
|
5236
|
+
await new Promise((resolve, reject) => {
|
|
5237
|
+
const socket = net2.connect(controlPath);
|
|
5238
|
+
socket.setTimeout(5000, () => socket.destroy(new Error("Local control timeout")));
|
|
5239
|
+
socket.once("connect", () => socket.write(JSON.stringify({ command }) + `
|
|
5240
|
+
`));
|
|
5241
|
+
socket.once("data", (data) => {
|
|
5242
|
+
console.log(data.toString().trim());
|
|
5243
|
+
socket.end();
|
|
5244
|
+
resolve();
|
|
5245
|
+
});
|
|
5246
|
+
socket.once("error", (error) => reject(new Error(`${error.message}. If the CLI has exited, run browser-mcp browser recover --profile ${profile} to check the profile lock and ${controlPath}.`)));
|
|
5247
|
+
});
|
|
5248
|
+
return;
|
|
5249
|
+
}
|
|
5250
|
+
abort.signal.throwIfAborted();
|
|
5251
|
+
const server = serverURL(options.server ?? "https://browser-mcp.click");
|
|
5252
|
+
for (const profile of profiles) {
|
|
5253
|
+
const controlPath = controlSocketPath(root, profile);
|
|
5254
|
+
const previousSocket = await fs9.lstat(controlPath).catch((error) => {
|
|
5255
|
+
if (error.code !== "ENOENT")
|
|
5256
|
+
throw error;
|
|
5257
|
+
});
|
|
5258
|
+
if (previousSocket)
|
|
5259
|
+
throw new Error(`Local control path already exists: ${controlPath}. Use a different --profile to launch another browser. If the prior host has stopped, run browser-mcp browser recover --profile ${profile}. Recovery verifies both runtime.lock and the socket; never blindly unlink either.`);
|
|
5260
|
+
abort.signal.throwIfAborted();
|
|
5261
|
+
}
|
|
5262
|
+
const results = await Promise.allSettled(profiles.map(async (profile) => {
|
|
5263
|
+
try {
|
|
5264
|
+
await startProfile(root, server, profile, options, abort.signal);
|
|
5265
|
+
} catch (cause) {
|
|
5266
|
+
requestStop();
|
|
5267
|
+
throw new Error(`Profile ${profile}: ${cause instanceof Error ? cause.message : cause}`, { cause });
|
|
5268
|
+
}
|
|
5269
|
+
}));
|
|
5270
|
+
const errors = results.flatMap((result) => result.status === "rejected" ? [result.reason] : []);
|
|
5271
|
+
if (errors.length)
|
|
5272
|
+
throw new AggregateError(errors, errors.map((error) => error.message).join(`
|
|
5273
|
+
`));
|
|
5274
|
+
} catch (error) {
|
|
5275
|
+
if (error !== abort.signal.reason)
|
|
5276
|
+
throw error;
|
|
5277
|
+
} finally {
|
|
5278
|
+
if (command === "start")
|
|
5279
|
+
for (const signal of signals)
|
|
5280
|
+
process.removeListener(signal, requestStop);
|
|
5281
|
+
}
|
|
5282
|
+
}
|
|
5283
|
+
async function startProfile(root, server, profile, options, groupSignal) {
|
|
5207
5284
|
const abort = new AbortController;
|
|
5208
5285
|
let starting = true;
|
|
5209
5286
|
let session;
|
|
5210
5287
|
let runtime, relay, local;
|
|
5211
5288
|
let stopQuota;
|
|
5212
|
-
|
|
5289
|
+
const controlPath = controlSocketPath(root, profile);
|
|
5290
|
+
let stopControl;
|
|
5213
5291
|
const clients = new Set;
|
|
5214
5292
|
const close = onceAsync(() => cleanupSteps([
|
|
5215
5293
|
["Relay", async () => {
|
|
@@ -5235,43 +5313,11 @@ Dedicated Chrome only. Foreground pipe lifecycle: stopping the CLI closes Chrome
|
|
|
5235
5313
|
if (!starting)
|
|
5236
5314
|
close().catch(() => {});
|
|
5237
5315
|
};
|
|
5238
|
-
|
|
5239
|
-
if (
|
|
5240
|
-
|
|
5241
|
-
process.on(signal, requestStop);
|
|
5316
|
+
groupSignal.addEventListener("abort", requestStop, { once: true });
|
|
5317
|
+
if (groupSignal.aborted)
|
|
5318
|
+
requestStop();
|
|
5242
5319
|
try {
|
|
5243
|
-
const root = await privateDirectory(installationRoot());
|
|
5244
|
-
controlPath = controlSocketPath(root, profile);
|
|
5245
|
-
if (command === "recover") {
|
|
5246
|
-
await recoverProfile(root, profile);
|
|
5247
|
-
console.log(`Verified stale lock/socket cleanup complete for profile ${profile}; profile data retained.`);
|
|
5248
|
-
return;
|
|
5249
|
-
}
|
|
5250
|
-
if (command !== "start") {
|
|
5251
|
-
if (!["status", "pause", "resume", "stop"].includes(command))
|
|
5252
|
-
throw new Error("Unknown browser command");
|
|
5253
|
-
await new Promise((resolve, reject) => {
|
|
5254
|
-
const socket = net2.connect(controlPath);
|
|
5255
|
-
socket.setTimeout(5000, () => socket.destroy(new Error("Local control timeout")));
|
|
5256
|
-
socket.once("connect", () => socket.write(JSON.stringify({ command }) + `
|
|
5257
|
-
`));
|
|
5258
|
-
socket.once("data", (data) => {
|
|
5259
|
-
console.log(data.toString().trim());
|
|
5260
|
-
socket.end();
|
|
5261
|
-
resolve();
|
|
5262
|
-
});
|
|
5263
|
-
socket.once("error", (error) => reject(new Error(`${error.message}. If the CLI has exited, run browser-mcp browser recover --profile ${profile} to check the profile lock and ${controlPath}.`)));
|
|
5264
|
-
});
|
|
5265
|
-
return;
|
|
5266
|
-
}
|
|
5267
5320
|
abort.signal.throwIfAborted();
|
|
5268
|
-
const server = serverURL(String(options.server ?? "https://browser-mcp.click"));
|
|
5269
|
-
const previousSocket = await fs9.lstat(controlPath).catch((error) => {
|
|
5270
|
-
if (error.code !== "ENOENT")
|
|
5271
|
-
throw error;
|
|
5272
|
-
});
|
|
5273
|
-
if (previousSocket)
|
|
5274
|
-
throw new Error(`Local control path already exists: ${controlPath}. If the prior host has stopped, run browser-mcp browser recover --profile ${profile}. Recovery verifies both runtime.lock and the socket; never blindly unlink either.`);
|
|
5275
5321
|
session = await launchDedicated({ root, profile, ephemeral: !!options.ephemeral, chromePath: options["chrome-path"], signal: abort.signal });
|
|
5276
5322
|
session.context.once("close", requestStop);
|
|
5277
5323
|
abort.signal.throwIfAborted();
|
|
@@ -5322,7 +5368,7 @@ Dedicated Chrome only. Foreground pipe lifecycle: stopping the CLI closes Chrome
|
|
|
5322
5368
|
return;
|
|
5323
5369
|
} else if (cmd !== "status")
|
|
5324
5370
|
throw new Error("Invalid command");
|
|
5325
|
-
socket.end(JSON.stringify({ state: relay.state, paused: relay.paused, instanceId: session.instanceId, profile, version: "0.3.
|
|
5371
|
+
socket.end(JSON.stringify({ state: relay.state, paused: relay.paused, instanceId: session.instanceId, profile, version: "0.3.7", protocol: 3 }) + `
|
|
5326
5372
|
`);
|
|
5327
5373
|
})().catch(() => socket.destroy());
|
|
5328
5374
|
});
|
|
@@ -5334,7 +5380,7 @@ Dedicated Chrome only. Foreground pipe lifecycle: stopping the CLI closes Chrome
|
|
|
5334
5380
|
}
|
|
5335
5381
|
abort.signal.throwIfAborted();
|
|
5336
5382
|
starting = false;
|
|
5337
|
-
console.error(`Dedicated Chrome running. Local controls: browser-mcp browser pause|status|stop --profile ${profile}. Ctrl-C closes
|
|
5383
|
+
console.error(`Dedicated Chrome running (${profile}). Local controls: browser-mcp browser pause|resume|status|stop --profile ${profile}. Ctrl-C closes all browsers started by this command.`);
|
|
5338
5384
|
await relay.start();
|
|
5339
5385
|
} catch (error) {
|
|
5340
5386
|
if (error !== abort.signal.reason && !(abort.signal.aborted && error instanceof Error && error.name === "AbortError"))
|
|
@@ -5343,9 +5389,7 @@ Dedicated Chrome only. Foreground pipe lifecycle: stopping the CLI closes Chrome
|
|
|
5343
5389
|
try {
|
|
5344
5390
|
await close();
|
|
5345
5391
|
} finally {
|
|
5346
|
-
|
|
5347
|
-
for (const signal of signals)
|
|
5348
|
-
process.removeListener(signal, requestStop);
|
|
5392
|
+
groupSignal.removeEventListener("abort", requestStop);
|
|
5349
5393
|
}
|
|
5350
5394
|
}
|
|
5351
5395
|
}
|
package/dist/main.js
CHANGED
|
@@ -8,20 +8,21 @@ var args = process.argv.slice(2);
|
|
|
8
8
|
var command = args.shift();
|
|
9
9
|
async function main() {
|
|
10
10
|
if (!command || command === "--help" || command === "help") {
|
|
11
|
-
console.log(`@ricsam/browser-mcp 0.3.
|
|
11
|
+
console.log(`@ricsam/browser-mcp 0.3.7
|
|
12
12
|
Usage: browser-mcp browser start|status|pause|resume|stop|recover [options]
|
|
13
13
|
browser-mcp files upload|download [options]
|
|
14
14
|
browser-mcp secrets export|exec [options]
|
|
15
15
|
browser-mcp forward --capability-file PATH
|
|
16
|
+
Launch multiple browsers: browser-mcp browser start --profile work --profile personal
|
|
16
17
|
Browser dependencies load only for browser commands. No automatic Chrome downloads.`);
|
|
17
18
|
return;
|
|
18
19
|
}
|
|
19
20
|
if (command === "--version") {
|
|
20
|
-
console.log("0.3.
|
|
21
|
+
console.log("0.3.7");
|
|
21
22
|
return;
|
|
22
23
|
}
|
|
23
24
|
if (command === "browser")
|
|
24
|
-
return (await import("./chunk-
|
|
25
|
+
return (await import("./chunk-rshfr4hg.js")).runBrowser(args);
|
|
25
26
|
if (command === "files")
|
|
26
27
|
return (await import("./chunk-xgk37h9a.js")).runFilesCommand(args);
|
|
27
28
|
if (command === "secrets")
|