Switched from deprecated document.execCommand to the clipboard API#175
Switched from deprecated document.execCommand to the clipboard API#175volovikariel wants to merge 1 commit intoMoustachauve:masterfrom
Conversation
|
I tested it on Chrome v120.0.6099.131 and IE v116.0.1938.62. Works as expected! |
|
doesn't work in the devtools tab: |
|
@warren-bank can you please share the website/element that you were trying to copy text from? |
|
@volovikariel any website.. the error happens when trying to export cookies to the clipboard from within devtools.. I can't remember if I was testing in Chrome or FF when I encountered the error. To make it easy to reproduce, I can tell you that v2.0.4 of my fork will have this issue.. it was released immediately after merging this PR but before noticing this problem in devtools. I'm testing now.. will let you know which browsers are effected.. results are in.. it does work in Firefox.. it does not work in Chrome. PS: adding the manifest permission |
|
@warren-bank I do not understand how I can reproduce this issue. Could you please help me understand? |
Flawlesslyjuulz1
left a comment
There was a problem hiding this comment.
Only change if it's beneficial and positive for the next phase
Flawlesslyjuulz1
left a comment
There was a problem hiding this comment.
- const fakeText = document.createElement('textarea');
- fakeText.classList.add('clipboardCopier');
- fakeText.textContent = text;
- document.body.appendChild(fakeText);
- fakeText.focus();
- fakeText.select();
- // TODO: switch to clipboard API.
- document.execCommand('Copy');
- document.body.removeChild(fakeText);
- navigator.clipboard.writeText(text);
I have not been able to test this on any browsers other than Firefox, but I'd expect it to work because the API seems to be supported on all major browsers.
Let me know if I'm missing anything 👍