Change text copy to use fallback (#811)
This commit is contained in:
25
skyvern-frontend/src/util/copyText.ts
Normal file
25
skyvern-frontend/src/util/copyText.ts
Normal file
@@ -0,0 +1,25 @@
|
||||
/**
|
||||
* Progressively enhanced text copying
|
||||
* https://web.dev/patterns/clipboard/copy-text
|
||||
*/
|
||||
async function copyText(text: string): Promise<void> {
|
||||
if ("clipboard" in navigator) {
|
||||
return navigator.clipboard.writeText(text);
|
||||
} else {
|
||||
const textArea = document.createElement("textarea");
|
||||
textArea.value = text;
|
||||
textArea.style.opacity = "0";
|
||||
document.body.appendChild(textArea);
|
||||
textArea.focus();
|
||||
textArea.select();
|
||||
const success = document.execCommand("copy");
|
||||
document.body.removeChild(textArea);
|
||||
if (success) {
|
||||
return Promise.resolve();
|
||||
} else {
|
||||
return Promise.reject();
|
||||
}
|
||||
}
|
||||
}
|
||||
|
||||
export { copyText };
|
||||
Reference in New Issue
Block a user