Skip to content

Commit be6e7cc

Browse files
authored
fix(mcp): do not clobber chromiumSandbox from the config file (#42288)
1 parent 04fb72b commit be6e7cc

2 files changed

Lines changed: 37 additions & 4 deletions

File tree

packages/playwright-core/src/tools/mcp/program.ts

Lines changed: 0 additions & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -81,10 +81,6 @@ export function decorateMCPCommand(command: Command) {
8181
.option('--viewport-size <size>', 'specify browser viewport size in pixels, for example "1280x720"', resolutionParser.bind(null, '--viewport-size'))
8282
.addOption(new ProgramOption('--vision', 'Legacy option, use --caps=vision instead').hideHelp())
8383
.action(async options => {
84-
85-
// normalize the --no-sandbox option: sandbox = true => nothing was passed, sandbox = false => --no-sandbox was passed.
86-
options.sandbox = options.sandbox === true ? undefined : false;
87-
8884
setupExitWatchdog();
8985

9086
if (options.vision) {

tests/mcp/config.spec.ts

Lines changed: 37 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -173,3 +173,40 @@ test('browser_get_config returns merged config from file, env and cli', async ({
173173
// From CLI arg (--isolated).
174174
expect(config.browser.isolated).toBe(true);
175175
});
176+
177+
test.describe('chromiumSandbox', () => {
178+
test.skip(({ mcpBrowser }) => mcpBrowser !== 'chrome', 'Channel-agnostic tests.');
179+
180+
test('config file value is respected', { annotation: { type: 'issue', description: 'https://github.com/microsoft/playwright-mcp/issues/1716' } }, async ({ startClient }) => {
181+
const { client } = await startClient({
182+
config: {
183+
capabilities: ['config'],
184+
browser: { launchOptions: { chromiumSandbox: true } },
185+
},
186+
});
187+
const config = JSON.parse(parseResponse(await client.callTool({ name: 'browser_get_config' })).result);
188+
expect(config.browser.launchOptions.chromiumSandbox).toBe(true);
189+
});
190+
191+
test('--no-sandbox overrides config file value', async ({ startClient }) => {
192+
const { client } = await startClient({
193+
config: {
194+
capabilities: ['config'],
195+
browser: { launchOptions: { chromiumSandbox: true } },
196+
},
197+
args: ['--no-sandbox'],
198+
});
199+
const config = JSON.parse(parseResponse(await client.callTool({ name: 'browser_get_config' })).result);
200+
expect(config.browser.launchOptions.chromiumSandbox).toBe(false);
201+
});
202+
203+
test('--sandbox enables the sandbox', async ({ startClient }) => {
204+
const { client } = await startClient({
205+
config: { capabilities: ['config'] },
206+
args: ['--browser=chromium', '--sandbox'],
207+
});
208+
const config = JSON.parse(parseResponse(await client.callTool({ name: 'browser_get_config' })).result);
209+
expect(config.browser.launchOptions.channel).toBe('chrome-for-testing');
210+
expect(config.browser.launchOptions.chromiumSandbox).toBe(true);
211+
});
212+
});

0 commit comments

Comments
 (0)