Explore Bato Web Agency Webflow Certified Partner Profile Explore Bato Web Agency Webflow Certified Partner Profile

Clipboard writeText() failed because the document is not focused

Illustration without a description Illustration without a description

The clipboard write ran when the document did not have focus. Check whether the call was delayed, the user switched tabs or the handler waited for another operation before writing. Clipboard requirements can also depend on the browser and its activation rules.

 

Call writeText() from the user’s action on the focused, secure page and catch rejection. If the content can be prepared beforehand, make it available when the user presses Copy. Give the user a way to retry when the request cannot complete.

 

document.querySelector('#copy')?.addEventListener('click', async () => { if (!document.hasFocus()) return; try { await navigator.clipboard.writeText('Copied text'); } catch (error) { console.warn('Copy not permitted', error.name); } });

 

A focus check is only a snapshot, so keep the rejection handler as well. Test both the normal click and the sequence that caused focus to move.

 

Test Copy while the page is focused, then repeat after deliberately moving focus to confirm the failure is handled.