javascript - firefox 不重启 Bootstrap 扩展脚本不重新加载

标签 javascript firefox firefox-addon firefox-addon-restartless

如果不重新启动 firefox,我无法在 firefox 扩展中反射(reflect)源代码修改。 我相信在使用引导方法时这应该是可能的。

这里是源代码:
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");

当我更改加载程序中的消息时,它不会反射(reflect)在 firefox(版本 30)中。我在配置文件扩展文件夹中有一个文件“goog@myself.com”,其中包含我的开发文件夹的路径。 当我从 about:extensions 页面启用/禁用或删除/撤消时,我对 loader.js 所做的更改不会反射(reflect)出来,除非我重新启动 firefox。 任何有关为什么代码未动态加载的指示都会有所帮助。

我对使用 SDK 进行开发不感兴趣。我还设置了各种标志,如 https://developer.mozilla.org/en-US/Add-ons/Setting_up_extension_development_environment 中所述。

编辑 1:

这是我用来测试场景的打包为 xpi(1.35KB) 的上述代码的链接。 https://www.dropbox.com/s/0io8b081ybu632q/test.xpi

编辑 2:

我的目标是加快开发过程,而不必为每次代码更改重新启动浏览器。这是一个相关的post , 但似乎是一个过时的。

最佳答案

AddonManager 或更具体地说是 XPIProvider 调用 flushStartupCache但仅在卸载附加组件时(包括在升级和降级期间)。但是,在 session 中禁用或启用加载项时不会清除缓存。

  • 要么在你的 bootstrap.js 中放置一个等价的方法,你在 shutdown 时调用(你应该在发布版本中这样做)。
  • 或者只是继续重申那个该死的浏览器。就我个人而言,我发现使用 "Restartless Restart" 重新启动会更快。附加键盘快捷键和在 about:addons 中漫游。

PS:我不能绝对确定这是唯一的问题,因为我无法测试您的东西,因为您没有提供完整、可重现的示例。

编辑 是的,确实,将以下内容添加到 shutdown 中就足够了,并且没有其他阻塞问题:

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

关于javascript - firefox 不重启 Bootstrap 扩展脚本不重新加载,我们在Stack Overflow上找到一个类似的问题: https://stackoverflow.com/questions/24711069/

相关文章:

html - 是否有使用 "multipart/mixed"内的 "multipart/form-data"上传文件的网络浏览器?

javascript - 在具有相关数据的 Jquery 数据表中打开弹出窗口不起作用

javascript - 受控状态设置为 false 后,Material-UI Snackbar 不会关闭

javascript - 在 Angular 中设置单选按钮默认值 - TypeError : Cannot read property 'x' of undefined'

firefox - 如何测量 Firefox 附加内存使用情况

javascript - 火狐插件 SDK : retrieving value from a different site based on clipboard content

firefox - 暂时禁用 Vimperator

javascript - 为什么 jquery position() 方法没有 setter 版本

javascript - 在 Angular 中从服务器下载文本/csv 内容作为文件在 Mozilla FireFox 中不起作用

javascript - 使用 Firefox 插件的 Javascript 捕获浏览器屏幕(完整且可见)