fix: make run log copy fallback reliable

This commit is contained in:
Mihaela Mihaljevic 2026-06-07 01:13:58 +02:00
parent 442e84d94a
commit aded103794

View File

@ -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;