简体   繁体   中英

How to copy text from a chrome extension using Async Clipboard API

I feel like I might be missing something simple. I am trying to get a text from the clipboard using the Async Clipboard Api but for the same strange reason, the operation is failing without any error messages.

I have a simple script that gets a text from the clipboard and then logs to console.

navigator.clipboard.readText()
    .then(data => {
        console.log('Text copied to clipboard', data);
    }).catch(err => {
    console.error("error copying text", err);
});

This fails with the message error copying text undefined .

In my manifest, I have requested the clipboardRead permission

  "permissions": [
    "clipboardRead"
  ]

What am I doing wrong?

Please see this Chromium bug where this issue is tracked. For a workaround that tried to use the new API and falls back to the legacy API, please see this example .

The technical post webpages of this site follow the CC BY-SA 4.0 protocol. If you need to reprint, please indicate the site URL or the original address.Any question please contact:yoyou2525@163.com.

 
粤ICP备18138465号  © 2020-2024 STACKOOM.COM