As reference here in order to read Clipboard text in a chrome extension, you have to:
- request "clipboardRead" permission in your manifest
- create a background script, since only the background script can access the clipboard
- create an element in your background page to accept the clipboard paste action. If you make this a textarea, you will get plain-text, if you make it a div with contentEditable=true, you will get Formatted HTML
- if you want to pass the clipboard data back to an in page script, you'll need to use the message-passing API
But this only works in manifest_version 2, because in manifest_version 3 you can not have a background script, but a service worker.
In this service worker you can not have normal functions, so I have a
chrome.runtime.onMessage.addListener
in this "manifest_version 3 service worker background.js script", and I invoke a message from my popup.html for example.
But then, the problem is that this service worker has no "document", so I can not create the textarea to do the trick of copying the contents there and call document.execCommand.
So ... is there any way to copy contents to clipBoard in Manifest Version 3 ?