问题
I want to add a file(background.js) which is a background script for my firefox extension. I added content scripts to my main.js using the following code.
var panel = panels.Panel({
contentURL: self.data.url("panel.html"),
onHide: handleHide,
contentScriptFile: [self.data.url("js/jquery.js"),
self.data.url("tipsy/jquery.tipsy.js"),,
self.data.url("js/settings.js")]
});
How do I add background scripts to the main.js file.
回答1:
Simply place the file in the lib
folder.
Except for scripts that interact directly with web content, all the JavaScript code you'll write or use when developing add-ons using the SDK is part of a CommonJS module.
Essentially, backend script don't share variables like content scripts/normal JS. You export
and require
variables between modules.
See adding local modules
来源:https://stackoverflow.com/questions/27243403/adding-background-scripts-to-a-firefox-add-on