mirror of
https://github.com/windmill-labs/windmill.git
synced 2026-08-21 08:02:26 +00:00
fix(frontend): fix copyToClipboard on non-HTTPS site (#2046)
This commit is contained in:
@@ -341,12 +341,30 @@ export async function copyToClipboard(value?: string, sendToast = true): Promise
|
||||
}
|
||||
|
||||
let success = false
|
||||
if (navigator?.clipboard) {
|
||||
if (navigator?.clipboard && window.isSecureContext) {
|
||||
success = await navigator.clipboard
|
||||
.writeText(value)
|
||||
.then(() => true)
|
||||
.catch(() => false)
|
||||
} else {
|
||||
const textArea = document.createElement("textarea");
|
||||
textArea.value = value;
|
||||
textArea.style.position = "fixed";
|
||||
textArea.style.left = "-999999px";
|
||||
|
||||
document.body.appendChild(textArea);
|
||||
textArea.select();
|
||||
|
||||
try {
|
||||
document.execCommand('copy');
|
||||
success = true;
|
||||
} catch (error) {
|
||||
// ignore (success = false)
|
||||
} finally {
|
||||
textArea.remove();
|
||||
}
|
||||
}
|
||||
|
||||
sendToast &&
|
||||
sendUserToast(success ? 'Copied to clipboard!' : "Couldn't copy to clipboard", !success)
|
||||
return success
|
||||
|
||||
Reference in New Issue
Block a user