figma-plugin
Building a Figma plugin
A Figma plugin is two programs talking over postMessage: code.js runs in Figma's plugin sandbox (no DOM, no window) and ui.html runs in an iframe (full DOM). manifest.json declares both (main, ui) plus networkAccess.allowedDomains. Source lives in integrations/figma-plugin/. It is a thin frontend over your own backend — your product's SDK or public REST API. Read this before the first file; the command-level playbook is in itsryanarmani/scripts scripts/figma-plugin/README.md. To publish to Community, use figma-plugin-submission.
When to use
- Triggers: 'build a Figma plugin', 'Figma Plugin API', 'exportAsync', 'figma.clientStorage', 'networkAccess allowedDomains', 'my Figma plugin fetch fails'.
- The two-context split: the sandbox has no DOM but no CORS; the iframe has DOM and full CORS. Every external origin must be in networkAccess.allowedDomains.
- The sandbox has no FormData or Blob, so multipart uploads are hand-built byte arrays; the UI ships as one HTML file inlined via html; export is async via exportAsync.
- Siblings: figma-plugin-submission, canva-app, browser-extension, shopify-app, connector-directory-submission.
The trap that wastes a day: fetch in the wrong context
The two contexts have opposite network rules:
code.js(sandbox):fetchexists and CORS is not enforced — but there is no DOM: noFormData, noBlob, noFileReader, noURL.createObjectURL.ui.html(iframe): full DOM, butfetchis an ordinary browser fetch — CORS applies.
If your API sends no CORS headers (most don't), a browser-side fetch from the UI is blocked and the failure looks like a generic network error with no useful console message. Put every API call in the sandbox; the UI sends intents over parent.postMessage / figma.ui.postMessage and renders the results. Keep the API key sandbox-side too (figma.clientStorage) so the secret never enters the iframe.