Javascript Copy to clipboard functionality #4779
Closed
kelemenattila
started this conversation in
General
Replies: 1 comment 1 reply
-
By default permission to cliipboard should be disabled. You can grant permissions programmatically.
chromiumWebBrowser.PermissionHandler = new MyPermissionHandler();` |
Beta Was this translation helpful? Give feedback.
1 reply
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment
Uh oh!
There was an error while loading. Please reload this page.
-
I need to copy custom formatted data in javascript to clipboard using ChromiumBrowser.
I'm adding the text to the clipboard with the following JS code:
navigator.clipboard.writeText(formattedText);
In case of ChromiumBrowser the text doesn't appear in clipboard. In case of other browsers (Chrome, Brave, Edge) works.
I got a workaround with creating a ghost element copy content with document.execCommand('copy'), works but 1/10 doesn't only if I debug the JS code step by step. By the way execCommand is obsolete :(
I attached the full workarround code but I prefer to use somehow the navigator to copy to clipboard if it is possible.
Thanks :)
const element = document.createElement('textarea');
element.value = formattedText;
document.body.appendChild(element);
element.select();
document.execCommand('copy');
document.body.removeChild(element);
Beta Was this translation helpful? Give feedback.
All reactions