Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

[Firefox (Nightly)] restart add-on/script speeds up testing userChrome modifications #85

Open
Pizzapops opened this issue Dec 7, 2017 · 34 comments

Comments

@Pizzapops
Copy link

commented Dec 7, 2017

I realize this may be inappropriate here but... Testing and modifying the Chrome css files requires a lot of restarting Firefox. Exiting and restarting Firefox was a nuisance. All of the restart addons on the Firefox add-ons site were labeled incompatible. Shift-F2 and type "restart" seemed to be my only option. Yesterday, I began digging through my FEBE backups trying various restart apps/versions. I did find one that works, Restart by Schuzak version 1.2.8. It provides a icon that that works, a menu bar option (under File) and a keyboard option, Alt-FR.

@Aris-t2

This comment has been minimized.

Copy link
Owner

commented Dec 7, 2017

Using legacy add-ons only works on Nightly, if they are still compatible like this restart add-on. It really improves testing between code modifications, thanks.

(Nightly only)
about:config > extensions.legacy.enabled > true
about:config > xpinstall.signatures.required > false

Restart by Schuzak

@Aris-t2 Aris-t2 changed the title [Win10][Fx59]restarts for userChrome mods [Firefox Nightly] restart add-on speeds up testing userChrome modifications Dec 7, 2017
@Aris-t2 Aris-t2 added the DISCUSSION label Dec 7, 2017
@rayman89

This comment has been minimized.

Copy link

commented Dec 17, 2017

Also shift + f2 type restart and press enter

@Pizzapops

This comment has been minimized.

Copy link
Author

commented Jan 1, 2018

Sporif posted a javascript for a "Moveable Restart Button for Firefox" on GitHubGist. I haven't tinkered with it yet. My javascript knowledge is minimal. Sporif is working on Firefox Quantum compatible userChrome.js.

@Aris-t2

This comment has been minimized.

Copy link
Owner

commented Jan 2, 2018

I adopted this useChrome.js method (->1) for my "scrollbar" tweaks a while ago.
https://github.com/Aris-t2/Scrollbars

One can do a lot of stuff after importing user scripts start working incl. additional toolbars and buttons. You can find many scripts here https://github.com/ardiman/userChrome.js including a movable restart button.

@Pizzapops

This comment has been minimized.

Copy link
Author

commented Jan 2, 2018

@Aris-t2
Sporif's script works fine. There seems to be a conflict with Schuzak's Restart but disabling that Legacy add-on fixed the problem. My translator is going to get a workout when I check out all of Ardiman's scripts.

@Aris-t2

This comment has been minimized.

Copy link
Owner

commented May 22, 2018

Restart button script - working in Firefox 62

restart

If Firefox should use only custom script, there is way without userChrome.js loading code from inside config.js. Otherwise use code inside a restart.uc.js or similar with userChrome.js.

.\firefox\defaults\pref\config-prefs.js

pref("general.config.obscure_value", 0);
pref("general.config.filename", "config.js");

.\firefox\config.js

// Restart button script for Firefox 60+ by Aris
//
// left-click on restart button: normal restart
// middle-click on restart button: no special function
// right-click on restart button: no special function
//
// based on 'Quit' button code by 2002Andreas
// restart code from Classic Theme Restorer add-on
(function() {

try {
  Components.utils.import("resource:///modules/CustomizableUI.jsm");
  var {Services} = Components.utils.import("resource://gre/modules/Services.jsm", {});
  
  CustomizableUI.createWidget({
	id: "uc-restart", // button id
	defaultArea: CustomizableUI.AREA_NAVBAR,
	removable: true,
	label: "Restart", // button title
	tooltiptext: "Restart", // button tooltip title
	onClick: function(event) {
	  
	  var cancelQuit   = Components.classes["@mozilla.org/supports-PRBool;1"].createInstance(Components.interfaces.nsISupportsPRBool);
	  var observerSvc  = Components.classes["@mozilla.org/observer-service;1"].getService(Components.interfaces.nsIObserverService);
			
	  if(event.button=='0') { // only for left-clicks
		observerSvc.notifyObservers(cancelQuit, "quit-application-requested", "restart");
			
		if(cancelQuit.data) return false;
				
		Services.startup.quit(Services.startup.eRestart | Services.startup.eAttemptQuit);
	  }
	},
	onCreated: function(button) {
	  return button;
	}
		
  });
  
  var sss =  Components.classes["@mozilla.org/content/style-sheet-service;1"].getService(Components.interfaces.nsIStyleSheetService);
  
  var uri = Services.io.newURI("data:text/css;charset=utf-8," + encodeURIComponent('\
	\
	  #uc-restart .toolbarbutton-icon {\
		list-style-image: url("chrome://browser/skin/reload.svg");\
		transform: scaleX(-1);\
		fill: red;\
	  }\
	\
  '), null, null);
  
  sss.loadAndRegisterSheet(uri, sss.AGENT_SHEET);
  
} catch (e) {
	Components.utils.reportError(e);
};

})();

