Skip to content

Instantly share code, notes, and snippets.

@Sporif
Last active October 3, 2022 18:27
Show Gist options
  • Star 7 You must be signed in to star a gist
  • Fork 3 You must be signed in to fork a gist
  • Save Sporif/ad6e917d87787491538bac80d3c8918c to your computer and use it in GitHub Desktop.
Save Sporif/ad6e917d87787491538bac80d3c8918c to your computer and use it in GitHub Desktop.
Restart Button for Firefox. An updated version of https://github.com/Endor8/userChrome.js/tree/master/restartfirefoxbutton_movable. Middle click also empties the script cache.
(function() {
if (location != 'chrome://browser/content/browser.xul' && location != 'chrome://browser/content/browser.xhtml')
return;
try {
CustomizableUI.createWidget({
id: 'restart-button',
type: 'custom',
defaultArea: CustomizableUI.AREA_NAVBAR,
onBuild: function(aDocument) {
var toolbaritem = aDocument.createElementNS('http://www.mozilla.org/keymaster/gatekeeper/there.is.only.xul', 'toolbarbutton');
toolbaritem.onclick = event => onClick(event);
var props = {
id: 'restart-button',
class: 'toolbarbutton-1 chromeclass-toolbar-additional',
label: 'Restart',
tooltiptext: 'Restart (with middle click userChrome.js cache is emptied)',
style: 'list-style-image: url(chrome://browser/skin/sync.svg)'
};
for(var p in props)
toolbaritem.setAttribute(p, props[p]);
return toolbaritem;
}
});
} catch(e) {};
function onClick(event) {
if(event.button == 1)
Services.appinfo.invalidateCachesOnRestart();
else if(event.button == 2)
return;
let cancelQuit = Cc["@mozilla.org/supports-PRBool;1"].createInstance(Ci.nsISupportsPRBool);
Services.obs.notifyObservers(cancelQuit, "quit-application-requested", "restart");
if(!cancelQuit.data)
Services.startup.quit(Services.startup.eAttemptQuit | Services.startup.eRestart);
}
})();
@intika
Copy link

intika commented Nov 24, 2018

One simple solution is to bookmark "about:profiles" ... when restart is needed open that page and click "normal restart"

capture
...

@rpolo77
Copy link

rpolo77 commented Dec 4, 2019

button stopped showing up in firefox 72

@siffegh
Copy link

siffegh commented Dec 5, 2019

Confirmed; it had stopped appearing in Nightly too.

@Sporif
Copy link
Author

Sporif commented Dec 5, 2019

@siffegh @rpolo77 Firefox 72 removed support for XBL, so the userchromejs method for injecting scripts found here or here no longer works.

@siffegh
Copy link

siffegh commented Dec 6, 2019

:-( Got any more magic tricks? FF sure is antagonizing lots of users with their ridiculous restrictions lately.

@you74674
Copy link

@siffegh
Copy link

siffegh commented Dec 14, 2019

If only I knew what I need from there, and how to implement it :-(

@rpolo77
Copy link

rpolo77 commented Dec 14, 2019

Save config.js to Firefox installation folder, next to firefox.exe
Save config-prefs.js into \defaults\pref inside Firefox installation folder, next to channel-prefs.js
Save userChrome.js into Firefox chrome folder, next to userChrome.css
and it works

@siffegh
Copy link

siffegh commented Dec 16, 2019

and it works

Yes - yes, it does :-) Thanks for the help, @rpolo77 and @you74674.

@Beckfield
Copy link

Beckfield commented Jan 24, 2020

The solution provided by you74674, and the instructions from rpolo77, works great on Windows. I tried saving the same files in the equivalent locations (hopefully) on my Linux MInt system, but it doesn't work. Either I have something wrong, or this just won't work on Linux. Any thoughts? I'm guessing the problem(s) may be within the .js files themselves, but I'm not strong on that kind of work.

config.js is in /usr/lib/firefox, next to firefox.sh
config-prefs.js in /usr/lib/firefox/defaults/pref, next to channel-prefs.js
userChrome.js in /home/ken/.mozilla/firefox/[profile].default/chrome, next to userChrome.css

Copy link

ghost commented Sep 26, 2020

Restart restored, thank you all so much. I had upgraded to 78.3esr and it broke userchrome and the restart button.

Tabs on the top again, those ba****rds!!!

@nollinvoyd
Copy link

@rpolo77 and @you74674

Firefox 82.02

I followed the instructions.

Save config.js to Firefox installation folder, next to firefox.exe
Save config-prefs.js into \defaults\pref inside Firefox installation folder, next to channel-prefs.js
Save userChrome.js into Firefox chrome folder, next to userChrome.css
and it works

Also moved RestartFirefoxButton_Movable.uc.js to the chrome folder, but the button does not appear.

Is this still supposed to work, or am I missing something? Can someone post what the button looks like?

Copy link

ghost commented Nov 5, 2020

Did you go to Customize and add the button to your toolbar area?

@siffegh
Copy link

siffegh commented Nov 5, 2020

Button looks like this: https://prnt.sc/vdnwr0

@nollinvoyd
Copy link

nollinvoyd commented Nov 8, 2020

Guess what? I didn't have RestartFirefoxButton_Movable.uc.js in the Chrome folder after all. Dumb.

So happy. Works fine. Been hoping to find this type of restart option for a long time now.

In past custom button setups, it was possible to source the button image from a local file. I still have the previous RestartFirefoxButton_Movable.uc.js. The section of that file pertaning to the button starts with

var dataUrl = "data:image/png;base64," +

after which the base 64 code is added.

Can someone tell me if this can be done, and if so, how?

Thanks

@nollinvoyd
Copy link

I just upgraded to Firefox 89, and the restart button icon changed

Firefox 88.01

FIREFOX 88 01 RESTART

Firefox 89

FIREFOX 89 RESTART

Is there a way to bring it back?

@Gersonzao
Copy link

It doesn't work :(

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment