How to detect firefox start-up event in firefox extension?

I'm creating an Firefox extension which is required to load a list of regular expression from a certain URL. But, if this called every time user load a page, it will be too painful for the server. So, I want the program to run once every time a user is starting Firefox.

I've found this solution:

How to detect first loading of NPAPI plugin/Extension in firefox and chrome

But it has a downside. If the Firefox starts with multiple tabs, it will not work (gBrowser.browsers.length don't have "1" as value).

So, what should I do?

Upvotes: 1

Views: 231

Answers (1)

willlma
willlma

Reputation: 7533

Where did you read that extension code is executed every time a user loads a page? By default, extension code on Firefox only runs on

  • install
  • enable
  • startup
  • upgrade
  • downgrade

So, just make the request in main.js and you should be fine.

If you really want the list to only load on startup (which doesn't sound like what you would actually want), then add the line

if (require("sdk/self").loadReason==='startup') loadRegexs()

Upvotes: 2

Related Questions