-
Notifications
You must be signed in to change notification settings - Fork 2
Expand file tree
/
Copy pathoffscreen.js
More file actions
39 lines (34 loc) · 1.03 KB
/
offscreen.js
File metadata and controls
39 lines (34 loc) · 1.03 KB
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
/**
* SuperTables - Offscreen Document for Clipboard Operations
* Required for clipboard access in Manifest V3
*/
// Listen for messages from the service worker
chrome.runtime.onMessage.addListener((message, sender, sendResponse) => {
if (message.target !== 'offscreen') return;
if (message.action === 'copy') {
handleCopy(message.text)
.then(() => sendResponse({ success: true }))
.catch((err) => sendResponse({ success: false, error: err.message }));
return true; // Keep channel open for async response
}
});
/**
* Copy text to clipboard
*/
async function handleCopy(text) {
// Try using Clipboard API first
try {
await navigator.clipboard.writeText(text);
return;
} catch (e) {
// Clipboard API failed, try execCommand fallback
}
// Fallback: use execCommand
const textarea = document.getElementById('clipboard-textarea');
textarea.value = text;
textarea.select();
const success = document.execCommand('copy');
if (!success) {
throw new Error('execCommand copy failed');
}
}