Firefox重新启动引导扩展脚本不重新加载 [英] firefox restartless bootstrap extension script not reloading
问题描述
我无法在不重新启动firefox的情况下获得反映在Firefox扩展中的源代码修改。
我相信这应该是可能的,当使用bootstrap方法。
以下是源代码:
bootstrap.js
var GOOGBAR_MODULES = [resource://googbar/loader.js];
函数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);
函数关闭(params,reason)
{
//卸载所有添加了Cu.import
的模块GOOGBAR_MODULES.forEach (Cu.unload,Cu);
//清除资源注册
var res = Services.io.getProtocolHandler(resource)。QueryInterface(Ci.nsIResProtocolHandler);
res.setSubstitution(googbar,null);
$ b
loader.js p>
console.log(googbar loader loaded);
当我在加载器中更改消息时,它并不反映在firefox(版本30)中。我在配置文件扩展名文件夹中有一个文件goog@myself.com,其中包含我的开发文件夹的路径。
我对loader.js所做的更改并不反映何时启用/禁用或从about:extensions页面移除/撤消,除非我重新启动firefox。
动态加载代码的任何指针都会有帮助。
我对使用SDK进行开发并不感兴趣。我还设置了各种标志,如 https://developer.mozilla.org / zh-CN / Add-ons / Setting_up_extension_development_environment
编辑1:
这里是上面的代码打包为一个xpi(1.35KB)的链接,我正在使用测试场景。 https://www.dropbox.com/s/0io8b081ybu632q/test.xpi
我的目标是加快开发进程而不必为每个代码更改重新启动浏览器。这是一个相关的帖子,但似乎是一个过时的一个。
AddonManager
或更具体地说 XPIProvider
调用 flushStartupCache
,但仅在卸载附件时(包括升级和降级期间)。但是,在禁用或启用会话中的附加组件时,缓存不会被清除。 - 要么在您的
shutdown
(您应该在发行版本中执行此操作)时调用c $ c> bootstrap.js 。 - 或者继续重申那个该死的浏览器。就个人而言,我发现使用无重启重启在键盘快捷方式和周围漫游:附加。
$ b $我不能确定这是唯一的问题,因为我不能测试你的东西,因为你没有提供一个完整的,可重现的例子。
编辑是,确实,加入以下关闭是足够的,没有其他阻塞问题:
$ $ p $if(reason == ADDON_DISABLE){
Services.obs.notifyObservers(null,startupcache-invalidate,null);
}
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.jsvar 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.
解决方案The
AddonManager
or more specifically theXPIProvider
callsflushStartupCache
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 whenshutdown
(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); }
这篇关于Firefox重新启动引导扩展脚本不重新加载的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!
- Either put an equivalent method in your