How can I add a recurring timer to a Firefox addon?

前端 未结 3 1055
南方客
南方客 2021-01-06 05:37

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 tr

相关标签:
3条回答
  • 2021-01-06 06:06

    Use nsITimer: https://developer.mozilla.org/en-US/docs/XPCOM_Interface_Reference/nsITimer

    It doesn't require you to use the unnecessary Jetpack SDK, and the extra require function; you can use Components.classes like you do for other XPCOM interaction within Mozilla addons.

    0 讨论(0)
  • 2021-01-06 06:12

    Use the timer module:

    var tmr = require('timer');
    tmr.setInterval(timedCount, 10000); // no need for an anon function since you don't pass any arguments to your function nor capture anything in a closure
    
    0 讨论(0)
  • 2021-01-06 06:26

    please note that the above is deprecated

    var tmr = require('sdk/timers');
    

    is now used instead

    0 讨论(0)
提交回复
热议问题