我从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);
最佳答案
Firefox 45中引入了一个错误,该错误打破了quit-application-granted
,负责通知观察者(例如插件或
脚本),表明浏览器即将关闭。
它应该固定在48以上。有关更多信息,请参见:
https://bugzilla.mozilla.org/show_bug.cgi?id=1269859
https://bugzilla.mozilla.org/show_bug.cgi?id=1284687
修正了变更集:
我们在关闭窗户之前要改善关机状态
表现,但我们最终陷入一种可能会错过的状态
每个会话中大多数标签的会话活动的最后〜2秒
窗口。这是因为我们正在删除会话更新
消息侦听器并解决刷新承诺
向窗口触发了domwindowclosed通知。
隐藏窗口可让我们正确等待消息。
而且,之后我们甚至没有收集窗口状态
我们已经脸红了,所以我们一直很想念(最糟糕的是
情况),每个窗口大约2秒钟的会话状态。这个地址
那。
– Bug 1284687 - Hide windows on shutdown while persisting session instead of closing them
关于javascript - Javascript Firefox重新启动,我们在Stack Overflow上找到一个类似的问题:https://stackoverflow.com/questions/36878005/