首页
学习
活动
专区
圈层
工具
发布
社区首页 >问答首页 >Javascript Firefox重启

Javascript Firefox重启
EN

Stack Overflow用户
提问于 2016-04-27 08:10:35
回答 1查看 282关注 0票数 1

我从Firefox 38升级到46,这个脚本不能正常工作,这意味着它应该关闭并重新启动Firefox,但升级后它只会关闭。

代码语言:javascript
复制
const nsIAppStartup = Components.interfaces.nsIAppStartup;

// Notify all windows that an application quit has been requested.
var os = Components.classes["@mozilla.org/observer-service;1"]
    .getService(Components.interfaces.nsIObserverService);
var cancelQuit = Components.classes["@mozilla.org/supports-PRBool;1"]
    .createInstance(Components.interfaces.nsISupportsPRBool);
os.notifyObservers(cancelQuit, "quit-application-requested", null);

// Something aborted the quit process. 
if (cancelQuit.data)
    return;

// Notify all windows that an application quit has been granted.
os.notifyObservers(null, "quit-application-granted", null);

// Enumerate all windows and call shutdown handlers
var wm = Components.classes["@mozilla.org/appshell/window-mediator;1"]
    .getService(Components.interfaces.nsIWindowMediator);
var windows = wm.getEnumerator(null);
while (windows.hasMoreElements()) {
    var win = windows.getNext();
    if (("tryToClose" in win) && !win.tryToClose())
        return;
}
Components.classes["@mozilla.org/toolkit/app-startup;1"].getService(nsIAppStartup)
    .quit(nsIAppStartup.eRestart | nsIAppStartup.eAttemptQuit);
EN

回答 1

Stack Overflow用户

发布于 2016-07-30 07:24:50

Firefox45中引入了一个错误,破坏了quit-application-granted的一些使用,负责通知观察者(例如插件或脚本)浏览器将关闭。

它应该在48和更高版本中修复。详情请参考:

带有修复的Changeset:

我们以前关闭窗口是为了提高感知到的关闭性能,但最终我们可能会错过每个窗口的大多数选项卡的最后~2秒的会话活动。这是因为我们删除了会话更新消息侦听器,并在为窗口触发domwindowclosed通知后解决了刷新承诺。

隐藏窗口可以让我们正确地等待消息。

更重要的是,我们甚至没有在刷新后收集窗口状态,所以我们总是丢失(在最坏的情况下)每个窗口大约2秒的会话状态。这就解决了这个问题。

-- Bug 1284687 - Hide windows on shutdown while persisting session instead of closing them

票数 0
EN
页面原文内容由Stack Overflow提供。腾讯云小微IT领域专用引擎提供翻译支持
原文链接:

https://stackoverflow.com/questions/36878005

复制
相关文章

相似问题

领券
问题归档专栏文章快讯文章归档关键词归档开发者手册归档开发者手册 Section 归档