chrome.runtime.sendMessage({ type: "theme", dark: matchMedia("(prefers-color-scheme: dark)").matches, }); chrome.runtime.onMessage.addListener( ({ type, text }, _sender, sendResponse) => { if (type !== "copy") return; const textarea = document.createElement("textarea"); textarea.value = text; document.body.append(textarea); textarea.select(); document.execCommand("copy"); textarea.remove(); sendResponse(); }, );