feat: Enhance copyTriggerWord function with modern clipboard API and fallback for non-secure contexts. Fixes https://github.com/willmiao/ComfyUI-Lora-Manager/issues/110

This commit is contained in:
Will Miao
2025-04-18 14:56:27 +08:00
parent be8605d8c6
commit fafbafa5e1

View File

@@ -336,7 +336,22 @@ async function saveTriggerWords() {
*/
window.copyTriggerWord = async function(word) {
try {
await navigator.clipboard.writeText(word);
// Modern clipboard API - with fallback for non-secure contexts
if (navigator.clipboard && window.isSecureContext) {
await navigator.clipboard.writeText(word);
} else {
// Fallback for older browsers or non-secure contexts
const textarea = document.createElement('textarea');
textarea.value = word;
textarea.style.position = 'absolute';
textarea.style.left = '-99999px';
document.body.appendChild(textarea);
textarea.select();
const success = document.execCommand('copy');
document.body.removeChild(textarea);
if (!success) throw new Error('Copy command failed');
}
showToast('Trigger word copied', 'success');
} catch (err) {
console.error('Copy failed:', err);