v2 with "clear caches feature"

// Restart button script for Firefox 60+ by Aris
//
// left-click on restart button: normal restart
// middle-click on restart button: restart + clear caches
// right-click on restart button: no special function
//
// based on 'Quit' button code by 2002Andreas
// restart code from Classic Theme Restorer add-on
// invalidate caches from Session Saver add-on

(function() {

try {
  Components.utils.import("resource:///modules/CustomizableUI.jsm");
  var {Services} = Components.utils.import("resource://gre/modules/Services.jsm", {});
  var sss =  Components.classes["@mozilla.org/content/style-sheet-service;1"].getService(Components.interfaces.nsIStyleSheetService);
  
  CustomizableUI.createWidget({
	id: "uc-restart", // button id
	defaultArea: CustomizableUI.AREA_NAVBAR,
	removable: true,
	label: "Restart", // button title
	tooltiptext: "Restart", // tooltip title
	onClick: function(event) {
	  
	  var cancelQuit   = Components.classes["@mozilla.org/supports-PRBool;1"].createInstance(Components.interfaces.nsISupportsPRBool);
	  var observerSvc  = Components.classes["@mozilla.org/observer-service;1"].getService(Components.interfaces.nsIObserverService);
			
	  if(event.button=='1') { // middle-click - clear caches
		Components.classes["@mozilla.org/xre/app-info;1"].getService(Ci.nsIXULRuntime).invalidateCachesOnRestart();
	  }
	  
	  if(event.button=='0' || event.button=='1') { // left/middle-click - restart
		observerSvc.notifyObservers(cancelQuit, "quit-application-requested", "restart");
			
		if(cancelQuit.data) return false;
				
		Services.startup.quit(Services.startup.eRestart | Services.startup.eAttemptQuit);
	  }
	},
	onCreated: function(button) {
	  return button;
	}
		
  });
  
  // style button icon
  var uri = Services.io.newURI("data:text/css;charset=utf-8," + encodeURIComponent('\
	\
	  #uc-restart .toolbarbutton-icon {\
		list-style-image: url("chrome://browser/skin/reload.svg"); /* icon / path to icon */ \
		transform: scaleX(-1); /* icon mirroring */\
		fill: red; /* icon color name/code */\
	  }\
	\
  '), null, null);
  
  sss.loadAndRegisterSheet(uri, sss.AGENT_SHEET);
  
} catch (e) {
	Components.utils.reportError(e);
};

})();
@Aris-t2 Aris-t2 changed the title [Firefox Nightly] restart add-on speeds up testing userChrome modifications [Firefox (Nightly)] restart add-on/script speeds up testing userChrome modifications May 22, 2018
@Aris-t2

This comment has been minimized.

Copy link
Owner

commented Jun 5, 2018

Looks I was wrong about items not being possible to add to Filemenu or PanelUI-button. The scripts require userChromeJS setup and only don't work with my "config.js" shortcut.

This script add a "Restart" menutiem to "File" menu: https://github.com/Endor8/userChrome.js/blob/master/addrestartbutton/addRestartButton.uc.js

