Interact with the clipboard

You work with the clipboard in extensions using the Web API navigator.clipboard method and "clipboardRead" or "clipboardWrite" extension permissions. navigator.clipboard enables your extension to read and write arbitrary data from and to the clipboard.

Note: The Web API document.execCommand method was used to provide clipboard functionality. However, document.execCommand("copy"), document.execCommand("cut"), and document.execCommand("paste") are deprecated and no longer guaranteed to work or be available on any browser. These features are documented in this article for historical reference.

The navigator.clipboard API provides methods for:

Note: The Clipboard API write and read methods are only available in secure contexts. Your extension can't use them from a content script running on http: pages; they can only use them from https: pages.

Writing to the clipboard

The Clipboard API methods navigator.clipboard.write() and navigator.clipboard.writeText() write arbitrary content to the clipboard. The methods are available from a secure context but only function after the extension's user performs transient activation. However, with the "clipboardWrite" permission, transient activation isn't required.

Note: In Firefox and Chrome, the "clipboardWrite" permission enables writing to the clipboard from all extension contexts and content scripts. In Safari, the "clipboardWrite" permission is only supported in extension contexts (not content scripts).

This function takes a string and writes it to the clipboard:

js
function updateClipboard(newClip) {
  navigator.clipboard.writeText(newClip).then(
    () => {
      /* clipboard successfully set */
    },
    () => {
      /* clipboard write failed */
    },
  );
}

Using execCommand()

Note: document.execCommand("copy") and document.execCommand("cut") are deprecated and no longer guaranteed to work or be available on any browser.

The "cut" and "copy" commands of the document.execCommand() method are used to replace the clipboard's content with the selected material. Extensions can use these commands without special permission in short-lived event handlers triggered by user actions (for example, a click handler).

For example, suppose you've got a popup that includes this HTML:

html
<input id="input" type="text" /> <button id="copy">Copy</button>

To make the "copy" button copy the contents of the <input> element, you can use code like this:

js
function copy() {
  let copyText = document.querySelector("#input");
  copyText.select();
  document.execCommand("copy");
}

document.querySelector("#copy").addEventListener("click", copy);

Because the execCommand() call is inside a click event handler, your extension doesn't need special permissions.

However, take the example of your extension triggering the copy from an alarm:

js
function copy() {
  let copyText = document.querySelector("#input");
  copyText.select();
  document.execCommand("copy");
}

browser.alarms.create({
  delayInMinutes: 0.1,
});

browser.alarms.onAlarm.addListener(copy);

Depending on the browser, this may not work. On Firefox, it doesn't work, and you see a message like this in the console:

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

To enable this use case, your extension must request the "clipboardWrite" permission: "clipboardWrite" enables your extension to write to the clipboard outside a short-lived event handler for a user action.

Note: document.execCommand() doesn't work on input fields of type="hidden", with the HTML5 attribute "hidden", or any matching CSS rule using "display: none;". To add a "copy to clipboard" button to a span, div, or p tag, you need to use a workaround, such as setting the input's position to absolute and moving it out of the viewport.

Reading from the clipboard

The Clipboard API methods navigator.clipboard.read() and navigator.clipboard.readText() read arbitrary text or binary data from the clipboard. These methods allow extensions to access data in the clipboard without pasting it into an editable element.

The methods are available from a secure context but only function after the extension's user performs transient activation and clicks a paste prompt in an ephemeral context menu. However, with the "clipboardRead" permission, your extension can read from the clipboard without user confirmation or transient activation.

Note: In Firefox and Chrome, the "clipboardRead" permission enables writing to the clipboard from all extension contexts and content scripts. Safari doesn't support the "clipboardRead" permission.

This snippet of code fetches the text from the clipboard and replaces the contents of the element with the ID "outbox" with that text.

js
navigator.clipboard
  .readText()
  .then((clipText) => (document.getElementById("outbox").innerText = clipText));

Using execCommand()

Note: document.execCommand("paste") is deprecated and no longer guaranteed to work or be available on any browser.

