If I try to write some html into the clipboard using navigator.clipboard.write safari will change it a lot including stripping comments, and adding a bunch of random css properties. I store metadata in the comments so I'd really like them to not do that otherwise it breaks my in-app copy/paste mechanisms. Is there a way to copy html to the clipboard without safari changing it?
const html = "<!-- data in comment --><div>Some content</div>"
document.querySelector('button').addEventListener('click', function() {
navigator.clipboard.write([new ClipboardItem({
"text/html": new Blob([html], {type: "text/html"})
})])
})
https://codepen.io/msfeldstein/pen/jOwEXGw?editors=0010
Expected result:
<!-- data in comment --><div>Some content</div>
Result in chrome:
<meta charset='utf-8'><!-- data in comment --><div>Some content</div>
Result in safari:
<div style="caret-color: rgb(0, 0, 0); color: rgb(0, 0, 0); font-style: normal; font-variant-caps: normal; font-weight: normal; letter-spacing: normal; orphans: auto; text-align: start; text-indent: 0px; text-transform: none; white-space: normal; widows: auto; word-spacing: 0px; -webkit-text-size-adjust: auto; -webkit-text-stroke-width: 0px; text-decoration: none;">Some content</div>
Note that the comment is totally stripped out, and i need the data in there.