superlistapp / super_native_extensions

Native drag & drop, clipboard access and context menu.
MIT License
459 stars 84 forks source link

Add support for web formats #423

Open jezell opened 2 months ago

jezell commented 2 months ago

Browsers won't let people add pdfs and almost anything but images + text to the clipboard by default, so the Chrome team came up with an idea called "web custom formats" to work around the issue. With web custom formats, apps can read and write any file type they want including internal data formats. These formats sometimes restrict things from working outside the browser, but at least they work within the browser.

https://developer.chrome.com/blog/web-custom-formats-for-the-async-clipboard-api

While it is possible to set these content types manually, it would be nice if it worked out of the box with things like Formats.pdf on web, and potentially if the other platforms also were updated to support "web " prefixes to allow pasting from web to other platforms:

const webPDFFormat = SimpleFileFormat(
  uniformTypeIdentifiers: ['com.adobe.pdf'],
  mimeTypes: ['web application/pdf'],
);

More details and very good explanation of the current state of Clipboard hacks and APIs on web: https://alexharri.com/blog/clipboard

Potentially fixes:

351

aardrop commented 1 month ago

I'm having similar challenges with even writing plaintext to the clipboard on the web. Is this common across all Formats on web?

jezell commented 1 month ago

@aardrop plain text should be safe to put in the clipboard on the web, assuming the site has been granted clipboard permissions by the user. Web generally allows text, html, and images without special hacks, but you can read more in the articles linked above about it.