Couldn't copy to clipboard

Hi,
Am developing a firefox web extension and facing issues with copying to clipboard.

On clicking a button, I copy a text to clipboard and this is working. On timeout, I have to clear the clipboard, so I will copy an empty string to clipboard.

Now the issue is, when I use document.execCommand(‘copy’) inside setTimeout, am getting the following error

> document.execCommand(‘cut’/‘copy’) was denied because it was not called from inside a short running user-generated event handler.

I have added clipboardWrite and clipboardRead permissions in manifest.json. And still facing the issue.

Can someone help me with this? Thanks in advance.

So, you copy a string to the clipboard and then clear it? Assuming this string is read elsewhere, have you tried clearing the clipboard right after the string is read?