To use document.execCommand("paste"), your extension needs the "clipboardRead" permission. This requirement exists even if you're using the "paste" command from within a user-generated event handler, such as click or keypress.

Consider HTML that includes this:

html
<textarea id="output"></textarea> <button id="paste">Paste</button>

To set the content of the <textarea> element with the ID "output" from the clipboard when the user clicks the "paste" <button>, you can use code like this:

js
function paste() {
  let pasteText = document.querySelector("#output");
  pasteText.focus();
  document.execCommand("paste");
  console.log(pasteText.textContent);
}
document.querySelector("#paste").addEventListener("click", paste);

Browser-specific considerations

In Chrome:

  • Chrome doesn't expose navigator.clipboard to extension service workers, and offscreen documents can't access navigator.clipboard due to the API's document focus requirements. As a result, Chrome extensions have to use the deprecated document.execCommand() APIs in an offscreen document or use navigator.clipboard in a different context, such as a content script or extension page. For page scripts to write to the clipboard without user interaction, the "clipboard-write" permission needs to be requested using the Web API navigator.permissions. Your extension can check for that permission using navigator.permissions.query():

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

    Note: The clipboard-write permission is not supported in Firefox or Safari.

In Firefox:

  • The availability of the Clipboard API read methods on the user's response to a paste prompt was introduced for web pages in Firefox 127 and extensions in Firefox 147. Before that, the methods were only available when the "clipboardRead" permission was set.

In Safari:

  • The "clipboardWrite" permission is only supported in extension contexts (not content scripts).
  • The "clipboardRead" permission isn't support.

Browser compatibility

api.Clipboard

