Get clipboard type in Electron

Viewed 1477

I'm using GitHub's Electron to build a desktop app. I want to grab the type of the current clipboard contents in order to better use it (eg. if it's HTML then I want to do something different than if it's just text).

Looking at the docs there's no way to check the type, but type is required to properly read it. Is there an easy way to get the type?

Relevant docs.

2 Answers

Install mime-types to electron, see: https://www.npmjs.com/package/mime-types

then add this to your class

let mime = require('mime-types');

then get mimetype by using this

let mimetype = mime.lookup(*here is file path*)
Related