Clipboard

Read and write content from and to the clipboard.

System requirements

Please make sure your local environment uses the following application versions before proceeding.

data-variant=info
data-slots=header, text1, text2
Plugins and Scripts
In plugins, you should seek permission for clipboard access in the manifest. IMPORTANT: Read about the manifest permissions before you proceed.
In scripts, the permission for clipboard is fixed. You can ignore the manifest details in the following examples. Learn about these values in the manifest fundamentals section.

Example

data-slots=heading, code
data-repeat=2
data-languages=JavaScript, JSON

JavaScript

async function foo() {
    const clipboard = navigator.clipboard;

    // Setting content for clipboard
    clipboard.setContent({ 'text/plain': "Test string to validate clipboard setContent" })
        .then(() => {
            console.log("Data successfully set on clipboard");
        }, (error) => {
            console.error("Error while setting data on clipboard:", error);
        });


    // Reading from clipboard and printing
    clipboard.getContent()
        .then((result) => {
            console.log(`Data from clipboard: ${result["text/plain"]}`);
        }, (error) => {
            console.error("Error while reading data from clipboard:", error);
        });
}

manifest

{
    "requiredPermissions": {
        "clipboard": "readAndWrite"
    }
}

Additional notes

Reference material