/    Sign up×
Community /Pin to ProfileBookmark

Maddening ReferenceError

Greetings!

I have a question which surrounds the use of .js in the context of the Firefox autoconfig scripting scheme. I don’t script every day, so I do hope my question isn’t too basic for the audience.

At any rate, here’s the code context which is showing up in various forms on the Browser Console:

(function() {
setInterval(toggle, 1000);
function toggle() {
… do something …
}
})();

When FF is launched, the console returns: “ReferenceError: setInterval is not defined”

Not to be dissuaded, I tried:

(function() {
window.setInterval(toggle, 1000);
function toggle() {
… do something …
}
})();

…and got back at the next run: “ReferenceError: window is not defined”

Sensing where this might be heading, I took a poke with:

(function() {
var t = window.setInterval(toggle, 1000);
function toggle() {
… do something …
}
})();

…and was reminded: “ReferenceError: window is not defined”

Finally, I tried:

(function() {
var t = setInterval(toggle, 1000);
function toggle() {
… do something …
}
})();

…and watched FF stick its tongue out at me again with: “ReferenceError: setInterval is not defined”

Of relevant note, this runs just fine:

(function() {
toggle();
function toggle() {
… do something …
}
})();

So, that’s my tale of woe in a nutshell…

Any help getting setInterval() to run as expected here is greatly appreciated 😉

Thanks!

to post a comment
JavaScript

4 Comments(s)

Copy linkTweet thisAlerts:
@daveyerwinJul 14.2020 — Firefox autoconfig does not

run in the browser environment

so no access to window object .

https://support.mozilla.org/en-US/kb/customizing-firefox-using-autoconfig#w_functions-of-autoconfig
Copy linkTweet thisAlerts:
@last2knowauthorJul 14.2020 — Thanks, DavyErwin, for the "heads up".

I do confess to being quite surprised here, as I was under a different impression about the nature and scope of these scripts.

Any input as to how one might get a "setInterval()" type of timer-like functionality in this code context?

Thanks again --
Copy linkTweet thisAlerts:
@daveyerwinJul 14.2020 — https://support.mozilla.org/en-US/kb/customizing-firefox-using-autoconfig#w_setting-up-autoconfig
Copy linkTweet thisAlerts:
@last2knowauthorJul 15.2020 — Fixed, per this:

https://developer.mozilla.org/en-US/docs/Mozilla/JavaScript_code_modules/Timer.jsm

...via this:

https://developer.mozilla.org/en-US/docs/Mozilla/JavaScript_code_modules

Target code:

Components.utils.import("resource://gre/modules/Timer.jsm");

Cheers!
×

Success!

Help @last2know spread the word by sharing this article on Twitter...

Tweet This
Sign in
Forgot password?
Sign in with TwitchSign in with GithubCreate Account
about: ({
version: 0.1.9 BETA 4.25,
whats_new: community page,
up_next: more Davinci•003 tasks,
coming_soon: events calendar,
social: @webDeveloperHQ
});

legal: ({
terms: of use,
privacy: policy
});
changelog: (
version: 0.1.9,
notes: added community page

version: 0.1.8,
notes: added Davinci•003

version: 0.1.7,
notes: upvote answers to bounties

version: 0.1.6,
notes: article editor refresh
)...
recent_tips: (
tipper: @Yussuf4331,
tipped: article
amount: 1000 SATS,

tipper: @darkwebsites540,
tipped: article
amount: 10 SATS,

tipper: @Samric24,
tipped: article
amount: 1000 SATS,
)...