mirror of
https://github.com/penpot/penpot.git
synced 2026-10-29 22:10:34 +00:00
Let a browser extension learn which tab holds an MCP session, so it can wake that tab when the browser freezes it. While the MCP plugin runs, the page listens for the extension's hello message, and says it is ready once it listens, so that a content script that said hello too early says it again. After a hello, the page posts its session ID, MCP server URL, token and connection status, and posts them again on every status change. When the plugin stops, it reports the session as disconnected. The plugin also reports "disconnected" while it reconnects on its own, for instance after a page resume, so the page announces "connecting" then and "disconnected" only once the user has stopped the connection. Otherwise the extension would forget the session at every reconnect. The page only accepts messages posted on its own window by its own origin, posts to its own origin only, and sends nothing before the extension asks, so the token stays in the page when no extension is installed. It reaches the window through app.util.globals, whose stand-in for the unit tests accepts postMessage.