@Aris-t2 Aris-t2 closed this Jun 5, 2018
@Aris-t2 Aris-t2 reopened this Jun 5, 2018
@Aris-t2

This comment has been minimized.

Copy link
Owner

commented Jun 5, 2018

I modified the above linked "Restart" item script for "File" menu and "Application" menu. It works fine with Firefox 60+ and has to be used with userChromeJS (like shown here for example).

// Restart item script for Firefox 60+ by Aris
//
// left-click on restart item: normal restart
// middle-click on restart item: restart + clear caches
// right-click on restart item: no special function
//
// based on 'addRestartButton.uc.js' script by Alice0775
// restart code from Classic Theme Restorer add-on
// invalidate caches from Session Saver add-on

var {Services} = Components.utils.import("resource://gre/modules/Services.jsm", {});

var RestartMenuFileAppItems = {
  init: function() {

	var label = "Restart";

	try {
	  restartitem_filemenu = document.createElement("menuitem");
	  restartitem_filemenu.setAttribute("label", label);
	  restartitem_filemenu.setAttribute("id","fileMenu-restart-item");
	  restartitem_filemenu.setAttribute("key", "R");
	  restartitem_filemenu.setAttribute("insertbefore", "menu_FileQuitItem");
	  restartitem_filemenu.setAttribute("onclick", "if (event.button == 0) {RestartMenuFileAppItems.restartApp(false);} else if (event.button == 1) {RestartMenuFileAppItems.restartApp(true)};");
	  restartitem_filemenu.setAttribute("oncommand", "RestartMenuFileAppItems.restartApp(false);");

	  if(document.getElementById("menu_FileQuitItem").previousSibling.id != "fileMenu-restart-item" )
		document.getElementById("menu_FileQuitItem").parentNode.insertBefore(restartitem_filemenu,document.getElementById("menu_FileQuitItem"));
	} catch(e) {}

	try {
	  restartitem_appmenu = document.createElement("toolbarbutton");
	  restartitem_appmenu.setAttribute("label", label);
	  restartitem_appmenu.setAttribute("id","appMenu-restart-button");
	  restartitem_appmenu.setAttribute("class","subviewbutton subviewbutton-iconic");
	  restartitem_appmenu.setAttribute("key", "R");
	  restartitem_appmenu.setAttribute("insertbefore", "appMenu-quit-button");
	  restartitem_appmenu.setAttribute("onclick", "if (event.button == 0) {RestartMenuFileAppItems.restartApp(false);} else if (event.button == 1) {RestartMenuFileAppItems.restartApp(true)};");
	  restartitem_appmenu.setAttribute("oncommand", "RestartMenuFileAppItems.restartApp(false);");

	  if(document.getElementById("appMenu-quit-button").previousSibling.id != "appMenu-restart-button" )
		document.getElementById("appMenu-quit-button").parentNode.insertBefore(restartitem_appmenu,document.getElementById("appMenu-quit-button"));
	} catch(e) {}

	var sss = Components.classes["@mozilla.org/content/style-sheet-service;1"].getService(Components.interfaces.nsIStyleSheetService);

	// style button icon
	var uri = Services.io.newURI("data:text/css;charset=utf-8," + encodeURIComponent('\
	  \
	  #appMenu-restart-button {\
		list-style-image: url("chrome://browser/skin/reload.svg"); /* icon / path to icon */ \
	  }\
	  #appMenu-restart-button .toolbarbutton-icon {\
		transform: scaleX(-1); /* icon mirroring */\
		color: red; /* icon color name/code */\
	  }\
	  \
	'), null, null);

	sss.loadAndRegisterSheet(uri, sss.AGENT_SHEET);
	
  },

  restartApp: function(clearcaches) {

	var cancelQuit = Components.classes["@mozilla.org/supports-PRBool;1"].createInstance(Components.interfaces.nsISupportsPRBool);
	var observerSvc = Components.classes["@mozilla.org/observer-service;1"].getService(Components.interfaces.nsIObserverService);

	if(clearcaches) {
	  Components.classes["@mozilla.org/xre/app-info;1"].getService(Components.interfaces.nsIXULRuntime).invalidateCachesOnRestart();
	}

	observerSvc.notifyObservers(cancelQuit, "quit-application-requested", "restart");

	if(cancelQuit.data) return false;

	Services.startup.quit(Services.startup.eRestart | Services.startup.eAttemptQuit);

  }

}

