Not a member of Pastebin yet?
Sign Up,
it unlocks many cool features!
- /***** manifest.json *****/
- {
- "manifest_version": 3,
- "name": "Clipboard Alert",
- "version": "1.0",
- "description": "Shows the current clipboard contents in an alert.",
- "permissions": [
- "activeTab",
- "scripting",
- "clipboardRead"
- ],
- "background": {
- "scripts": [
- "background.js"
- ]
- },
- "action": {
- "default_title": "Show Clipboard"
- }
- }
- /***** background.js *****/
- browser.action.onClicked.addListener(async (tab) => {
- if (!tab.id) return;
- try {
- await browser.scripting.executeScript({
- target: { tabId: tab.id },
- func: async () => {
- try {
- const text = await navigator.clipboard.readText();
- alert("Clipboard contents:\n\n" + text);
- } catch (err) {
- alert("Failed to read clipboard:\n" + err);
- }
- }
- });
- } catch (e) {
- console.error("Script injection failed:", e);
- }
- });
Advertisement
Add Comment
Please, Sign In to add comment