When --config points to a malformed JSON configuration, Playwright MCP starts with the default configuration instead of reporting the JSON parse error. This reproduces on current main (d58bc892f28561a81924ee3220a314c1a9f25ec8).
For example, this config intends to select Firefox but contains a trailing comma:
{ "browser": { "browserName": "firefox", } }
The resulting config uses the default Chromium/Chrome settings and includes the original JSON text as an unused top-level INI key:
{
"browser": {
"browserName": "chromium",
"launchOptions": { "channel": "chrome", ... }
},
"{ \"browser\": { \"browserName\": \"firefox\", } }": true,
...
}
I reproduced this with a focused config-resolution test:
test('malformed JSON config throws instead of being parsed as INI', async ({}, testInfo) => {
const configFile = testInfo.outputPath('config.json');
await fs.promises.writeFile(configFile, '{ "browser": { "browserName": "firefox", } }');
await expect(resolveCLIConfigForMCP({ config: configFile }, {}))
.rejects.toThrow();
});
On current main, the test fails with Received promise resolved instead of rejected.
I would expect JSON-looking input with invalid syntax to report the original parse error rather than continue with the default config. INI input should remain supported.
The behavior comes from the broad JSON-to-INI fallback in packages/playwright-core/src/tools/mcp/config.ts:
try {
const data = await fs.promises.readFile(configFile, 'utf8');
return JSON.parse(data.charCodeAt(0) === 0xFEFF ? data.slice(1) : data);
} catch {
return configFromIniFile(configFile);
}
As a possible implementation, the loader could strip the optional BOM, inspect the first non-whitespace character, and preserve the JSON parse error for JSON-looking input while retaining the existing INI fallback for other content.
I prototyped that approach locally and verified that malformed JSON reports its original SyntaxError, while valid JSON, JSON with a UTF-8 BOM, and INI content continue to work. The focused config-resolution suite passes.
Related: #39420 handles a UTF-8 BOM before JSON parsing, but the loader still falls back to INI for other JSON parse errors.
I would be happy to implement the focused fix and regression test if maintainers consider it suitable for a community contribution.
1.62.0-next, current main commit d58bc892f28561a81924ee3220a314c1a9f25ec8
When
--configpoints to a malformed JSON configuration, Playwright MCP starts with the default configuration instead of reporting the JSON parse error. This reproduces on currentmain(d58bc892f28561a81924ee3220a314c1a9f25ec8).For example, this config intends to select Firefox but contains a trailing comma:
{ "browser": { "browserName": "firefox", } }The resulting config uses the default Chromium/Chrome settings and includes the original JSON text as an unused top-level INI key:
I reproduced this with a focused config-resolution test:
On current
main, the test fails withReceived promise resolved instead of rejected.I would expect JSON-looking input with invalid syntax to report the original parse error rather than continue with the default config. INI input should remain supported.
The behavior comes from the broad JSON-to-INI fallback in
packages/playwright-core/src/tools/mcp/config.ts:As a possible implementation, the loader could strip the optional BOM, inspect the first non-whitespace character, and preserve the JSON parse error for JSON-looking input while retaining the existing INI fallback for other content.
I prototyped that approach locally and verified that malformed JSON reports its original
SyntaxError, while valid JSON, JSON with a UTF-8 BOM, and INI content continue to work. The focused config-resolution suite passes.Related: #39420 handles a UTF-8 BOM before JSON parsing, but the loader still falls back to INI for other JSON parse errors.
I would be happy to implement the focused fix and regression test if maintainers consider it suitable for a community contribution.
1.62.0-next, currentmaincommitd58bc892f28561a81924ee3220a314c1a9f25ec8