webext-domain-permission-toggle

Browser-action context menu to request permission for the current tab. Chrome, Firefox, Safari.

Usage no npm install needed!

<script type="module">
  import webextDomainPermissionToggle from 'https://cdn.skypack.dev/webext-domain-permission-toggle';
</script>

README

webext-domain-permission-toggle npm version

Context menu

WebExtension module: Browser-action context menu to request permission for the current tab. Chrome, Firefox, Safari.

Works great when paired with webext-dynamic-content-scripts if you want to also inject content scripts on the new domains.

This repository even includes a customizable guide to tell your users how to use it. At the bottom of that page, you'll find a link that lets you customize it with your extension’s name and icon. You can link your users to it directly, it's a permalink.

Install

You can download the standalone bundle and include it in your manifest.json.

Or use npm:

npm install webext-domain-permission-toggle
import addDomainPermissionToggle from 'webext-domain-permission-toggle';

Usage

// In background.js
addDomainPermissionToggle();

manifest.json

{
    "browser_action": { /* Firefox support */
        "default_icon": "icon.png"
    },
    "permissions": [
        "contextMenus",
        "activeTab"
    ],
    "optional_permissions": [
        "*://*/*"
    ],
    "background": {
        "scripts": [
            "webext-domain-permission-toggle.js",
            "background.js"
        ]
    }
}

API

addDomainPermissionToggle([options])

Context menu

Adds an item to the browser action icon's context menu (as shown in the screenshot).

The user can access this menu by right clicking the icon. If your extension doesn't have any action or popup assigned to the icon, it will also appear with a left click.

options

title

Type: string

Default: 'Enable ${extensionName} on this domain'

The title of the action in the context menu.

reloadOnSuccess
Reload confirmation message

Type: boolean string

Default: false

If true or string, when the user accepts the new permission, they will be asked to reload the current tab. Set a string to customize the message or true use the default message: Do you want to reload this page to apply ${extensionName}?

Related

Permissions

Others

License

MIT © Federico Brigante