我从Firefox 38升级到46,这个脚本不能正常工作,这意味着它应该关闭并重新启动Firefox,但升级后它只会关闭。
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);发布于 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
https://stackoverflow.com/questions/36878005
复制相似问题