From aded1037942803aeaece9b3c658a45ad2c483cd9 Mon Sep 17 00:00:00 2001 From: Mihaela Mihaljevic Date: Sun, 7 Jun 2026 01:13:58 +0200 Subject: [PATCH] fix: make run log copy fallback reliable --- WasmSite/main.js | 32 ++++++++++++++++++++------------ 1 file changed, 20 insertions(+), 12 deletions(-) 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;