How can i fix notallowederror when copying to clipboard in Firefox?
#1
I'm trying to implement a simple feature where a user can click a button to copy some text from a div to their clipboard. I wrote the function using `navigator.clipboard.writeText()`, and it works perfectly in Chrome, but in Firefox I just get a "NotAllowedError" without any prompt. I'm not sure if my permissions are wrong or if I need a completely different approach for cross-browser support.
Reply
#2
Yeah, this is a Firefox quirk. navigator.clipboard.writeText often dies with NotAllowedError if the call isn’t in a real user gesture on a secure page. I saw it happen when I fired it from a small delay after the click.
Reply
#3
I added a fallback: drop the text into a hidden textarea and call document.execCommand('copy'). Firefox accepted that and it still works after a user click, even though the Clipboard API was choking.
Reply
#4
It felt like a permissions thing but there was no prompt, just the error. I started to suspect the problem was timing or the environment more than the code.
Reply
#5
Are you testing on HTTPS and actually triggering the copy from a real click handler?
Reply


[-]
Quick Reply
Message
Type your reply to this message here.

Image Verification
Please enter the text contained within the image into the text box below it. This process is used to prevent automated spam bots.
Image Verification
(case insensitive)

Forum Jump: