diff --git a/node-api/public/index.html b/node-api/public/index.html
index b2e61ec..7025b8b 100644
--- a/node-api/public/index.html
+++ b/node-api/public/index.html
@@ -106,11 +106,29 @@ btnClear.addEventListener('click', async () => {
});
btnCopy.addEventListener('click', async () => {
+ const text = JSON.stringify(history, null, 2);
try {
- await navigator.clipboard.writeText(JSON.stringify(history, null, 2));
+ async function copyText(t) {
+ if (navigator.clipboard && navigator.clipboard.writeText) {
+ return navigator.clipboard.writeText(t);
+ }
+ const ta = document.createElement('textarea');
+ ta.value = t;
+ ta.style.position = 'fixed';
+ ta.style.opacity = '0';
+ ta.setAttribute('readonly', '');
+ document.body.appendChild(ta);
+ ta.focus();
+ ta.select();
+ ta.setSelectionRange(0, ta.value.length);
+ const ok = document.execCommand('copy');
+ document.body.removeChild(ta);
+ if (!ok) throw new Error('copy command failed');
+ }
+ await copyText(text);
alert('Copiado al portapapeles');
} catch (e) {
- alert('No se pudo copiar: ' + e.message);
+ alert('No se pudo copiar: ' + (e && e.message ? e.message : e));
}
});