/webext-domain-permission-toggle

Browser-action context menu to request permission for the current tab.

Primary LanguageJavaScript

webext-domain-permission-toggle Travis build status npm version

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

Install

npm install webext-domain-permission-toggle

manifest.json

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

webpack, rollup, browserify

// background.js
import DPT from 'webext-domain-permission-toggle';

Usage

DPT.addContextMenu();

API

DPT.addContextMenu([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: Do you want to reload this page to apply ${extensionName}?

If the user accepts the new permission, they will be asked to reload the current tab. Set a string to customize the message and false to avoid the reload and its request.

Related

License

MIT © Federico Brigante — Twitter