OpenNIT-Vault-Extension/extension/offscreen.js
2026-07-01 18:26:57 +02:00

17 lines
No EOL
633 B
JavaScript

'use strict';
chrome.runtime.onMessage.addListener((msg) => {
if (!msg || msg.target !== 'offscreen') return;
if (msg.type === 'CLIP_WRITE') {
const text = msg.text || '';
// Bevorzugt die Clipboard-API; Fallback über execCommand.
Promise.resolve()
.then(() => navigator.clipboard.writeText(text))
.catch(() => {
const ta = document.getElementById('t');
ta.value = text || ' ';
ta.select();
try { document.execCommand('copy'); } catch (e) { /* ignore */ }
ta.value = '';
});
}
});