-
Notifications
You must be signed in to change notification settings - Fork 2.1k
Description
The case I'm having is wanting to use Playwright MCP to test an app with webcam + microphone permissions. In our E2E test I add an init script that mocks these permissions and creates a fake video stream using canvas. It's been working pretty great for us.
Problem is that when I try this in Playwright MCP, I can't seem to let it run the js code before the initial page is loaded. And after the page is loaded it already ran the permissions query, so ideally I want this js code to run right on page load.
Proposed Solution
Option 1: CLI argument
playwright-mcp --page-init-js=/path/to/init-script.jsOption 2: New MCP tool
// New tool: browser_add_init_script
mcp__playwright__browser_add_init_script({
script: "window.mockPermissions = true; /* mock code */"
})
// Or load from file
mcp__playwright__browser_add_init_script({
scriptPath: "/path/to/mock-script.js"
})Option 3: Parameter in browser_navigate mcp action
// Enhanced browser_navigate tool
mcp__playwright__browser_navigate({
url: "https://example.com",
initScript: "/* initialization code */"
})Let me know what you think. I'm not an expert in MCP, but it would be really nice to have this so we can start testing our streaming platform with playwright mcp. If you have any other solutions to this then please let me know