当前位置: 动力学知识库 > 问答 > 编程问答 >

javascript - Firefox Add-on SDK reload extension only upon restart

问题描述:

I'm currently having an issue with an extension I'm developing using the Firefox Add-on SDK. For some basic context, the extension executes content scripts using the page-mod api in the sdk. On each of the content scripts some additional javascript is injected into the page itself (we'll call them page scripts). In order to do some complex tasks, the javascript injected into the page can communicate with the content script and which will then in turn make requests to the background process of the extension. Due to the complexity of the extension, when it is auto-updated, it is possible to get into a state where multiple page-scripts running the same code are running on the given content-script.

What I'm wondering is if it's possible for extensions built using the Add-on SDK can be forced to update itself only upon restart. This would mean that the extension won't get reloaded even if the auto-update occurs until a user restarts their Firefox Browser.

If this is not possible, any other solutions would be great.

网友答案:

Though I agree with @Noitidart's comment, you can choose to inject your content scripts from main.js only on restart like so:

const { loadReason } = require('sdk/self');
if (loadReason==='startup') {
  //Inject the scripts
}

You'll have to make sure that your old version's content scripts can communicate with the new background scripts without breaking, which will be a pain to test. See here for the other load reasons.

分享给朋友:
您可能感兴趣的文章:
随机阅读: