How can a plugin access the Clipboard API?

I’ve been working on a plugin for Penpot, and I’ve hit a roadblock with clipboard functionality. The plugin’s iframe permissions policy blocks me from using navigator.clipboard.writeText.

Since the plugin manifest.json file includes a “permissions” section, I wonder if we could get a “clipboard” permission. If this could enable clipboard access (or at least make it configurable for plugin developers), it’d solve a major limitation.

Here’s what I’ve tried so far, but nothing worked:

  • Falling back to document.execCommand(“copy”) → No luck.
  • Sending data to the parent frame with postMessage → Couldn’t access window, parent, or navigator.

It feels like I’ve thrown everything at the wall, but clipboard access is still out of reach. Adding a clipboard option in the permissions section of the manifest.json would be a game-changer.

What do you think? Is this something that could be supported?

Thanks!

@Jemeni11 document.execCommand(“copy”) should work, I’m using also that in my Color Picker plugin → color-picker-penpot/src/main.ts at 89d3d1061191efb070957f70390ba75b95028cb1 · girafic/color-picker-penpot · GitHub

Currently, the Clipboard API cannot be used within plugin.js or the plugin interface. However, within the plugin interface, it should be possible to use document.execCommand("copy"). This initial limitation is due to security reasons, but we expect to gradually unlock additional APIs over time.