3

How to correctly restart firefox (without any "restore session" things and with the same windows as before) from code?

I know pid of "firefox-bin" in a bash script process and I have my custom plugin loaded into it.

Vi.
  • 37,014
  • 18
  • 93
  • 148

1 Answers1

4
Services.prefs.setBoolPref("browser.sessionstore.resume_session_once", true);
const nsIAppStartup = Components.interfaces.nsIAppStartup;
Components.classes["@mozilla.org/toolkit/app-startup;1"]
          .getService(nsIAppStartup)
          .quit(nsIAppStartup.eRestart | nsIAppStartup.eAttemptQuit);

Note that this applies to Firefox 4 so the code might be slightly different for earlier versions.

Neil
  • 54,642
  • 8
  • 60
  • 72
  • Based on `chrome://browser/content/aboutRestartRequired.js` read from Firefox Nightly 106.0a1 (2022-09-05) (64-bit), all is needed is `Services.startup.quit(Ci.nsIAppStartup.eRestart | Ci.nsIAppStartup.eAttemptQuit)`. However, I was able to restart Firefox only when `chrome://browser/content/aboutRestartRequired.js` was open in a tab, in that tab I open web onsole and run the command. In other tabs, `Services` and `Ci are not defined. Does anyone know how to get an instance of `Services` and `Ci`? Thanks! – tukusejssirs Sep 05 '22 at 09:22
  • @tukusejssirs This is chrome code, so you need to open the Browser Console, not the Web Console. – Neil Sep 05 '22 at 10:51
  • how can I run a JS command in Browser console? And if the chrome code can’t be run in Web Console, how is it possible to run it _in Web Console_ when I open `chrome://browser/content/aboutRestartRequired.js`? – tukusejssirs Sep 05 '22 at 14:05
  • @tukusejssirs For your first question, I think you need to Enable browser chrome and add-on debugging toolboxes (in the web console preferences) first. – Neil Sep 05 '22 at 15:47
  • @tukusejssirs For your second question, this is expected behaviour for any `chrome://browser/content/` page; the Browser Console itself inspects `chrome://browser/content/browser.xhtml`. – Neil Sep 05 '22 at 15:49