Skip to content

Add Playwright based MCP server#1647

Closed
lilac wants to merge 11 commits intoweb-infra-dev:mainfrom
lilac:playwright
Closed

Add Playwright based MCP server#1647
lilac wants to merge 11 commits intoweb-infra-dev:mainfrom
lilac:playwright

Conversation

@lilac
Copy link
Copy Markdown
Contributor

@lilac lilac commented Dec 23, 2025

In v1 the MCP server for web automation only supports bridge mode. This change bring the deprecated MCP server back.

…core

- Move playwright from devDependencies to dependencies so it's available at runtime
- Add playwright-core to externals to prevent bundling issues
- Fixes 'Cannot find module playwright-core' error when running in http mode
…nshots

- Add waitForNetworkIdle method to BaseAgent interface in types.ts
- Call waitForNetworkIdle after action execution in tool-generator.ts
- Update PlaywrightAgent.waitForNetworkIdle to use optional timeout,
  respecting Playwright's configured navigationTimeout by default

This fixes an issue where clicking links that trigger navigation would
return screenshots of the old page before the new page finished loading.
Add common tools for browser control that execute directly without AI:
- navigate, reload, go_back, go_forward, get_url, get_title

Also add web_close tool to playwright-mcp and web-bridge-mcp.
Some MCP clients like Cursor perform client-side tool argument validation
that incorrectly rejected string values when the schema specified
union([string, number]). Simplified the value field to accept only strings,
which fixes compatibility issues while maintaining the same runtime behavior.

The transform() call is also removed since it's no longer needed.
@netlify
Copy link
Copy Markdown

netlify Bot commented Dec 23, 2025

Deploy Preview for midscene ready!

Name Link
🔨 Latest commit bda3b2e
🔍 Latest deploy log https://app.netlify.com/projects/midscene/deploys/6984b02f58c5f100089df883
😎 Deploy Preview https://deploy-preview-1647--midscene.netlify.app
📱 Preview on mobile
Toggle QR Code...

QR Code

Use your smartphone camera to open QR code link.

To edit notification comments on pull requests, go to your Netlify project configuration.

lilac added 2 commits January 9, 2026 22:57
Actions like KeyboardPress with no locate parameter should execute
directly without calling the AI model service. Previously, all actions
went through aiAction() which requires AI, causing 403 errors when
pressing keys like Enter/Tab without specifying an element to locate.

Changes:
- Add callActionInActionSpace to BaseAgent interface for direct execution
- Add actionNeedsAI() to detect if locate fields require AI resolution
- Use direct execution when no locate prompt is provided
- Fall back to aiAction only when AI reasoning is needed
- Set viewport: null initially to detect natural window size
- Cap viewport at 1280x720 maximum for consistency on large screens
- Fit to actual window size on smaller screens to prevent overflow
- Use innerWidth/innerHeight for accurate viewport detection
@quanru
Copy link
Copy Markdown
Collaborator

quanru commented Mar 9, 2026

Thanks for the contribution! However, our current codebase already supports non-bridge mode for the web MCP server.

In packages/web-integration/src/cli.ts, the default mode is Puppeteer-based (non-bridge). The --bridge flag is required to use bridge mode:

const isBridge = process.argv.includes('--bridge');
const tools = isBridge
  ? new WebMidsceneTools()           // Bridge mode
  : new WebPuppeteerMidsceneTools(); // Default: Puppeteer non-bridge mode

The WebPuppeteerMidsceneTools class (in packages/web-integration/src/mcp-tools-puppeteer.ts) provides direct browser automation via Puppeteer without requiring the Chrome extension bridge. It launches a persistent Chrome instance and supports web_connect, web_disconnect, and web_close operations - similar to what this PR proposes with Playwright.

So we don't think adding a separate Playwright-based MCP package is necessary at this point, as the existing Puppeteer mode already covers this use case. If you have specific requirements that Puppeteer mode doesn't satisfy, feel free to share them and we can discuss further.

@quanru
Copy link
Copy Markdown
Collaborator

quanru commented Mar 9, 2026

If there is still a need, please reopen the current pr

@quanru quanru closed this Mar 9, 2026
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment

Labels

None yet

Projects

None yet

Development

Successfully merging this pull request may close these issues.

2 participants