Plugins
Build a plugin
Create a manifest and JavaScript command, load it in Developer mode, and test it on a design.
A Popcorn plugin is a manifest plus JavaScript code. It can add a menu command, open a panel, and work with the active document through the popcorn API. Start with one command that makes a small, visible change so you can check the permission and undo behavior.
Make a manifest
Host a manifest.json and the script it names at URLs the browser can fetch. A minimal drawing plugin declares code, API version 1.0, and content:write permission. Add ui only if it opens a panel. Declare network and list the hosts it may reach under networkAccess.allowedDomains (a host such as api.example.com or a wildcard such as *.example.com, never a bare *) if the code needs remote data. Requests are not redirected: if an allowed host answers with a redirect, net.fetch fails with redirect_refused, so call the final address and list its host. The manifest may supply up to eight menu commands.
{
"name": "Hello Shapes",
"code": "plugin.js",
"api": "1.0",
"permissions": [
"content:write"
],
"menu": [
{
"command": "add",
"label": "Add a rectangle"
}
]
}
In plugin.js, register a run handler and use the document API instead of editing canvas internals:
popcorn.on('run', async () => {
await popcorn.createRectangle({
x: 40,
y: 40,
width: 120,
height: 80,
fill: '#e5e5e5'
});
popcorn.notify('Rectangle added');
});
Test it
Open Plugins → Manage plugins… → Developer and load the manifest URL. Run the command on a throwaway design, then check selection, undo, and any error message. Developer installs stay in this browser. To make a plugin available through Browse, it must be published to the curated catalog.
Other useful document methods include selection(), currentPage(), createText(), createImage(), update(), remove(), and batch(). Use batch() when several changes should form one undo step. createImage() takes the image's bytes or pixels. A web address works only with network permission and a host in allowedDomains; Popcorn then downloads it once and stores the copy. The image must be PNG, JPEG, WebP, GIF or SVG. Review permissions and safety before adding more access, and test every method against the API version in your manifest.