I'm building an extension Firefox that can access to clipboard without user interaction.
While testing my plugin from about:debugging in Firefox 118.0.1, I can see a Read and Change Data notification like this:
I notice this happen when I have any permission on my manifest.json:
"permissions": [
"activeTab",
"clipboardWrite",
"clipboardRead"
],
How to allow clipboard copy and paste on all context?
I'm OK to be transparent like ask once on install but not requesting on every website.
This notification occurs because a content.js is used and requires data permission in the page (activeTab).
This was expected when the extension was installed using manifest V2, but now in manifest v3 it is necessary to ask the user for permission when user performing an action such as a click.
Here's how to do it:
manifest.json:
-------------
"manifest_version": 3,
...
"content_scripts": [
{
"matches": [
"<all_urls>"
],
"js": [
"content.js"
]
}
],
"permissions": [
"contextMenus"
],
"optional_permissions": [
"activeTab"
]
background.js:
--------------
async function requestPermissions() {
const permissionsToRequest = {
permissions: ["activeTab"],
origins: ["<all_urls>"]
}
await browser.permissions.request(permissionsToRequest);
}
// click right handler
browser.contextMenus.onClicked.addListener(async (info, tab) => {
requestPermissions();
...
});