I'm trying to use setInterval() within an extension developed with the firefox add-on sdk. Unfortunately, no matter how I call setInterval(), I keep getting the ReferenceError that setInterval is not defined.
I've simplified my code to illustrate the problem. The below code results in this error:
var globalTimer = 0;
function setGlobalTimer() {
globalTimer = setInterval(testFunction, 15000);
//globalTimer = setInterval(function() { testFunction(); }, 15000);
}
function testFunction() {
console.log("testFunction just called");
}
var { ToggleButton } = require("sdk/ui/button/toggle");
var button = ToggleButton({
id: "my-button",
label: "my button",
icon: {
"16": "./icon-16.png",
"32": "./icon-32.png",
"64": "./icon-64.png"
},
onClick: handleClick
});
function handleClick(state) {
testFunction();
setGlobalTimer();
}
Both ways of setting the global variable globalTimer in setGlobalTimer(), one way is commented out, result in the following error when I click on my toggle button in Firefox:
ReferenceError: setInterval is not defined
I've scanned the stackoverflow site for questions about setInterval() not working, and in other cases, using the calls I am using has worked. But this code generates the above error for me.
If anyone can help me with this problem I would greatly appreciate it.
Thanks in advance.