diff --git a/WasmSite/main.js b/WasmSite/main.js index 6f63029..a14cbbd 100644 --- a/WasmSite/main.js +++ b/WasmSite/main.js @@ -523,18 +523,14 @@ async function copyRunLog() { if (!text) { return; } - if ("clipboard" in navigator && window.isSecureContext) { - await navigator.clipboard.writeText(text); - } else { - const textarea = document.createElement("textarea"); - textarea.value = text; - textarea.setAttribute("readonly", ""); - textarea.style.position = "fixed"; - textarea.style.opacity = "0"; - document.body.append(textarea); - textarea.select(); - document.execCommand("copy"); - textarea.remove(); + try { + if ("clipboard" in navigator && window.isSecureContext) { + await navigator.clipboard.writeText(text); + } else { + copyTextWithTextarea(text); + } + } catch { + copyTextWithTextarea(text); } const previousLabel = copyRunLogButton.textContent; copyRunLogButton.textContent = "Copied"; @@ -543,6 +539,18 @@ async function copyRunLog() { }, 1500); } +function copyTextWithTextarea(text) { + const textarea = document.createElement("textarea"); + textarea.value = text; + textarea.setAttribute("readonly", ""); + textarea.style.position = "fixed"; + textarea.style.opacity = "0"; + document.body.append(textarea); + textarea.select(); + document.execCommand("copy"); + textarea.remove(); +} + function resetStreamDocument(message) { streamDocumentElement.replaceChildren(document.createTextNode(message)); streamDocumentElement.scrollTop = 0;