Using the new Clipboard API I can easily read out the current content as text (sample code) and the API looks like it could support multiple 'types', but at least in Chrome and Edge it always only returns text/plain
. Is this a bug/limitation in the new API, or should I do my call differently?
Full example how to trigger this behavior
Note: make sure to copy rich text content beforehand. (This is not a snippet as the new clipboard API doesn't seem to work in iframes)
<!DOCTYPE html>
<html>
<head> </head>
<body>
<div contenteditable>
paste into this area for old api
</div>
<button id="async">async api</button>
<script>
document.querySelector("#async").addEventListener("click", (e) => {
navigator.permissions
.query({ name: "clipboard-read" })
.then((result) => {
// If permission to read the clipboard is granted or if the user will
// be prompted to allow it, we proceed.
if (result.state == "granted" || result.state == "prompt") {
navigator.clipboard.read().then((data) => {
console.log(data.map((d) => d.types)); // always returns only [['text/plain']]
});
}
});
});
document.querySelector("div").addEventListener("paste", (e) => {
console.log(e.clipboardData.types); // returns for the same content ["text/plain", "text/html"]
});
</script>
</body>
</html>