mirror of
https://github.com/mdn/webextensions-examples.git
synced 2026-04-16 14:28:33 +02:00
* Replace var with let in examples store-collected-images/webextension-plain/deps/uuidv4.js * Reverted third–party code
26 lines
726 B
JavaScript
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.
|
|
*/
|
|
let messenger = {
|
|
notify: function(message) {
|
|
browser.runtime.sendMessage({content: "Object method call: " + message});
|
|
}
|
|
};
|
|
|
|
window.wrappedJSObject.messenger = cloneInto(messenger, window, {cloneFunctions: true});
|