RestartMenuFileAppItems.init();

Edit
Fixed issue with duplicating items.

Edit 2
Fixed Firefox 62 issue.
(Updated method 2 from here required)

@Aris-t2

This comment has been minimized.

Copy link
Owner

commented Jun 5, 2018

Just tested "method 2" from "Scrollbars" repository on a new browser/profile configuration and everything still works fine in Firefox 60+.

Repeat the steps mentioned here: https://github.com/Aris-t2/Scrollbars#method-2---files-for-firefox-installation-folder-and-firefox-profile-folder

Use short files names without spaces like:

\chrome\userChrome\restart_button.uc.js
\chrome\userChrome\restart_items.uc.js

Make sure file names are imported correctly \chrome\userChrome.js:

userChrome.import("/userChrome/restart_button.uc.js", "UChrm");
userChrome.import("/userChrome/restart_items.uc.js", "UChrm");

If required, try to clean your script cache: https://github.com/Aris-t2/Scrollbars#scriptstartup-cache-must-be-deleted-after-every-change

1

@Acid-Crash

This comment has been minimized.

Copy link

commented Jun 8, 2018

@Aris-t2. Thx for the fix.
Earlier you have mentioned that Restart item for AppButton isn't possible with config.js. Is this statement still valid or something has changed?

@Aris-t2

This comment has been minimized.

Copy link
Owner

commented Jun 8, 2018

I could not get it to work that way. It seems the script needs a certain level of access to the main window which it only gets after userChromeJS is loaded. There might be a way to combing some stuff, but I have to run some tests first.

Edit
Combining all the scripts did not work either. Most likely only stuff like this (stuff, that does not require main window / dom access) works from within config.js directly: https://developer.mozilla.org/en-US/docs/Mozilla/JavaScript_code_modules/CustomizableUI.jsm

@aabatpurdue

This comment has been minimized.

Copy link

commented Jun 10, 2018

You don't need to worry about shift + f2 much longer. See mozilla

@Aris-t2

This comment has been minimized.

Copy link
Owner

commented Jun 10, 2018

@aabatpurdue
I shared my modified restart script because of that deprecation.

Those *+#§ at Mozilla removed developer toolbar, because according to them "this feature was barely used" and those, who used it, mainly used it to restart the browser. Its actually a nobrainer to conclude people need a restart button, but they are way too focused on their "everything has to be restartless" stuff and therefore everything has to work without a restart... even if it does not.

@aabatpurdue

This comment has been minimized.

Copy link

commented Jun 10, 2018

You could change "even if" to "even when".

I found a page somewhere that implied they had nobody to maintain it and, of course, they couldn't put out the money to hire someone. As the saying goes "money, money, money, the root of all evil" or something like that (:-}).

Repository owner deleted a comment from stonecrusher Jun 11, 2018
Repository owner deleted a comment Jun 11, 2018
Repository owner deleted a comment from WagnerGMD Jun 11, 2018
Repository owner deleted a comment from WagnerGMD Jun 11, 2018
Repository owner deleted a comment Jun 11, 2018
Repository owner deleted a comment Jun 11, 2018
Repository owner deleted a comment from krystian3w Jun 11, 2018
Repository owner deleted a comment from krystian3w Jun 11, 2018
Repository owner deleted a comment from krystian3w Jun 11, 2018
Repository owner deleted a comment from krystian3w Jun 11, 2018
Repository owner deleted a comment from Acid-Crash Jun 11, 2018
Repository owner deleted a comment from hopalongrock Jun 11, 2018
Repository owner deleted a comment from Acid-Crash Jun 11, 2018
Repository owner deleted a comment from krystian3w Jun 11, 2018
Repository owner deleted a comment from hopalongrock Jun 11, 2018
Repository owner deleted a comment from hopalongrock Jun 11, 2018
Repository owner deleted a comment from Acid-Crash Jun 11, 2018
@Aris-t2

