Adding background scripts to a firefox add-on

放肆的年华 提交于 2020-01-03 19:32:15

问题


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

易学教程内所有资源均来自网络或用户发布的内容,如有违反法律规定的内容欢迎反馈
该文章没有解决你所遇到的问题?点击提问,说说你的问题,让更多的人一起探讨吧!