Skip to content

A plugin marketplace for GitHub Copilot and other AI agents that provides Power Platform development plugins, including reusable skills, agents, and commands for building and deploying solutions.

Fix Playwright MCP config path quoting (#187)

Priyanshu Agrawal36fcbc74d99f
diff --git a/plugins/power-pages/scripts/launch-playwright-mcp.js b/plugins/power-pages/scripts/launch-playwright-mcp.js
index dd46c29c6..cc1986787 100644
--- a/plugins/power-pages/scripts/launch-playwright-mcp.js
+++ b/plugins/power-pages/scripts/launch-playwright-mcp.js
@@ -9,13 +9,30 @@ const { spawn } = require('child_process');
const path = require('path');
const { detectBrowser } = require('./lib/detect-browser');
-function buildMcpArgs(browser) {
+function quoteShellArg(value, platform = process.platform) {
+ const argument = String(value);
+
+ if (platform === 'win32') {
+ if (argument.includes('"')) {
+ throw new Error('Cannot quote an argument containing double quotes for cmd.exe.');
+ }
+
+ return `"${argument}"`;
+ }
+
+ return `'${argument.replace(/'/g, "'\\''")}'`;
+}
+
+function buildMcpArgs(browser, {
+ configPath = path.join(__dirname, 'playwright-mcp-fullscreen.config.json'),
+ platform = process.platform,
+} = {}) {
return [
'@playwright/mcp@latest',
'--browser',
browser,
'--config',
- path.join(__dirname, 'playwright-mcp-fullscreen.config.json'),
+ quoteShellArg(configPath, platform),
];
}
@@ -33,4 +50,4 @@ if (require.main === module) {
launch();
}
-module.exports = { buildMcpArgs, launch };
+module.exports = { buildMcpArgs, launch, quoteShellArg };
diff --git a/plugins/power-pages/scripts/tests/launch-playwright-mcp.test.js b/plugins/power-pages/scripts/tests/launch-playwright-mcp.test.js
index c67b15ddb..2f7c11a76 100644
--- a/plugins/power-pages/scripts/tests/launch-playwright-mcp.test.js
+++ b/plugins/power-pages/scripts/tests/launch-playwright-mcp.test.js
@@ -7,16 +7,26 @@ const { EventEmitter } = require('node:events');
const {
buildMcpArgs,
launch,
+ quoteShellArg,
} = require('../launch-playwright-mcp');
test('buildMcpArgs launches Playwright MCP with fullscreen config', () => {
+ const expectedConfigPath = path.join(__dirname, '..', 'playwright-mcp-fullscreen.config.json');
const args = buildMcpArgs('chrome');
const configIndex = args.indexOf('--config');
assert.deepEqual(args.slice(0, 3), ['@playwright/mcp@latest', '--browser', 'chrome']);
assert.equal(args.includes('--viewport-size'), false);
assert.notEqual(configIndex, -1);
- assert.equal(path.basename(args[configIndex + 1]), 'playwright-mcp-fullscreen.config.json');
+ assert.equal(args[configIndex + 1], quoteShellArg(expectedConfigPath));
+});
+
+test('buildMcpArgs quotes Windows config paths containing spaces', () => {
+ const configPath = 'C:\\Users\\Power User\\.claude\\plugins\\power-pages\\scripts\\playwright-mcp-fullscreen.config.json';
+ const args = buildMcpArgs('msedge', { configPath, platform: 'win32' });
+ const configIndex = args.indexOf('--config');
+
+ assert.equal(args[configIndex + 1], `"${configPath}"`);
});
test('fullscreen config maximizes the browser and uses the real viewport size', () => {