Skip to content

Privacy-first password manager with built-in email aliasing. Fully encrypted and self-hostable.

Make clipboard clear work for mv3 and mv2 browsers (#881)

Leendert de Borst7054593c0744
diff --git a/apps/browser-extension/public/offscreen.js b/apps/browser-extension/public/offscreen.js
index 461adfc9b..c6ceeb4a3 100644
--- a/apps/browser-extension/public/offscreen.js
+++ b/apps/browser-extension/public/offscreen.js
@@ -28,7 +28,7 @@ async function clearClipboard() {
try {
// Use execCommand to clear clipboard
console.log(textEl);
- textEl.value = '\u200B'; // Zero-width space
+ textEl.value = '\n';
textEl.select();
console.log(textEl.value);
document.execCommand('copy');
diff --git a/apps/browser-extension/src/entrypoints/background.ts b/apps/browser-extension/src/entrypoints/background.ts
index 6b645f705..ce437f051 100644
--- a/apps/browser-extension/src/entrypoints/background.ts
+++ b/apps/browser-extension/src/entrypoints/background.ts
@@ -158,9 +158,11 @@ async function createOffscreenDocument(): Promise<void> {
* Clear clipboard using offscreen document or fallback method.
*/
async function clearClipboardContent(): Promise<void> {
- // Try to use offscreen document if available (Chrome 109+)
- if (chrome.offscreen) {
- // Ensure offscreen document exists
+ if (import.meta.env.CHROME || import.meta.env.EDGE) {
+ /*
+ * Chrome and Edge use mv3 and do not have direct access to clipboard
+ * so we use an offscreen document to clear the clipboard.
+ */
await createOffscreenDocument();
// Send message to offscreen document to clear clipboard
@@ -172,8 +174,8 @@ async function clearClipboardContent(): Promise<void> {
throw new Error(response?.message || 'Failed to clear clipboard via offscreen');
}
} else {
- // Fallback: try direct clipboard access (may not work in service worker)
- await navigator.clipboard.writeText(' ');
+ // Firefox and Safari use mv2 and do not have offscreen document support, use direct clipboard access.
+ await navigator.clipboard.writeText('');
}
}