feat(browser): allow MCP target URLs in profile creation

This commit is contained in:
Vincent Koc
2026-03-14 01:27:13 -07:00
parent cb09e795ae
commit 40aa31f5c8
2 changed files with 28 additions and 17 deletions

View File

@@ -201,20 +201,27 @@ describe("BrowserProfilesService", () => {
);
});
it("rejects driver=existing-session when cdpUrl is provided", async () => {
it("allows driver=existing-session when cdpUrl is provided as an MCP target", async () => {
const resolved = resolveBrowserConfig({});
const { ctx } = createCtx(resolved);
const { ctx, state } = createCtx(resolved);
vi.mocked(loadConfig).mockReturnValue({ browser: { profiles: {} } });
const service = createBrowserProfilesService(ctx);
const result = await service.createProfile({
name: "chrome-live",
driver: "existing-session",
cdpUrl: "http://127.0.0.1:9222",
});
await expect(
service.createProfile({
name: "chrome-live",
driver: "existing-session",
cdpUrl: "http://127.0.0.1:9222",
}),
).rejects.toThrow(/does not accept cdpUrl/i);
expect(result.transport).toBe("chrome-mcp");
expect(result.cdpUrl).toBeNull();
expect(result.isRemote).toBe(false);
expect(state.resolved.profiles["chrome-live"]).toEqual({
cdpUrl: "http://127.0.0.1:9222",
driver: "existing-session",
attachOnly: true,
color: expect.any(String),
});
});
it("deletes remote profiles without stopping or removing local data", async () => {

View File

@@ -130,15 +130,19 @@ export function createBrowserProfilesService(ctx: BrowserRouteContext) {
}
}
if (driver === "existing-session") {
throw new BrowserValidationError(
"driver=existing-session does not accept cdpUrl; it attaches via the Chrome MCP auto-connect flow",
);
profileConfig = {
cdpUrl: parsed.normalized,
driver,
attachOnly: true,
color: profileColor,
};
} else {
profileConfig = {
cdpUrl: parsed.normalized,
...(driver ? { driver } : {}),
color: profileColor,
};
}
profileConfig = {
cdpUrl: parsed.normalized,
...(driver ? { driver } : {}),
color: profileColor,
};
} else {
if (driver === "extension") {
throw new BrowserValidationError("driver=extension requires an explicit loopback cdpUrl");