How to add metadata to clipboard

Hi, I use dom event to add custom data into the clipboard in addition to the other data that is copied. I used this plugin but I don’t get my custom data (no metter if I return true or false). If I use preventDefault() I get only my custom data without the copied data. How can I do it? this is what I tried:

const clipboardPlugin = new Plugin({ props: {
handleDOMEvents: {
copy: (view, event) => { const clipboard = event.clipboardData;

      if (clipboard) {  
        clipboard.setData('application/my-custom-data', 'my-custom-data');  
      }
      return false;
    }
    }
  },  
});

Thanks.

I don’t think any browsers support adding data other than HTML and plain text to the clipboard.

I can do it this way, but I prefer to do it with ProseMirror:

document.addEventListener(‘copy’, (e) => { e.clipboardData?.setData(‘application/my-custom-data’, ‘my-custom-data’); console.log(‘Final clipboard data:’, { ‘text/plain’: e.clipboardData?.getData(‘text/plain’), ‘text/html’: e.clipboardData?.getData(‘text/html’), ‘application/my-custom-data’: e.clipboardData?.getData(‘application/my-custom-data’) }); });

Seems I was misremembering—browsers isolate the native clipboard from custom web clipboard data for security reasons, but do allow reading such data inside the browser itself.

ProseMirror’s event model doesn’t really intend handlers to do something, then return false, and let other handlers do their thing in addition to that. The idea is that a single handler handles the entire event (and returns true when it does). As such, the native copy handler assumes it is responsible for the entire event, and will clear the clipboardData before adding its data. There’s not currently any way to add to this without, as you found, registering an independent DOM event handler that runs after the built-in one.

Thank you, Marijn.

The native copy handler assumes it is responsible for the entire event, and will clear the clipboardData before adding its data.

With this in mind, would it be possible for ProseMirror to export its serializeForClipboard function so that a handler that wants to add metadata can do so without having to reimplement the whole clipboard serialization logic?