This comment has been minimized.

Copy link
Owner

commented Jun 11, 2018

Cleaned up thread/discussion!

@Pizzapops

This comment has been minimized.

Copy link
Author

commented Jun 11, 2018

@Aris-t2

I have been using Luke Baker's restart with Nuchi's XML file with both FxQ61 & FxQ62. Since XML is a Mozilla Dodo bird, I started switch over to your method 2. It works fine with FxQ61 and Ice Dragon59 but I can not get it to work with Nightly62. The App/firefox files and Chrome files are set up exactly the same as the earlier FxQ versions. I tried several profiles and some Chrome folder variations with no luck. I did a clean FxQ62 portable install. Only the App files were added and the Chrome folder with necessary Restart files. Still not working.

Did Mozilla screw up java-script on Nightly or did I miss something?

@Aris-t2

This comment has been minimized.

Copy link
Owner

commented Jun 12, 2018

@Pizzapops
Something got changed or "fixed" in Fx62, so an error inside "method 2" scripts and "restart items" script occurred.

Use the updated code above for the restart items and the updated "method 2" (v1.0.4a) from scrollbars project.

@Pizzapops

This comment has been minimized.

Copy link
Author

commented Jun 12, 2018

@Aris-t2
Thanks as always for the quick fix.

@refriedfood

This comment has been minimized.

Copy link

commented Sep 10, 2018

I followed your instructions with method 2 and I couldn't get it to work. Ultimately I'd like to use it with FF portable. Its structure is pretty much the same, but either way I couldn't get the "restart" option to even show up in the file menu.

*v62.0 - 64bit

@Acid-Crash

This comment has been minimized.

Copy link

commented Sep 11, 2018

@refriedfood.
Hi, I do successfully use Restart script on FF Nightly portable (Windows).
You need to do the following:
FirefoxPortableNightly\App\firefox64\defaults\pref
Update channel-prefs.js
FirefoxPortableNightly\App\firefox64
Add here config.js

FirefoxPortableNightly\Data\profile\chrome
Add userChrome.js and userChrome folder

startupCache (needs to be cleared) folder is here FirefoxPortableNightly\Data\profile\startupCache\

@refriedfood

This comment has been minimized.

Copy link

commented Sep 12, 2018

I did that, too. I don't know what magic you're doing, but I certainly don't have the same spell you do.

@Pizzapops

This comment has been minimized.

Copy link
Author

commented Sep 12, 2018

@refriedfood
Click on ItWorks and click Download. It is a clean FXNightly.zip with only JS added and has nine functioning scripts including left sidebar. Follow @Acid-Crash 's directions and clear startupCache before starting Nightly for the first time. Change the default profile in ** about:profiles** to the profile that is included. Be careful not to delete any profiles used by other copies of Nightly.

@refriedfood

This comment has been minimized.

Copy link

commented Sep 14, 2018

That did it. What was missing was a proper config.js in FirefoxPortable\App\Firefox64

So:
FirefoxPortable\App\Firefox64\config.js
FirefoxPortable\Data\profile\chrome\userChrome.js
userChrome.import("/userChrome/restart_button.uc.js", "UChrm"); userChrome.import("/userChrome/restart_items.uc.js", "UChrm");
Must be in userChrome.js
FirefoxPortable\Data\profile\chrome\userChrome\userChromeJS.js & userChromeJSutilities.js & restart_items.uc.js & restart_button.uc.js
Cleared FirefoxPortable\Data\profile\startupCache

Got it. Great job, and thank you!
Now if I could just get the search bar to stick on the current engine I've selected each time so I don't have to type and then click the engine each time.

@krystian3w

This comment has been minimized.

Copy link
Contributor

commented Sep 25, 2018

https://mail.mozilla.org/pipermail/firefox-dev/2018-March/006249.html -
if someone was looking for what happened to Firefox Command Line for Developers.

@bendover22

