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

Open
wants to merge 1 commit into
base: main
Choose a base branch
from

Conversation

mxschmitt
Copy link
Member

No description provided.

@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!

* @typedef {{tabId: number}} DebuggerTarget
*/

function debugLog(...args) {
Copy link
Member

Choose a reason for hiding this comment

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

this looks like a debugging remnant. is there value in commiting it?

Copy link
Member Author

Choose a reason for hiding this comment

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

Probably doesn't hurt!


mcpExtensionPage: async ({ mcpExtension, mcpHeadless }, use) => {
if (!mcpExtension)
return await use(undefined);
Copy link
Member

Choose a reason for hiding this comment

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

throw an error instead, then you don't have to assert() on it on the calling side

Copy link
Member Author

Choose a reason for hiding this comment

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

startClient uses this fixture, so if we remove the undefined we would lie about the type and throw there? So not sure if that suggestion still applies.

@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)

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.

4 participants