Search code examples
javascriptfirefox

navigator.clipboard.readText() is not working in Firefox


I have this code for paste:

navigator.clipboard.readText().then(
  clipText => document.querySelector("#Note").innerText += clipText);

But it returns this error:

Uncaught TypeError: navigator.clipboard.readText is not a function


Solution

  • Reading clipboard on Firefox (version 94, nov 2021) doesn't seem to work and throws an error:

    var promise = navigator.clipboard.readText();
    
    // Uncaught TypeError: navigator.clipboard.readText is not a function
    

    Documentation on MDN Web Docs suggests to grant permission via Permission API:

    The "clipboard-read" permission of the Permissions API must be granted before you can read data from the clipboard.

    But clipboard-read doesnt seem to be supported:

    navigator.permissions.query({ name: "clipboard-read" });
    
    // Uncaught TypeError: 'clipboard-read' is not a valid value for enumeration PermissionName.
    

    The only way to enable clipboard reading (and writing) is to enable dom.events.testing.asyncClipboard on Firefox client:

    1. Enter about:config in navigation bar
    2. Click "Accept the Risk and Continue"
    3. Search dom.events.testing.asyncClipboard and set true