desktop mobile
Chrome
Edge
Firefox
Opera
Safari
Chrome Android
Firefox for Android
Opera Android
Safari on iOS
Samsung Internet
WebView Android
WebView on iOS
Clipboard
Chrome – Full support
Chrome 66 (Release date: 2018-04-17)
footnote Full support
Edge – Full support
Edge 79 (Release date: 2020-01-15)
footnote Full support
Firefox – Full support
Firefox 63 (Release date: 2018-10-23)
footnote Full support
Opera – Full support
Opera 53 (Release date: 2018-05-10)
footnote Full support
Safari – Full support
Safari 13.1 (Release date: 2020-03-24)
footnote Full support
Chrome Android – Full support
Chrome Android 66 (Release date: 2018-04-17)
footnote Full support
Firefox for Android – Full support
Firefox for Android 63 (Release date: 2018-10-23)
footnote Full support
Opera Android – Full support
Opera Android 47 (Release date: 2018-07-23)
footnote Full support
Safari on iOS – Full support
Safari on iOS 13.4 (Release date: 2020-03-24)
footnote Full support
Samsung Internet – Full support
Samsung Internet 9 (Release date: 2018-09-15)
footnote Full support
WebView Android – Full support
WebView Android 66 (Release date: 2018-04-17)
footnote Full support
WebView on iOS – Full support
WebView on iOS 13.4 (Release date: 2020-03-24)
footnote Full support
clipboardchange event
Experimental
Chrome – Full support
Chrome 144 (Release date: 2026-01-13)
footnote
footnote From version 145, firing clipboardchange events requires sticky activation or the clipboard-read permission to be granted.
Edge – Full support
Edge 144 (Release date: 2026-01-21)
footnote
footnote From version 145, firing clipboardchange events requires sticky activation or the clipboard-read permission to be granted.
Firefox – No support
Firefox
footnote No support
Opera – Full support
Opera 128 (Release date: 2026-02-26)
footnote
footnote From version 129, firing clipboardchange events requires sticky activation or the clipboard-read permission to be granted.
Safari – No support
Safari
footnote No support
Chrome Android – Full support
Chrome Android 144 (Release date: 2026-01-13)
footnote
footnote From version 145, firing clipboardchange events requires sticky activation or the clipboard-read permission to be granted.
Firefox for Android – No support
Firefox for Android
footnote No support
Opera Android – Full support
Opera Android 95 (Release date: 2026-02-11)
footnote
footnote From version 96, firing clipboardchange events requires sticky activation or the clipboard-read permission to be granted.
Safari on iOS – No support
Safari on iOS
footnote No support
Samsung Internet – No support
Samsung Internet
footnote No support
WebView Android – No support
WebView Android
footnote No support
WebView on iOS – No support
WebView on iOS
footnote No support
read
Chrome – Full support
Chrome 76 (Release date: 2019-07-30)
footnote
footnote The user must grant the clipboard-read permission.
Edge – Full support
Edge 79 (Release date: 2020-01-15)
footnote
footnote The user must grant the clipboard-read permission.
Firefox – Full support
Firefox 127 (Release date: 2024-06-11)
footnote
footnote This method must be called within user gesture event handlers.
footnote A paste prompt is displayed when the clipboard is read. If the clipboard contains same-origin content, the prompt is suppressed.
footnote Web extensions with the clipboardRead permission in their manifest can read data without the paste prompt displaying. Prior to Firefox 147, extensions without this permission were unable to read clipboard data.
Opera – Full support
Opera 63 (Release date: 2019-08-20)
footnote
footnote The user must grant the clipboard-read permission.
Safari – Full support
Safari 13.1 (Release date: 2020-03-24)
footnote Full support
Chrome Android – Full support
Chrome Android 76 (Release date: 2019-07-30)
footnote
footnote The user must grant the clipboard-read permission.
Firefox for Android – Full support
Firefox for Android 127 (Release date: 2024-06-11)
footnote
footnote This method must be called within user gesture event handlers.
footnote A paste prompt is displayed when the clipboard is read. If the clipboard contains same-origin content, the prompt is suppressed.
footnote Web extensions with the clipboardRead permission in their manifest can read data without the paste prompt displaying. Prior to Firefox for Android 147, extensions without this permission were unable to read clipboard data.
Opera Android – Full support
Opera Android 54 (Release date: 2019-10-18)
footnote
footnote The user must grant the clipboard-read permission.
Safari on iOS – Full support
Safari on iOS 13.4 (Release date: 2020-03-24)
footnote Full support
Samsung Internet – Full support
Samsung Internet 12 (Release date: 2020-06-19)
footnote
footnote The user must grant the clipboard-read permission.
WebView Android – Full support
WebView Android 76 (Release date: 2019-07-30)
footnote
footnote The user must grant the clipboard-read permission.
WebView on iOS – Full support
WebView on iOS 13.4 (Release date: 2020-03-24)
footnote Full support
formats.unsanitized parameter
Experimental
Chrome – Full support
Chrome 122 (Release date: 2024-02-20)
footnote Full support
Edge – Full support
Edge 122 (Release date: 2024-02-23)
footnote Full support
Firefox – No support
Firefox
footnote No support
Opera – Full support
Opera 108 (Release date: 2024-03-05)
footnote Full support
Safari – No support
Safari
footnote No support
Chrome Android – Full support
Chrome Android 122 (Release date: 2024-02-20)
footnote Full support
Firefox for Android – No support
Firefox for Android
footnote No support
Opera Android – Full support
Opera Android 81 (Release date: 2024-03-14)
footnote Full support
Safari on iOS – No support
Safari on iOS
footnote No support
Samsung Internet – Full support
Samsung Internet 26 (Release date: 2024-06-07)
footnote Full support
WebView Android – Full support
WebView Android 122 (Release date: 2024-02-20)
footnote Full support
WebView on iOS – No support
WebView on iOS
footnote No support
readText
Chrome – Full support
Chrome 66 (Release date: 2018-04-17)
footnote
footnote The user must grant the clipboard-read permission.
Edge – Full support
Edge 79 (Release date: 2020-01-15)
footnote
footnote The user must grant the clipboard-read permission.
Firefox – Full support
Firefox 125 (Release date: 2024-04-16)
footnote
footnote This method must be called within user gesture event handlers.
footnote A paste prompt is displayed when the clipboard is read. If the clipboard contains same-origin content, the prompt is suppressed.
footnote Web extensions with the clipboardRead permission in their manifest can read data without the paste prompt displaying. Prior to Firefox 147, extensions without this permission were unable to read clipboard data.
Opera – Full support
Opera 53 (Release date: 2018-05-10)
footnote
footnote The user must grant the clipboard-read permission.
Safari – Full support
Safari 13.1 (Release date: 2020-03-24)
footnote Full support
Chrome Android – Full support
Chrome Android 66 (Release date: 2018-04-17)
footnote
footnote The user must grant the clipboard-read permission.
Firefox for Android – Full support
Firefox for Android 125 (Release date: 2024-04-16)
footnote
footnote This method must be called within user gesture event handlers.
footnote A paste prompt is displayed when the clipboard is read. If the clipboard contains same-origin content, the prompt is suppressed.
footnote Web extensions with the clipboardRead permission in their manifest can read data without the paste prompt displaying. Prior to Firefox for Android 147, extensions without this permission were unable to read clipboard data.
Opera Android – Full support
Opera Android 47 (Release date: 2018-07-23)
footnote
footnote The user must grant the clipboard-read permission.
Safari on iOS – Full support
Safari on iOS 13.4 (Release date: 2020-03-24)
footnote Full support
Samsung Internet – Full support
Samsung Internet 9 (Release date: 2018-09-15)
footnote
footnote The user must grant the clipboard-read permission.
WebView Android – Full support
WebView Android 66 (Release date: 2018-04-17)
footnote
footnote The user must grant the clipboard-read permission.
WebView on iOS – Full support
WebView on iOS 13.4 (Release date: 2020-03-24)
footnote Full support
Supports image/png MIME type
Chrome – Full support
Chrome 76 (Release date: 2019-07-30)
footnote Full support
Edge – Full support
Edge 79 (Release date: 2020-01-15)
footnote Full support
Firefox – Full support
Firefox 127 (Release date: 2024-06-11)
footnote Full support
Opera – Full support
Opera 63 (Release date: 2019-08-20)
footnote Full support
Safari – Full support
Safari 13.1 (Release date: 2020-03-24)
footnote Full support
Chrome Android – Full support
Chrome Android 76 (Release date: 2019-07-30)
footnote Full support
Firefox for Android – Full support
Firefox for Android 127 (Release date: 2024-06-11)
footnote Full support
Opera Android – Full support
Opera Android 54 (Release date: 2019-10-18)
footnote Full support
Safari on iOS – Full support
Safari on iOS 13.4 (Release date: 2020-03-24)
footnote Full support
Samsung Internet – Full support
Samsung Internet 12 (Release date: 2020-06-19)
footnote Full support
WebView Android – Full support
WebView Android 76 (Release date: 2019-07-30)
footnote Full support
WebView on iOS – Full support
WebView on iOS 13.4 (Release date: 2020-03-24)
footnote Full support
Supports text/html MIME type
Chrome – Full support
Chrome 86 (Release date: 2020-10-20)
footnote Full support
Edge – Full support
Edge 86 (Release date: 2020-10-09)
footnote Full support
Firefox – Full support
Firefox 127 (Release date: 2024-06-11)
footnote Full support
Opera – Full support
Opera 72 (Release date: 2020-10-21)
footnote Full support
Safari – Full support
Safari 13.1 (Release date: 2020-03-24)
footnote Full support
Chrome Android – Full support
Chrome Android 86 (Release date: 2020-10-20)
footnote Full support
Firefox for Android – Full support
Firefox for Android 127 (Release date: 2024-06-11)
footnote Full support
Opera Android – Full support
Opera Android 61 (Release date: 2020-12-07)
footnote Full support
Safari on iOS – Full support
Safari on iOS 13.4 (Release date: 2020-03-24)
footnote Full support
Samsung Internet – Full support
Samsung Internet 14 (Release date: 2021-04-17)
footnote Full support
WebView Android – Full support
WebView Android 86 (Release date: 2020-10-20)
footnote Full support
WebView on iOS – Full support
WebView on iOS 13.4 (Release date: 2020-03-24)
footnote Full support
Supports text/plain MIME type
Chrome – Full support
Chrome 76 (Release date: 2019-07-30)
footnote Full support
Edge – Full support
Edge 79 (Release date: 2020-01-15)
footnote Full support
Firefox – Full support
Firefox 127 (Release date: 2024-06-11)
footnote Full support
Opera – Full support
Opera 63 (Release date: 2019-08-20)
footnote Full support
Safari – Full support
Safari 13.1 (Release date: 2020-03-24)
footnote Full support
Chrome Android – Full support
Chrome Android 76 (Release date: 2019-07-30)
footnote Full support
Firefox for Android – Full support
Firefox for Android 127 (Release date: 2024-06-11)
footnote Full support
Opera Android – Full support
Opera Android 54 (Release date: 2019-10-18)
footnote Full support
Safari on iOS – Full support
Safari on iOS 13.4 (Release date: 2020-03-24)
footnote Full support
Samsung Internet – Full support
Samsung Internet 12 (Release date: 2020-06-19)
footnote Full support
WebView Android – Full support
WebView Android 76 (Release date: 2019-07-30)
footnote Full support
WebView on iOS – Full support
WebView on iOS 13.4 (Release date: 2020-03-24)
footnote Full support
write
Chrome – Full support
Chrome 76 (Release date: 2019-07-30)
footnote
footnote From version 107, this method must be called within user gesture event handlers, or the user must grant the clipboard-write permission.
footnote Before version 107, the user must grant the clipboard-write permission.
Edge – Full support
Edge 79 (Release date: 2020-01-15)
footnote Full support
Firefox – Full support
Firefox 127 (Release date: 2024-06-11)
footnote
footnote This method must be called within user gesture event handlers.
footnote Web extensions with the clipboardWrite permission in their manifest can write data without a user gesture.
Opera – Full support
Opera 63 (Release date: 2019-08-20)
footnote
footnote From version 93, this method must be called within user gesture event handlers, or the user must grant the clipboard-write permission.
footnote Before version 93, the user must grant the clipboard-write permission.
Safari – Full support
Safari 13.1 (Release date: 2020-03-24)
footnote Full support
Chrome Android – Full support
Chrome Android 76 (Release date: 2019-07-30)
footnote
footnote From version 107, this method must be called within user gesture event handlers, or the user must grant the clipboard-write permission.
footnote Before version 107, the user must grant the clipboard-write permission.
Firefox for Android – Full support
Firefox for Android 127 (Release date: 2024-06-11)
footnote
footnote This method must be called within user gesture event handlers.
footnote Web extensions with the clipboardWrite permission in their manifest can write data without a user gesture.
Opera Android – Full support
Opera Android 54 (Release date: 2019-10-18)
footnote
footnote From version 73, this method must be called within user gesture event handlers, or the user must grant the clipboard-write permission.
footnote Before version 73, the user must grant the clipboard-write permission.
Safari on iOS – Full support
Safari on iOS 13.4 (Release date: 2020-03-24)
footnote Full support
Samsung Internet – Full support
Samsung Internet 12 (Release date: 2020-06-19)
footnote
footnote From version 21.0, this method must be called within user gesture event handlers, or the user must grant the clipboard-write permission.
footnote Before version 21.0, the user must grant the clipboard-write permission.
WebView Android – Full support
WebView Android 76 (Release date: 2019-07-30)
footnote
footnote From version 107, this method must be called within user gesture event handlers, or the user must grant the clipboard-write permission.
footnote Before version 107, the user must grant the clipboard-write permission.
WebView on iOS – Full support
WebView on iOS 13.4 (Release date: 2020-03-24)
footnote Full support
writeText
Chrome – Full support
Chrome 66 (Release date: 2018-04-17)
footnote
footnote From version 107, this method must be called within user gesture event handlers, or the user must grant the clipboard-write permission.
footnote Before version 107, the user must grant the clipboard-write permission.
Edge – Full support
Edge 79 (Release date: 2020-01-15)
footnote
footnote From version 107, this method must be called within user gesture event handlers, or the user must grant the clipboard-write permission.
footnote Before version 107, the user must grant the clipboard-write permission.
Firefox – Full support
Firefox 63 (Release date: 2018-10-23)
footnote
footnote This method must be called within user gesture event handlers.
footnote Web extensions with the clipboardWrite permission in their manifest can write data without a user gesture.
Opera – Full support
Opera 53 (Release date: 2018-05-10)
footnote
footnote From version 93, this method must be called within user gesture event handlers, or the user must grant the clipboard-write permission.
footnote Before version 93, the user must grant the clipboard-write permission.
Safari – Full support
Safari 13.1 (Release date: 2020-03-24)
footnote
footnote This method must be called within user gesture event handlers.
Chrome Android – Full support
Chrome Android 66 (Release date: 2018-04-17)
footnote
footnote From version 107, this method must be called within user gesture event handlers, or the user must grant the clipboard-write permission.
footnote Before version 107, the user must grant the clipboard-write permission.
Firefox for Android – Full support
Firefox for Android 63 (Release date: 2018-10-23)
footnote
footnote This method must be called within user gesture event handlers.
footnote Web extensions with the clipboardWrite permission in their manifest can write data without a user gesture.
Opera Android – Full support
Opera Android 47 (Release date: 2018-07-23)
footnote
footnote From version 73, this method must be called within user gesture event handlers, or the user must grant the clipboard-write permission.
footnote Before version 73, the user must grant the clipboard-write permission.
Safari on iOS – Full support
Safari on iOS 13.4 (Release date: 2020-03-24)
footnote
footnote This method must be called within user gesture event handlers.
Samsung Internet – Full support
Samsung Internet 9 (Release date: 2018-09-15)
footnote
footnote From version 21.0, this method must be called within user gesture event handlers, or the user must grant the clipboard-write permission.
footnote Before version 21.0, the user must grant the clipboard-write permission.
WebView Android – Full support
WebView Android 66 (Release date: 2018-04-17)
footnote
footnote From version 107, this method must be called within user gesture event handlers, or the user must grant the clipboard-write permission.
footnote Before version 107, the user must grant the clipboard-write permission.
WebView on iOS – Full support
WebView on iOS 13.4 (Release date: 2020-03-24)
footnote
footnote This method must be called within user gesture event handlers.

