Skip to content

feat: add MCP Chrome extension #325

New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Merged
merged 9 commits into from
Jun 13, 2025
Merged

Conversation

mxschmitt
Copy link
Member

@mxschmitt mxschmitt commented May 2, 2025

Instructions:

  1. git clone https://github.com/mxschmitt/playwright-mcp && git checkout extension-drafft
  2. npm ci && npm run build
  3. chrome://extensions in your normal Chrome, "load unpacked" and select the extension folder.
  4. node cli.js --port=4242 --extension - The URL it prints at the end you can put into the extension popup.

Put either this into Claude Desktop (it does not support SSE yet hence wrapping it or just put the URL into Cursor/VSCode)

{
  "mcpServers": {
    "playwright": {
      "command": "bash",
      "args": [
        "-c",
        "source $HOME/.nvm/nvm.sh && nvm use --silent 22 && npx supergateway --streamableHttp http://127.0.0.1:4242/mcp"
      ]
    }
  }
}

Things like Take a snapshot of my browser. should now work in your Prompt Chat.


  • SSE only for now, since we already have a http server with a port there
  • Upstream "page tests" can be executed over this CDP relay via chore: introduce new extension test mode playwright#36286
  • Limitations for now are everything what happens outside of the tab its session is shared with -> window.open / target=_blank.

@mxschmitt mxschmitt force-pushed the extension-drafft branch 2 times, most recently from 4280890 to dcce7ae Compare May 2, 2025 11:13
@mxschmitt mxschmitt marked this pull request as draft May 2, 2025 12:11
Copy link
Member

@Skn0tt Skn0tt left a comment

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

big change!

@mxschmitt mxschmitt force-pushed the extension-drafft branch 2 times, most recently from ed6a65c to eaf5fa3 Compare May 2, 2025 15:16
@mxschmitt mxschmitt marked this pull request as ready for review May 2, 2025 16:53
@mxschmitt mxschmitt force-pushed the extension-drafft branch from 53be395 to 7040a41 Compare May 2, 2025 20:00
@pavelfeldman
Copy link
Member

Let's structure your code a bit differently:

  • As far as Playwright MCP is concerned, it will talk over CDP, no changes other than a little tweak to the config. No mentions of CDPWebSocketRelay in the context
  • Empty extension that will pump JSON RPC messages into the chrome.debug associated with the tab
    • A page action that "shares" tab with the running MCP server. Ala chromecast
  • A standalone web socket server that Playwright and Extension connect to.
    • This is your bridge.
    • /cdp endpoint is a full CDP, with Browser.* available
    • /extension endpoint that extension forwards chrome.debug. It literally creates chrome.debug instance in the bridge that is indistinguishable from the one in the bg page

@mxschmitt mxschmitt force-pushed the extension-drafft branch from 7040a41 to 0698d71 Compare May 5, 2025 10:11
this.dispatch({ id: message.id, result: versionInfo });
return;
}
if (message.method === 'Target.setAutoAttach' && !message.sessionId) {
Copy link
Contributor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

If message.sessionId exists, I assume it will just forward the request to chrome.debugger.sendCommand, right? I had some issues in the past with Target.setAutoAttach requests on pages with service workers:

https://github.com/ruifigueira/playwright-crx/blob/eb65d74c6bb0e9f04cc4fdff1570ac9b2c53d0fe/src/server/transport/crxTransport.ts#L89-L101

Copy link
Contributor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

And there was also issues with oopif that I had to address on Target.setAutoAttach:

ruifigueira/playwright-crx#20 (comment)

@yury-s yury-s force-pushed the extension-drafft branch from 7e89425 to 6679996 Compare June 12, 2025 23:27
@mxschmitt mxschmitt force-pushed the extension-drafft branch 2 times, most recently from f9a4598 to 1913cc7 Compare June 13, 2025 10:46
Copy link
Member

@yury-s yury-s left a comment

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Let's land and iterate further.

@yury-s yury-s merged commit 6c3f3b6 into microsoft:main Jun 13, 2025
5 of 6 checks passed
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.

5 participants