firefox restartless bootstrap extension script not reloading

喜夏-厌秋 提交于 2019-12-13 01:27:53

问题


I am unable to get a source code modification reflected in the firefox extension without restarting firefox. I believe this should be possible when using the bootstrap approach.

Here is the source code:
bootstrap.js

var GOOGBAR_MODULES = [ "resource://googbar/loader.js"];

function startup(params, reason)
{

    var res = Services.io.getProtocolHandler("resource").QueryInterface(Ci.nsIResProtocolHandler);
    var modulesURI = Services.io.newURI(__SCRIPT_URI_SPEC__ + "/../content/", null, null);
    res.setSubstitution("googbar", modulesURI);
    Cu.import("resource://googbar/loader.js");
} 


function shutdown(params, reason)
{ 
    // Unload all modules added with Cu.import
    GOOGBAR_MODULES.forEach(Cu.unload, Cu);

    // Clear our resource registration
    var res = Services.io.getProtocolHandler("resource").QueryInterface(Ci.nsIResProtocolHandler);
    res.setSubstitution("googbar", null);

}

loader.js

console.log("googbar loader loaded");

when i change the message in the loader, it doesnt get reflected in firefox (version 30). I have a file "goog@myself.com" in the profile extensions folder which contains the path to my development folder. The changes I made to loader.js doesnt reflect when I enable/disable or remove/undo from the about:extensions page, unless i restart firefox. Any pointers to why the code is not loading dynamically would be helpful.

I am not interested in using the SDK for development. I have also set various flags as described in https://developer.mozilla.org/en-US/Add-ons/Setting_up_extension_development_environment

EDIT 1:

Here is a link to above code packaged as an xpi(1.35KB) i am using to test the scenario. https://www.dropbox.com/s/0io8b081ybu632q/test.xpi

EDIT 2:

My goal is to speed up the development process without having to restart the browser for every code change. Here is a related post, but seems to be an outdated one.


回答1:


The AddonManager or more specifically the XPIProvider calls flushStartupCache but only when the add-on is uninstalled (incl. during up- and downgrades). However, the cache is not cleared when disabling or enabling an add-on in-session.

  • Either put an equivalent method in your bootstrap.js that you call when shutdown (you should do this in release versions).
  • Or just continue restating that damn browser. Personally I find it faster to just restart with the "Restartless Restart" add-on keyboard shortcut and roaming around in about:addons.

PS: I can not be absolutely sure this is the only issue at play, since I cannot test your stuff, since you didn't provide a full, reproducible example.

Edit Yes, indeed, adding the following to shutdown is sufficient and there are no other blocking issues:

if (reason == ADDON_DISABLE) {
  Services.obs.notifyObservers(null, "startupcache-invalidate", null);
}


来源:https://stackoverflow.com/questions/24711069/firefox-restartless-bootstrap-extension-script-not-reloading

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