0

I have to make a small modification on a legacy addon built in Addon SDK that's why I am not using webextension. I am trying to make a background script that should be running in the background as long as the addon is installed. I have an HTML panel and there is a script that is attached to it. But the panel's script runs only when the button is clicked. I tried to make another panel and attach the background script to it simply as:

var panels = require("sdk/panel");
var backgroundPanel = panels.Panel({
    contentScriptFile: "./background.js"
});

But the background.js never runs. How to run a script on the background automatically as long as the addon is installed without the need to be triggered?

user7945230
  • 1,075
  • 2
  • 13
  • 20

1 Answers1

1

The code you have already shown, commonly placed in a file called index.js, is already executed when the add-on is added to Firefox (i.e. upon add-on installation and when Firefox loads the add-on each time Firefox starts up) and will be executing until Firefox closes. It is already your background script.

Makyen
  • 31,849
  • 12
  • 86
  • 121
  • Thanks. Is it possible to run multiple files as background? – user7945230 Jun 06 '17 at 20:00
  • Yes, through multiple methods. The recommended method is: [Creating Reusable Modules](https://developer.mozilla.org/en-US/Add-ons/SDK/Tutorials/Creating_reusable_modules) – Makyen Jun 06 '17 at 20:40