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.
JavaScript claude-code-pluginclaude-code-skillscode-appsgithub-copilot-pluginpower-appspower-pagespower-platform
Pin Power Pages Playwright MCP runtime (#383)
Priyanshu Agrawala2f38979f143
diff --git a/plugins/power-pages/scripts/launch-playwright-mcp.js b/plugins/power-pages/scripts/launch-playwright-mcp.jsindex 2762542d9..8ab84a967 100644--- a/plugins/power-pages/scripts/launch-playwright-mcp.js+++ b/plugins/power-pages/scripts/launch-playwright-mcp.js@@ -5,45 +5,85 @@// then falls back to Playwright's bundled Chromium.// Self-contained — no external dependencies required.-const { spawn } = require('child_process');+const { spawn } = require('node:child_process');+const fs = require('node:fs');const path = require('path');const { detectBrowser } = require('./lib/detect-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, "'\\''")}'`;-}+const PLAYWRIGHT_MCP_VERSION = '0.0.78';+const PLAYWRIGHT_MCP_PACKAGE = `@playwright/mcp@${PLAYWRIGHT_MCP_VERSION}`;function buildMcpArgs(browser, {configPath = path.join(__dirname, 'playwright-mcp-fullscreen.config.json'),- platform = process.platform,} = {}) {+ // Marketplace installs copy only this plugin directory and do not run npm install,+ // so a lockfile would not materialize a local executable. Keep the runtime package+ // immutable, and disable lifecycle scripts while npx prepares the reviewed version.return [- '-y',- '@playwright/mcp@latest',+ '--yes',+ '--ignore-scripts',+ `--package=${PLAYWRIGHT_MCP_PACKAGE}`,+ 'playwright-mcp','--browser',browser,'--config',- quoteShellArg(configPath, platform),+ configPath,+ ];+}++function resolveNpxCli({+ execPath = process.execPath,+ platform = process.platform,+ existsSync = fs.existsSync,+} = {}) {+ // Windows exposes npx as a .cmd shim that cannot run with shell:false. Invoking+ // npm's JavaScript entrypoint through Node preserves raw argv on every platform.+ const pathApi = platform === 'win32' ? path.win32 : path.posix;+ const nodeDir = pathApi.dirname(execPath);+ const candidates = [+ pathApi.resolve(nodeDir, '..', 'lib', 'node_modules', 'npm', 'bin', 'npx-cli.js'),+ pathApi.join(nodeDir, 'node_modules', 'npm', 'bin', 'npx-cli.js'),];+ const match = candidates.find((candidate) => existsSync(candidate));++ if (!match) {+ throw new Error(+ 'Could not locate npm/bin/npx-cli.js beside the current Node installation. Install Node.js with npm before starting the Playwright MCP server.',+ );+ }++ return match;}-function launch({ browser = detectBrowser(), spawnFn = spawn, onExit = (code) => process.exit(code || 0) } = {}) {- const child = spawnFn('npx', buildMcpArgs(browser), {+function launch({+ browser = detectBrowser(),+ npxCliPath,+ resolveNpxCliFn = resolveNpxCli,+ spawnFn = spawn,+ exitFn = (code) => process.exit(code),+ writeError = (message) => process.stderr.write(message),+} = {}) {+ let resolvedNpxCliPath = npxCliPath;+ if (resolvedNpxCliPath === undefined) {+ try {+ resolvedNpxCliPath = resolveNpxCliFn();+ } catch (error) {+ writeError(`Failed to start Playwright MCP: ${error.message}\n`);+ exitFn(1);+ return null;+ }+ }++ const child = spawnFn(process.execPath, [resolvedNpxCliPath, ...buildMcpArgs(browser)], {stdio: 'inherit',- shell: true,+ shell: false,});- child.on('exit', onExit);+ child.once('error', (error) => {+ writeError(`Failed to start Playwright MCP: ${error.message}\n`);+ exitFn(1);+ });+ child.once('exit', (code) => exitFn(code ?? 1));return child;}@@ -51,4 +91,9 @@ if (require.main === module) {launch();}-module.exports = { buildMcpArgs, launch, quoteShellArg };+module.exports = {+ PLAYWRIGHT_MCP_PACKAGE,+ buildMcpArgs,+ launch,+ resolveNpxCli,+};diff --git a/plugins/power-pages/scripts/tests/launch-playwright-mcp.test.js b/plugins/power-pages/scripts/tests/launch-playwright-mcp.test.jsindex 0a5323fe5..d928b2418 100644--- a/plugins/power-pages/scripts/tests/launch-playwright-mcp.test.js+++ b/plugins/power-pages/scripts/tests/launch-playwright-mcp.test.js@@ -5,28 +5,69 @@ const test = require('node:test');const { EventEmitter } = require('node:events');const {+ PLAYWRIGHT_MCP_PACKAGE,buildMcpArgs,launch,- quoteShellArg,+ resolveNpxCli,} = require('../launch-playwright-mcp');-test('buildMcpArgs launches Playwright MCP with fullscreen config', () => {+test('buildMcpArgs launches the exact reviewed Playwright MCP version', () => {const expectedConfigPath = path.join(__dirname, '..', 'playwright-mcp-fullscreen.config.json');const args = buildMcpArgs('chrome');const configIndex = args.indexOf('--config');- assert.deepEqual(args.slice(0, 4), ['-y', '@playwright/mcp@latest', '--browser', 'chrome']);+ assert.equal(PLAYWRIGHT_MCP_PACKAGE, '@playwright/[email protected]');+ assert.deepEqual(+ args.slice(0, 6),+ [+ '--yes',+ '--ignore-scripts',+ '--package=@playwright/[email protected]',+ 'playwright-mcp',+ '--browser',+ 'chrome',+ ],+ );+ assert.equal(args.some((arg) => /@(latest|next|\^|~|\*)$/.test(arg)), false);assert.equal(args.includes('--viewport-size'), false);assert.notEqual(configIndex, -1);- assert.equal(args[configIndex + 1], quoteShellArg(expectedConfigPath));+ assert.equal(args[configIndex + 1], 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' });+test('buildMcpArgs preserves config paths with spaces and shell metacharacters as raw argv', () => {+ const configPath = '/tmp/Power Pages $(echo unsafe); & [preview]/config\'s "quoted" path.json';+ const args = buildMcpArgs('chrome', { configPath });const configIndex = args.indexOf('--config');- assert.equal(args[configIndex + 1], `"${configPath}"`);+ assert.equal(args[configIndex + 1], configPath);+});++test('buildMcpArgs preserves Windows config paths without shell quoting', () => {+ const configPath = 'C:\\Users\\Power User & Team\\Power Pages (Preview)\\playwright-mcp.config.json';+ const args = buildMcpArgs('msedge', { configPath });+ const configIndex = args.indexOf('--config');++ assert.equal(args[configIndex + 1], configPath);+});++test('resolveNpxCli finds the Windows npm JavaScript entrypoint', () => {+ const expected = 'C:\\Program Files\\nodejs\\node_modules\\npm\\bin\\npx-cli.js';+ const checked = [];++ const resolved = resolveNpxCli({+ execPath: 'C:\\Program Files\\nodejs\\node.exe',+ platform: 'win32',+ existsSync(candidate) {+ checked.push(candidate);+ return candidate === expected;+ },+ });++ assert.equal(resolved, expected);+ assert.deepEqual(checked, [+ 'C:\\Program Files\\lib\\node_modules\\npm\\bin\\npx-cli.js',+ expected,+ ]);});test('fullscreen config maximizes the browser and uses the real viewport size', () => {@@ -37,25 +78,116 @@ test('fullscreen config maximizes the browser and uses the real viewport size',assert.equal(config.browser.contextOptions.viewport, null);});-test('launch wires spawn and process exit handling', () => {+test('launch preserves an explicit npx CLI path and uses raw argv without a shell', () => {let spawnCall;const child = new EventEmitter();launch({browser: 'msedge',+ npxCliPath: 'C:\\Program Files\\nodejs\\node_modules\\npm\\bin\\npx-cli.js',+ resolveNpxCliFn() {+ assert.fail('explicit npxCliPath must bypass default resolution');+ },spawnFn(command, args, options) {spawnCall = { command, args, options };return child;},- onExit(code) {+ exitFn(code) {spawnCall.exitCode = code;},});- assert.equal(spawnCall.command, 'npx');- assert.deepEqual(spawnCall.args.slice(0, 4), ['-y', '@playwright/mcp@latest', '--browser', 'msedge']);- assert.deepEqual(spawnCall.options, { stdio: 'inherit', shell: true });+ assert.equal(spawnCall.command, process.execPath);+ assert.deepEqual(+ spawnCall.args.slice(0, 7),+ [+ 'C:\\Program Files\\nodejs\\node_modules\\npm\\bin\\npx-cli.js',+ '--yes',+ '--ignore-scripts',+ '--package=@playwright/[email protected]',+ 'playwright-mcp',+ '--browser',+ 'msedge',+ ],+ );+ assert.deepEqual(spawnCall.options, { stdio: 'inherit', shell: false });child.emit('exit', 7);assert.equal(spawnCall.exitCode, 7);});++test('launch reports missing npm once and does not spawn', () => {+ const exits = [];+ let spawnCalls = 0;+ let stderr = '';++ const child = launch({+ browser: 'chrome',+ resolveNpxCliFn() {+ throw new Error('Could not locate npm/bin/npx-cli.js');+ },+ spawnFn() {+ spawnCalls += 1;+ return new EventEmitter();+ },+ exitFn(code) {+ exits.push(code);+ },+ writeError(message) {+ stderr += message;+ },+ });++ assert.equal(child, null);+ assert.equal(spawnCalls, 0);+ assert.deepEqual(exits, [1]);+ assert.equal(+ stderr,+ 'Failed to start Playwright MCP: Could not locate npm/bin/npx-cli.js\n',+ );+});++test('launch reports spawn errors and exits with failure', () => {+ const child = new EventEmitter();+ const exits = [];+ let stderr = '';++ launch({+ browser: 'chrome',+ npxCliPath: '/trusted/npm/bin/npx-cli.js',+ spawnFn() {+ return child;+ },+ exitFn(code) {+ exits.push(code);+ },+ writeError(message) {+ stderr += message;+ },+ });++ child.emit('error', new Error('spawn ENOENT'));++ assert.deepEqual(exits, [1]);+ assert.match(stderr, /^Failed to start Playwright MCP: spawn ENOENT\n$/);+});++test('launch treats signal-only child exits as failures', () => {+ const child = new EventEmitter();+ let exitCode;++ launch({+ browser: 'chrome',+ npxCliPath: '/trusted/npm/bin/npx-cli.js',+ spawnFn() {+ return child;+ },+ exitFn(code) {+ exitCode = code;+ },+ });++ child.emit('exit', null, 'SIGTERM');++ assert.equal(exitCode, 1);+});diff --git a/plugins/power-pages/scripts/tests/mcp-config.test.js b/plugins/power-pages/scripts/tests/mcp-config.test.jsindex 9c215bf6e..f24194aeb 100644--- a/plugins/power-pages/scripts/tests/mcp-config.test.js+++ b/plugins/power-pages/scripts/tests/mcp-config.test.js@@ -9,26 +9,39 @@ const pluginRoot = path.resolve(__dirname, '..', '..');const config = JSON.parse(fs.readFileSync(path.join(pluginRoot, '.mcp.json'), 'utf8'));const server = config.mcpServers.playwright;-function createFakeNpx(dir) {- const commandPath = path.join(dir, process.platform === 'win32' ? 'npx.cmd' : 'npx');- const script = process.platform === 'win32'- ? '@echo off\r\necho fake-npx %*\r\n'- : '#!/bin/sh\necho "fake-npx $*"\n';-- fs.writeFileSync(commandPath, script, { mode: 0o755 });- return commandPath;+function createSpawnPreload(dir) {+ const preloadPath = path.join(dir, 'intercept-spawn.js');+ fs.writeFileSync(preloadPath, `+const { EventEmitter } = require('node:events');+const fs = require('node:fs');+const realExistsSync = fs.existsSync;+fs.existsSync = (candidate) => {+ if (String(candidate).replaceAll('\\\\', '/').endsWith('/npm/bin/npx-cli.js')) {+ process.stdout.write('fake-npx-cli ' + candidate + '\\n');+ return true;+ }+ return realExistsSync(candidate);+};+require('node:child_process').spawn = (command, args, options) => {+ process.stdout.write('fake-spawn ' + JSON.stringify({ command, args, options }) + '\\n');+ const child = new EventEmitter();+ process.nextTick(() => child.emit('exit', 0));+ return child;+};+`);+ return preloadPath;}function runBootstrap({cwd,pluginRoot: pluginRootValue,claudePluginRoot,- pathPrefix,+ preloadPath,realpathOverride,statFailure,} = {}) {const env = { ...process.env };- const args = [...server.args];+ let args = [...server.args];delete env.PLUGIN_ROOT;delete env.CLAUDE_PLUGIN_ROOT;@@ -38,10 +51,6 @@ function runBootstrap({if (claudePluginRoot !== undefined) {env.CLAUDE_PLUGIN_ROOT = claudePluginRoot;}- if (pathPrefix) {- const pathSeparator = process.platform === 'win32' ? ';' : ':';- env.PATH = `${pathPrefix}${pathSeparator}${env.PATH || ''}`;- }if (realpathOverride) {// Patch only the launcher lookup so the canonical root still follows the real filesystem.const bootstrapIndex = args.indexOf('-e') + 1;@@ -67,6 +76,10 @@ function runBootstrap({args[bootstrapIndex] = `${prelude} ${args[bootstrapIndex]}`;}+ if (preloadPath) {+ args = ['--require', preloadPath, ...args];+ }+return spawnSync(server.command, args, {cwd,encoding: 'utf8',@@ -228,27 +241,33 @@ test('playwright MCP bootstrap supports installed-plugin root environment convenconst tempDir = fs.mkdtempSync(path.join(os.tmpdir(), 'power-pages-mcp-'));t.after(() => fs.rmSync(tempDir, { recursive: true, force: true }));- createFakeNpx(tempDir);+ const preloadPath = createSpawnPreload(tempDir);await t.test('PLUGIN_ROOT', () => {const result = runBootstrap({cwd: tempDir,pluginRoot,- pathPrefix: tempDir,+ preloadPath,});assert.equal(result.status, 0, result.stderr);- assert.match(result.stdout, /fake-npx/);+ assert.match(result.stdout, /fake-npx-cli/);+ assert.match(result.stdout, /fake-spawn/);+ assert.match(result.stdout, /--package=@playwright\/mcp@0\.0\.78/);+ assert.match(result.stdout, /"shell":false/);});await t.test('CLAUDE_PLUGIN_ROOT', () => {const result = runBootstrap({cwd: tempDir,claudePluginRoot: pluginRoot,- pathPrefix: tempDir,+ preloadPath,});assert.equal(result.status, 0, result.stderr);- assert.match(result.stdout, /fake-npx/);+ assert.match(result.stdout, /fake-npx-cli/);+ assert.match(result.stdout, /fake-spawn/);+ assert.match(result.stdout, /--package=@playwright\/mcp@0\.0\.78/);+ assert.match(result.stdout, /"shell":false/);});});