fix: HTTP fallback for clipboard — execCommand('copy') textarea method

- Added copyToClipboard() in utils.js with dual strategy:
  - HTTPS: navigator.clipboard.writeText() (modern API)
  - HTTP: textarea + execCommand('copy') (legacy fallback)
- viewer.js: uses copyToClipboard() instead of direct navigator.clipboard
- popout.html: same dual-strategy inline
- Fixed: 'Erreur lors de la copie' on HTTP contexts
This commit is contained in:
2026-07-25 10:32:39 -04:00
parent 15a217eca4
commit 5426022273
3 changed files with 52 additions and 7 deletions
+31 -1
View File
@@ -650,4 +650,34 @@ function initEditor() {
);
}
export { getFileIcon, safeCreateIcons, flushIcons, safeHighlight, escapeHtml, EXT_ICONS, openEditor, closeEditor, saveFile, deleteFile, waitForCodeMirror, initEditor };
function safeHighlight(block) {
try { hljs.highlightElement(block); } catch (e) { /* skip */ }
}
/** Copy text to clipboard — works on both HTTP and HTTPS */
function copyToClipboard(text) {
// Try modern API first (HTTPS-only)
if (navigator.clipboard && window.isSecureContext) {
navigator.clipboard.writeText(text).catch(() => {});
return true;
}
// Fallback for HTTP contexts
const ta = document.createElement("textarea");
ta.value = text;
ta.style.position = "fixed";
ta.style.left = "-9999px";
ta.style.top = "-9999px";
document.body.appendChild(ta);
ta.focus();
ta.select();
try {
document.execCommand("copy");
return true;
} catch (e) {
return false;
} finally {
document.body.removeChild(ta);
}
}
export { getFileIcon, safeCreateIcons, flushIcons, safeHighlight, escapeHtml, EXT_ICONS, openEditor, closeEditor, saveFile, deleteFile, waitForCodeMirror, initEditor, copyToClipboard };