1.0.0 • Published 6 years ago
alias-extension v1.0.0
Alias-Extension
Execute functions remotely in different contexts of your extension.
Install
npm install --save alias-extensionGet started
An example of the execution of functions from content in the context of background.
content.js:
import { createAliases } from 'alias-extension';
const aliases = {
FOO: 'foo'
}
const { foo } = createAliases(aliases);
foo();background.js:
import { executeAliases } from 'alias-extension';
const aliases = {
FOO: () => {
console.log('bar');
return 'foo';
}
}
executeAliases(aliases);Calling the foo function from the content script will cause FOO alias to be executed in the background script. The call will return the value returned from FOO alias.
API
createAliases(aliases, options)
aliasesan object in which the key is the name of the alias and the key is the name of the function to call the alias.options:senderName- sender identifier string.extensionId- id of the extension to which alias will be sent.toActiveTab- iftruethen alias will be sent to the content script of the active page.tabId- sends alias for the content script of the page with the specified id.sendOptions- options for sendMessage.bashowBrowserError- if true, when an error occurs, the console will also display an error generated by the browser.activeTabNotOptimized- by default, the id for sending alias for the content script of the active page is calculated only once for eachcreateAliases. Set this flag totrueso that the id of the active page is calculated each time alias is executed.
createAliasesToTab(aliases, options)
A wrapper for the createAliases function which sets the toActiveTab flag if tabId is not passed or == false.
executeAliases(aliases, options)
aliasesan object in which the key is the name of the alias and the value of the function that is executed when this alias is executed.options:senderName- string or array of strings. If this parameter is specified, aliases will be executed only if thesenderNameof the sender aliases matches thesenderNameof the executor or is contained in thesenderNamearray of the executing aliases.tabsOnly- iftrueonly aliases from content scripts are executed.excludeTabs- iftruethen aliases from content scripts are ignored.extensionId- checks the extension id of the sending alias to match the one specified in the parameter.
executeTabAliases(aliases, options)
Wrapper for the executeAliases function with set tabsOnly: true and excludeTabs: false.
License
1.0.0
6 years ago