mirror of
https://github.com/penpot/penpot.git
synced 2026-11-14 14:00:36 +00:00
Build one extension per browser, in dist/chrome and dist/firefox, from the same source. A script makes each manifest. The code keeps the chrome namespace, which Firefox implements with promises in Manifest V3. The Firefox manifest runs the background as an event page, leaves out the debugger permission, and sets the add-on ID and Firefox 140 as the minimum version. Its extension page policy drops the default upgrade-insecure-requests, which would turn ws:// servers into wss://. Firefox has no debugger API, and it does not freeze background pages: it only slows their timers, which the plugin's heartbeat survives. The background therefore unfreezes in place only where the debugger API exists, and otherwise brings the tab forward and goes back, as a fallback that should rarely run. Firefox stops an event page that is idle for 30 s, even while its WebSocket is open, so the wake agent connection would drop and come back with each alarm. While it holds a connection, the background calls an extension API every 20 s, which Firefox counts as activity.
57 lines
1.9 KiB
JavaScript
57 lines
1.9 KiB
JavaScript
/** Browsers the extension is built for, one directory of `dist/` each. */
|
|
export const BROWSERS = ["chrome", "firefox"];
|
|
|
|
const CONTENT_SCRIPTS = [
|
|
{
|
|
matches: ["https://design.penpot.app/*", "https://localhost/*", "http://localhost/*"],
|
|
js: ["content.js"],
|
|
run_at: "document_idle",
|
|
},
|
|
];
|
|
|
|
/**
|
|
* Creates the extension manifest for a browser.
|
|
*
|
|
* Chrome runs the background as a module service worker and needs `debugger` to unfreeze pages
|
|
* in place. Firefox runs it as an event page, has no debugger API and needs an add-on ID.
|
|
*
|
|
* @param {"chrome" | "firefox"} browser - The browser to build for
|
|
*/
|
|
export function createManifest(browser) {
|
|
const common = {
|
|
manifest_version: 3,
|
|
name: "Penpot MCP Wake",
|
|
version: "0.1.0",
|
|
description: "Wakes a background Penpot tab when an MCP task needs it.",
|
|
action: {
|
|
default_title: "Penpot MCP Wake",
|
|
default_popup: "popup.html",
|
|
},
|
|
content_scripts: CONTENT_SCRIPTS,
|
|
};
|
|
if (browser === "chrome") {
|
|
return {
|
|
...common,
|
|
minimum_chrome_version: "116",
|
|
// Chrome does not allow debugger as an optional permission
|
|
permissions: ["storage", "alarms", "debugger"],
|
|
background: { service_worker: "background.js", type: "module" },
|
|
};
|
|
}
|
|
return {
|
|
...common,
|
|
permissions: ["storage", "alarms"],
|
|
background: { scripts: ["background.js"] },
|
|
// the default policy adds upgrade-insecure-requests, which breaks ws:// servers
|
|
content_security_policy: { extension_pages: "script-src 'self'" },
|
|
browser_specific_settings: {
|
|
gecko: {
|
|
id: "mcp-wake@penpot.app",
|
|
// the first version that knows data_collection_permissions
|
|
strict_min_version: "140.0",
|
|
data_collection_permissions: { required: ["none"] },
|
|
},
|
|
},
|
|
};
|
|
}
|