






















@@ -139,6 +139,68 @@ describe("chrome MCP page parsing", () => {
139139]);
140140});
141141142+it("uses browserUrl for existing-session cdpUrl without also passing userDataDir", () => {
143+expect(
144+buildChromeMcpArgs({
145+cdpUrl: "http://127.0.0.1:9222",
146+userDataDir: "/tmp/brave-profile",
147+}),
148+).toEqual([
149+"-y",
150+"chrome-devtools-mcp@latest",
151+"--browserUrl",
152+"http://127.0.0.1:9222",
153+"--experimentalStructuredContent",
154+"--experimental-page-id-routing",
155+]);
156+});
157+158+it("uses wsEndpoint for direct existing-session websocket cdpUrl", () => {
159+expect(
160+buildChromeMcpArgs({
161+cdpUrl: "ws://127.0.0.1:9222/devtools/browser/abc",
162+}),
163+).toEqual([
164+"-y",
165+"chrome-devtools-mcp@latest",
166+"--wsEndpoint",
167+"ws://127.0.0.1:9222/devtools/browser/abc",
168+"--experimentalStructuredContent",
169+"--experimental-page-id-routing",
170+]);
171+});
172+173+it("appends custom Chrome MCP args and lets explicit endpoint args override auto-connect", () => {
174+expect(
175+buildChromeMcpArgs({
176+userDataDir: "/tmp/brave-profile",
177+mcpArgs: ["--browserUrl", "http://127.0.0.1:9222", "--no-usage-statistics"],
178+}),
179+).toEqual([
180+"-y",
181+"chrome-devtools-mcp@latest",
182+"--experimentalStructuredContent",
183+"--experimental-page-id-routing",
184+"--browserUrl",
185+"http://127.0.0.1:9222",
186+"--no-usage-statistics",
187+]);
188+});
189+190+it("omits the npx package prefix for a custom Chrome MCP command", () => {
191+expect(
192+buildChromeMcpArgs({
193+mcpCommand: "/usr/local/bin/chrome-devtools-mcp",
194+cdpUrl: "http://127.0.0.1:9222",
195+}),
196+).toEqual([
197+"--browserUrl",
198+"http://127.0.0.1:9222",
199+"--experimentalStructuredContent",
200+"--experimental-page-id-routing",
201+]);
202+});
203+142204it("parses new_page text responses and returns the created tab", async () => {
143205const factory: ChromeMcpSessionFactory = async () => createFakeSession();
144206setChromeMcpSessionFactoryForTest(factory);
@@ -435,8 +497,8 @@ describe("chrome MCP page parsing", () => {
435497const createdSessions: ChromeMcpSession[] = [];
436498const closeMocks: Array<ReturnType<typeof vi.fn>> = [];
437499const factoryCalls: Array<{ profileName: string; userDataDir?: string }> = [];
438-const factory: ChromeMcpSessionFactory = async (profileName, userDataDir) => {
439-factoryCalls.push({ profileName, userDataDir });
500+const factory: ChromeMcpSessionFactory = async (profileName, options) => {
501+factoryCalls.push({ profileName, userDataDir: options?.userDataDir });
440502const session = createFakeSession();
441503const closeMock = vi.fn().mockResolvedValue(undefined);
442504session.client.close = closeMock as typeof session.client.close;
此内容由惯性聚合(RSS阅读器)自动聚合整理,仅供阅读参考。 原文来自 — 版权归原作者所有。