diff --git a/src/browser/profiles-service.test.ts b/src/browser/profiles-service.test.ts index 13bbdf27c49..029488dd527 100644 --- a/src/browser/profiles-service.test.ts +++ b/src/browser/profiles-service.test.ts @@ -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 () => { diff --git a/src/browser/profiles-service.ts b/src/browser/profiles-service.ts index 86321006e98..27ad1b75120 100644 --- a/src/browser/profiles-service.ts +++ b/src/browser/profiles-service.ts @@ -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");