I'm building an app that lets the user drag data items out of the browser onto their OS desktop as individual files.
The data I'm exporting is JSON, and I'm setting the MIME type appropriately, but my Mac is wrapping the data in a bunch of strange binary that makes the file worthless for all its intended purposes (which expect pure JSON).
Here's the code I'm using to set up the drag-out-of-browser data:
function onDragStart( event, itemId ) {
let data = itemToJSON(itemId)
event.dataTransfer.setData('application/json', data)
event.dataTransfer.setData('text/plain', data)
}
Here's a screenshot of the file when opened in VSCode. (I'm not pasting the text into this post because I don't expect the non-ASCII to survive a web form.1)
In the screenshot above, the data is the string "TOM RULES".
It includes some plain text that is suggestive, like "bplist", "com.apple.traditional-mac-plain-text", and "public.utf8-plain-text". You can also see from the VSCode breadcrumbs that the OS chose the proprietary ".textClipping" file extension despite my declaring the data type. (I would expect a sane OS to choose ".txt" and ".json" for text/plain and application/json.)
It makes no difference whether I use the proper MIME type for JSON or just stick with plain text: I get the same garbage binary wrapper every time.
This question is also concerned with dragging custom text data out of a browser, but there's no mention of this problem. It's also 11 years old, and I'm already doing what they suggest: declaring my data as plain text.
Is there anything I can do to avoid this, so that the file contains only the literal ASCII text I provide?
(Am using Firefox for dev, although I suspect this is about the OS and not about the browser.)
1 If anybody really needs the actual file data, I can paste a base64-encoded representation here. For now, I'm not going to the trouble.