This comment has been minimized.

Copy link

commented Mar 11, 2019

Don't know if this has been mentioned, but I add a bookmark for "about:profiles" to the bookmark toolbar. It has options to restart normally & restart w/ addons disabled. It's very fast for me.
I keep the bookmarks toolbar hidden & instead add the "open bookmark" icon to the navbar.

I name the bookmark "Restart Fx". It only takes clicking the bookmark icon, then hovering Bookmarks Toolbar item - where it shows any BM that you added to the BM toolbar.

@Aris-t2

This comment has been minimized.

Copy link
Owner

commented Mar 11, 2019

If you use custom js scripts, you can place a button on your toolbar.
I use restart_button.uc.js with my "dev" profile: https://github.com/Aris-t2/CustomJSforFx/tree/master/scripts

@vladaurosh

This comment has been minimized.

Copy link

commented Jul 18, 2019

Hi Aris-t2.
I am not able to add this to FF 68.
I added this into chrome/userChrome.js
userChrome.import("/userChrome/restart_button.uc.js", "UChrm");
userChrome.import("/userChrome/restart_items.uc.js", "UChrm");

Then I added script from this link into userChrome/restart_items.uc.js

What should I add into userChromeJS.js file?

I created defaults/pref/config-prefs.js and added:
pref("general.config.obscure_value", 0);
pref("general.config.filename", "config.js");
pref("general.config.sandbox_enabled", false);

And config.js as well with:

const Cu = Components.utils;
try {
  Cu.import("resource://gre/modules/Services.jsm");
  Cu.import("resource://gre/modules/osfile.jsm");
  if (!Services.appinfo.inSafeMode) {	
	Services.scriptloader.loadSubScript(
	  OS.Path.toFileURI(OS.Path.join(OS.Constants.Path.profileDir,
		"./chrome/userChrome/userChromeJS.js")), this, "UTF-8");	
  };
} catch(e) {};

What am I missing here?

Thanks,

@Aris-t2

This comment has been minimized.

Copy link
Owner

commented Jul 18, 2019

Please keep the JS talk inside the corresponding area of the CustomJSforFx repository: Aris-t2/CustomJSforFx#4

Everything you need to know is written on the main page of that repository: https://github.com/Aris-t2/CustomJSforFx/

I recommend to test M2 with a clean new Fx profile.

@vladaurosh

This comment has been minimized.

Copy link

commented Jul 18, 2019

Thanks Aris-t2, will do.
I cleared script/startup cache, and it works now.

@vladaurosh

This comment has been minimized.

Copy link

commented Sep 7, 2019

Looks like new FF 69 broke this. :(
File menu is now horizontal and missing Restart.

@Aris-t2

This comment has been minimized.

Copy link
Owner

commented Sep 8, 2019

Test a new profile, make sure you have updated CSS files, JS methods and JS scripts, if you are using them. Also check if this pref is set correctly:
'about:config > toolkit.legacyUserProfileCustomizations.stylesheets > true'

@hopalongrock

This comment has been minimized.

Copy link

commented Sep 11, 2019

I have the same issue with FF 69 and 70 beta.
Based on Aris's comment I downloaded and copied the files from CustomJSforFx, Method 2, the restart scripts from here. Now I have 3 program folders and 4 profiles, all have this problem. The interesting thing is that the restart button works fine.
Maybe the restart_items.uc.js script is causing it.

The previous FF versions didn't have this issue.

@Aris-t2

This comment has been minimized.

Copy link
Owner

commented Sep 12, 2019

Try to setup a new test profile and make sure you are cleaning the corresponding cache folder.

All scripts work up to Fx 71 Nightly.

@hopalongrock

This comment has been minimized.

Copy link

commented Sep 12, 2019

I've used so far the "Restart item script" and "Restart button script" you posted in this issue as text.
Using the "restart_button.uc.js" and "restart_item_in_menu.uc.js" scripts from CustomJSforFx solved my horizontal File menu problem in Fx 69 and 70.

Thanks Aris!

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Projects
None yet
10 participants
You can’t perform that action at this time.