Javascript: Querying clipboard permissions on Firefox does not work

I'm trying to modify the content of the clipboard by executing the "copy" command on a focused DOM element. However, the new content comes from the server, and arrives from a websocket, which is then processed in a callback that does not come from direct user interaction.

Because it wasn't triggered by the user, it is not allowed to do such thing as modifying the clipboard content, as specified in the Firefox's MDM website . The error message is:

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

To overcome this issue, the same page suggest to request permissions to the browser throught navigator.permissions.query():

navigator.permissions.query({name: "clipboard-write"}).then(result => {
  if (result.state == "granted" || result.state == "prompt") {
    /* write to the clipboard now */

However, thought the article they use different names for the permissions:

  • clipboard-write
  • clipboard-read
  • clipboardWrite
  • clipboardRead

Within the same site, the permissions article shows a browser compatibility table , where it says Firefox supports clipboardWrite from version 51 and clipboardRead from version 54.

The problem is that none of these permissions is working on Firefox (I'm using Firefox 63). The query callback is never called. I have tried the four permission names without any luck.

To make sure the mechanism was working, I tested other permissions, such as notifications which worked flawlessly (It showed "prompt")

navigator.permissions.query({name: "notifications"}).then(result => {

So my question is: Am I doing something wrong when requesting the permissions, or have this permissions changed whatsoever?



Recent Questions

Top Questions

Home Tags Terms of Service Privacy Policy DMCA Contact Us

©2020 All rights reserved.