Empresas
Empleos
  • Sobre nosotros
  • Soluciones
    • Publicación de vacantes
      Publica tu vacante y recibe candidatos calificados en 48h.
    • Evaluación de candidatos
      500+ pruebas técnicas y psicológicas, más anti-fraude.
    • Headhunting
      Búsqueda ejecutiva a la medida de principio a fin.
    • Nómina + EOR
      Dispersión de nómina y EOR en más de 15 países de LATAM.
  • Precios
  • Empleos

0

201
Vistas
Dragging text data out of browser onto desktop results in file with extra non-ASCII garbage

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)

Exported binary data

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.

about 4 years ago · Juan Pablo Isaza
Responde la pregunta
Encuentra empleos remotos

¡Descubre la nueva forma de encontrar empleo!

Top de empleos
Top categorías de empleo
Empresas
Publicar vacante Precios Comercial
Legal
Términos y condiciones Política de privacidad
© 2026 PeakU Inc. All Rights Reserved.
Andres GPT
Recomiéndame algunas ofertas
Necesito ayuda