/webext-domain-permission-toggle

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

Primary LanguageTypeScriptMIT LicenseMIT

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

Context menu

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

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

Install

You can just download the standalone bundle (it might take a minute to download) and include the file in your manifest.json, or:

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": [
		"http://*/*",
		"https://*/*"
	],
	"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: 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

Permissions

Others

License

MIT © Federico Brigante