mirror of
https://github.com/microsoft/playwright-mcp.git
synced 2025-07-27 00:52:27 +08:00
chore: fix merge config (#311)
This commit is contained in:
parent
fd22def4c5
commit
6d6b1a384b
@ -89,7 +89,7 @@ export async function configFromCLIOptions(cliOptions: CLIOptions): Promise<Conf
|
|||||||
const launchOptions: LaunchOptions = {
|
const launchOptions: LaunchOptions = {
|
||||||
channel,
|
channel,
|
||||||
executablePath: cliOptions.executablePath,
|
executablePath: cliOptions.executablePath,
|
||||||
headless: cliOptions.headless ?? false,
|
headless: cliOptions.headless,
|
||||||
};
|
};
|
||||||
|
|
||||||
if (browserName === 'chromium')
|
if (browserName === 'chromium')
|
||||||
@ -158,24 +158,33 @@ export async function outputFile(config: Config, name: string): Promise<string>
|
|||||||
return path.join(result, fileName);
|
return path.join(result, fileName);
|
||||||
}
|
}
|
||||||
|
|
||||||
|
function pickDefined<T extends object>(obj: T | undefined): Partial<T> {
|
||||||
|
return Object.fromEntries(
|
||||||
|
Object.entries(obj ?? {}).filter(([_, v]) => v !== undefined)
|
||||||
|
) as Partial<T>;
|
||||||
|
}
|
||||||
|
|
||||||
function mergeConfig(base: Config, overrides: Config): Config {
|
function mergeConfig(base: Config, overrides: Config): Config {
|
||||||
const browser: Config['browser'] = {
|
const browser: Config['browser'] = {
|
||||||
...base.browser,
|
...pickDefined(base.browser),
|
||||||
...overrides.browser,
|
...pickDefined(overrides.browser),
|
||||||
launchOptions: {
|
launchOptions: {
|
||||||
...base.browser?.launchOptions,
|
...pickDefined(base.browser?.launchOptions),
|
||||||
...overrides.browser?.launchOptions,
|
...pickDefined(overrides.browser?.launchOptions),
|
||||||
...{ assistantMode: true },
|
...{ assistantMode: true },
|
||||||
},
|
},
|
||||||
contextOptions: {
|
contextOptions: {
|
||||||
...base.browser?.contextOptions,
|
...pickDefined(base.browser?.contextOptions),
|
||||||
...overrides.browser?.contextOptions,
|
...pickDefined(overrides.browser?.contextOptions),
|
||||||
},
|
},
|
||||||
};
|
};
|
||||||
|
|
||||||
|
if (browser.browserName !== 'chromium')
|
||||||
|
delete browser.launchOptions.channel;
|
||||||
|
|
||||||
return {
|
return {
|
||||||
...base,
|
...pickDefined(base),
|
||||||
...overrides,
|
...pickDefined(overrides),
|
||||||
browser,
|
browser,
|
||||||
};
|
};
|
||||||
}
|
}
|
||||||
|
@ -41,6 +41,7 @@ program
|
|||||||
.option('--config <path>', 'Path to the configuration file.')
|
.option('--config <path>', 'Path to the configuration file.')
|
||||||
.action(async options => {
|
.action(async options => {
|
||||||
const config = await resolveConfig(options);
|
const config = await resolveConfig(options);
|
||||||
|
console.error(config);
|
||||||
const serverList = new ServerList(() => createServer(config));
|
const serverList = new ServerList(() => createServer(config));
|
||||||
setupExitWatchdog(serverList);
|
setupExitWatchdog(serverList);
|
||||||
|
|
||||||
|
@ -34,11 +34,11 @@ type TestFixtures = {
|
|||||||
cdpEndpoint: string;
|
cdpEndpoint: string;
|
||||||
server: TestServer;
|
server: TestServer;
|
||||||
httpsServer: TestServer;
|
httpsServer: TestServer;
|
||||||
|
mcpHeadless: boolean;
|
||||||
|
mcpBrowser: string | undefined;
|
||||||
};
|
};
|
||||||
|
|
||||||
type WorkerFixtures = {
|
type WorkerFixtures = {
|
||||||
mcpHeadless: boolean;
|
|
||||||
mcpBrowser: string | undefined;
|
|
||||||
_workerServers: { server: TestServer, httpsServer: TestServer };
|
_workerServers: { server: TestServer, httpsServer: TestServer };
|
||||||
};
|
};
|
||||||
|
|
||||||
@ -112,11 +112,11 @@ export const test = baseTest.extend<TestFixtures, WorkerFixtures>({
|
|||||||
browserProcess.kill();
|
browserProcess.kill();
|
||||||
},
|
},
|
||||||
|
|
||||||
mcpHeadless: [async ({ headless }, use) => {
|
mcpHeadless: async ({ headless }, use) => {
|
||||||
await use(headless);
|
await use(headless);
|
||||||
}, { scope: 'worker' }],
|
},
|
||||||
|
|
||||||
mcpBrowser: ['chrome', { option: true, scope: 'worker' }],
|
mcpBrowser: ['chrome', { option: true }],
|
||||||
|
|
||||||
_workerServers: [async ({}, use, workerInfo) => {
|
_workerServers: [async ({}, use, workerInfo) => {
|
||||||
const port = 8907 + workerInfo.workerIndex * 4;
|
const port = 8907 + workerInfo.workerIndex * 4;
|
||||||
|
49
tests/headed.spec.ts
Normal file
49
tests/headed.spec.ts
Normal file
@ -0,0 +1,49 @@
|
|||||||
|
/**
|
||||||
|
* Copyright (c) Microsoft Corporation.
|
||||||
|
*
|
||||||
|
* Licensed under the Apache License, Version 2.0 (the "License");
|
||||||
|
* you may not use this file except in compliance with the License.
|
||||||
|
* You may obtain a copy of the License at
|
||||||
|
*
|
||||||
|
* http://www.apache.org/licenses/LICENSE-2.0
|
||||||
|
*
|
||||||
|
* Unless required by applicable law or agreed to in writing, software
|
||||||
|
* distributed under the License is distributed on an "AS IS" BASIS,
|
||||||
|
* WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
|
||||||
|
* See the License for the specific language governing permissions and
|
||||||
|
* limitations under the License.
|
||||||
|
*/
|
||||||
|
|
||||||
|
import { test, expect } from './fixtures';
|
||||||
|
|
||||||
|
for (const mcpHeadless of [false, true]) {
|
||||||
|
test.describe(`mcpHeadless: ${mcpHeadless}`, () => {
|
||||||
|
test.use({ mcpHeadless });
|
||||||
|
test.skip(process.platform === 'linux', 'Auto-detection wont let this test run on linux');
|
||||||
|
test('browser', async ({ client, server, mcpBrowser }) => {
|
||||||
|
test.skip(!['chrome', 'msedge', 'chromium'].includes(mcpBrowser ?? ''), 'Only chrome is supported for this test');
|
||||||
|
server.route('/', (req, res) => {
|
||||||
|
res.writeHead(200, { 'Content-Type': 'text/html' });
|
||||||
|
res.end(`
|
||||||
|
<body></body>
|
||||||
|
<script>
|
||||||
|
document.body.textContent = navigator.userAgent;
|
||||||
|
</script>
|
||||||
|
`);
|
||||||
|
});
|
||||||
|
|
||||||
|
const response = await client.callTool({
|
||||||
|
name: 'browser_navigate',
|
||||||
|
arguments: {
|
||||||
|
url: server.PREFIX,
|
||||||
|
},
|
||||||
|
});
|
||||||
|
|
||||||
|
expect(response).toContainTextContent(`Mozilla/5.0`);
|
||||||
|
if (mcpHeadless)
|
||||||
|
expect(response).toContainTextContent(`HeadlessChrome`);
|
||||||
|
else
|
||||||
|
expect(response).not.toContainTextContent(`HeadlessChrome`);
|
||||||
|
});
|
||||||
|
});
|
||||||
|
}
|
Loading…
x
Reference in New Issue
Block a user