Why am I encountering difficulties accessing custom functions with the Firefox Addon SDK?
In the code snippet provided below, whenever I click on context menu Sub Item 1, it does not work as intended; It is trying to access the custom function verifyTest()
but instead throws a ReferenceError: verifyTest is undefined. On the other hand, clicking Sub Item 2 which calls the built-in function alert()
works perfectly fine.
I have also attempted using self.postMessage (and onMessage) without any luck. What steps should I take in order to successfully access (or define) my custom functions that are essential for my addon to function correctly?
///// Content in main.js
function verifyTest() {
alert('test1');
}
var script1 = 'self.on("click", function(node, data){'+
' verifyTest();'+
'});';
var script2 = 'self.on("click", function(){'+
' alert(\'test2\');'+
'});';
var cm = require("sdk/context-menu");
cm.Menu({
label: "Main Item",
context: cm.SelectorContext("body"),
items: [
cm.Item({ label: "Sub Item 1", context: cm.SelectorContext("input[type=text]"), contentScript: script1, data: "item1" }),
cm.Item({ label: "Sub Item 2", context: cm.SelectorContext("input[type=text]"), contentScript: script2, data: "item2" })
]
});