zenorocha / clipboard.js

:scissors: Modern copy to clipboard. No Flash. Just 3kb gzipped :clipboard:
https://clipboardjs.com
MIT License
33.98k stars 3.98k forks source link

Doesn't work properly in Safari 16.5.1 #856

Closed dentalala closed 2 months ago

dentalala commented 1 year ago

For some reason I cannot explain, copying is not working properly in Safari 16.5.1, but is perfectly fine in Firefox. It doesn't look like there's something wrong with JavaScript execution in this browser, and I don't have any weird experimental features enabled. But Clipboard.js seems to empty clipboard instead of copying a string in Safari.

https://urbanpsychopaths.com ↑ See “Website Link” at the bottom right block

xmaxiy commented 1 year ago

Apple changed their behaviour and permissions to write text into the clipboard (maybe it's a bug from Apple? Don't know). It only works as a blob because the clipboard needs a promise. You can write a fallback function for JS, like: if (navigator.clipboard && navigator.clipboard.write) { var data = [new ClipboardItem({ "text/plain": Promise.resolve(new Blob(["Copy Text"], { type: 'text/plain' })) })]; navigator.clipboard.write(data).then(function () { //function }, function (e) { console.log(e); }); }

Hopefully this getting fixed soon.

MHKzxb commented 1 year ago

我和你碰到了同样的问题,测试后删除一个css可以解决: -webkit-user-select:none;

xmaxiy commented 1 year ago

我和你碰到了同样的问题,测试后删除一个css可以解决: -webkit-user-select:none;

Doesn't work for me. The text is still not in the clipboard.

ciaoben commented 10 months ago

我和你碰到了同样的问题,测试后删除一个css可以解决: -webkit-user-select:none;

I confirm that checking that the container of the text you are copying does not have this line fix the problem.

obetomuniz commented 2 months ago

Hey @dentalala, I'm planning to contribute to some open issues. Can you confirm if your problem remains? For now, it seems not related to clipboard.js, so closing. If that's not the case, soon I will be triaging so we can investigate in deep, and potentially, find a fix. So feel free to reopen it if that's the case.