Files
webextensions-examples/export-helpers/content_scripts/export.js
wbamberg b269b12a61 Add an example of how to use export helpers in content scripts (#86)
* Added example of using export helpers

* stop using wrapedJSObject with exportFunction; remove createObjectIn

* Updated for review comments

* Fix content_scripts 'matches' property
2017-10-23 16:21:24 -07:00

26 lines
726 B
JavaScript

/**
* Define a function in the content script's scope, then export it
* into the page script's scope.
*/
function notify(message) {
browser.runtime.sendMessage({content: "Function call: " + message});
}
exportFunction(notify, window, {defineAs:'notify'});
/**
* Create an object that contains functions in the content script's scope,
* then clone it into the page script's scope.
*
* Because the object contains functions, the cloneInto call must include
* the `cloneFunctions` option.
*/
var messenger = {
notify: function(message) {
browser.runtime.sendMessage({content: "Object method call: " + message});
}
};
window.wrappedJSObject.messenger = cloneInto(messenger, window, {cloneFunctions: true});