Legend

Tip: you can click/tap on a cell for more information.

Full support
Full support
No support
No support
Experimental. Expect behavior to change in the future.
See implementation notes.

webextensions.api.clipboard

desktop mobile
Chrome
Edge
Firefox
Opera
Safari
Firefox for Android
Safari on iOS
clipboard
Chrome – No support
Chrome
footnote No support
Edge – No support
Edge
footnote No support
Firefox – Full support
Firefox 57 (Release date: 2017-11-14)
footnote Full support
Opera – No support
Opera
footnote No support
Safari – No support
Safari
footnote No support
Firefox for Android – Full support
Firefox for Android 57 (Release date: 2017-11-28)
footnote Full support
Safari on iOS – No support
Safari on iOS
footnote No support
setImageData
Chrome – No support
Chrome
footnote No support
Edge – No support
Edge
footnote No support
Firefox – Full support
Firefox 57 (Release date: 2017-11-14)
footnote Full support
Opera – No support
Opera
footnote No support
Safari – No support
Safari
footnote No support
Firefox for Android – No support
Firefox for Android
footnote
footnote Method is defined but always rejects with an error.
Safari on iOS – No support
Safari on iOS
footnote No support

Legend

Tip: you can click/tap on a cell for more information.

Full support
Full support
No support
No support
See implementation notes.

See also