如何向 Firefox 插件添加循环计时器?
我正在尝试使用新的插件构建器预览 (https://builder.addons.mozilla.org/) 创建一个插件,并且我需要一个大约每 10 分钟运行一次的函数。我尝试过 setInterval 和 setTimeout,但它们都返回以下错误:(
error: An exception occurred.
Traceback (most recent call last):
File "resource://jid0-31njasqk3btmpa6paroepuybjn4-myaddon-lib/main.js", line 41, in
setTimeout(function() { timedCount(); }, 10000);
ReferenceError: setTimeout is not defined
当我尝试时,setTimeout 被 setInterval 替换。setTimeout 函数在我构建的类似网页中工作得很好。我只是让函数调用本身给出无限循环(听起来很愚蠢,应该有一个 while 循环,但它是在教程中;) 但现在我无法克服插件中的错误。
另外,如果你可以帮助我解析这个插件中的本地或远程页面(最好是远程的,但我可以让它解析本地主机上的 django 创建的页面),或者更好,只需告诉我如何使用 python ;)会很棒的。
谢谢!
I am trying to create an addon with the new addons builder preview (https://builder.addons.mozilla.org/), and I need a function to run about once every 10 minutes. I have tried both setInterval and setTimeout, but they both return the following error:
error: An exception occurred.
Traceback (most recent call last):
File "resource://jid0-31njasqk3btmpa6paroepuybjn4-myaddon-lib/main.js", line 41, in
setTimeout(function() { timedCount(); }, 10000);
ReferenceError: setTimeout is not defined
(with setTimeout being replaced with setInterval when I tried it. The setTimeout function worked great in the similar webpage that I built. I just had the function call itself to give an infinite loop (It sounds stupid, there should be a while loop, but it was in a tutorial;)
But now I can't get past that error in my addon.
Also, if you can help me parse a local or remote page in this addon (preferably remote, but I could make it parse a django-created page on localhost instead), or even better, just tell me how to use python ;) that would be great.
Thanks!
如果你对这篇内容有疑问,欢迎到本站社区发帖提问 参与讨论,获取更多帮助,或者扫码二维码加入 Web 技术交流群。
绑定邮箱获取回复消息
由于您还没有绑定你的真实邮箱,如果其他用户或者作者回复了您的评论,将不能在第一时间通知您!
发布评论
评论(3)
请注意,上面的内容已被弃用
,现在已使用
please note that the above is deprecated
is now used instead
使用计时器模块:
Use the timer module:
使用
nsITimer
:https://developer.mozilla.org /en-US/docs/XPCOM_Interface_Reference/nsITimer它不需要您使用不必要的 Jetpack SDK,以及额外的
require
功能;您可以像在 Mozilla 插件中进行其他 XPCOM 交互一样使用Components.classes
。Use
nsITimer
: https://developer.mozilla.org/en-US/docs/XPCOM_Interface_Reference/nsITimerIt doesn't require you to use the unnecessary Jetpack SDK, and the extra
require
function; you can useComponents.classes
like you do for other XPCOM interaction within Mozilla addons.