MozillaZine

userChrome.js hacks

Discussion about official Mozilla Firefox builds
morat
 
Posts: 4004
Joined: February 3rd, 2009, 6:29 pm

Post Posted November 9th, 2019, 9:06 am


therube

User avatar
 
Posts: 20551
Joined: March 10th, 2004, 9:59 pm
Location: Maryland USA

Post Posted November 9th, 2019, 12:40 pm

What is http://github.com/Sporif/firefox-quantu ... Chrome.css supposed to do?

copy code, put into /chrome/userChrome.css
enable "chrome" in FF ("stylesheets", about:config, toolkit.legacyUserProfileCustomizations.stylesheets)
restart FF

I'm not seeing any difference, assuming I've done things correctly (72 Nightly).


(The word legacy in there is telling, but then we all knew that.)
Fire 750, bring back 250.
Mozilla/5.0 (Windows; U; Windows NT 6.1; en-US; rv:1.9.1.19) Gecko/20110420 SeaMonkey/2.0.14 Pinball CopyURL+ FetchTextURL FlashGot NoScript

morat
 
Posts: 4004
Joined: February 3rd, 2009, 6:29 pm

Post Posted November 9th, 2019, 2:31 pm

Is there an error involving the -moz-binding property in the browser console?

Instructions:

* start firefox
* set toolkit.legacyUserProfileCustomizations.stylesheets pref to true
* exit firefox
* create userChrome.css file in chrome folder
* create userChrome.xml file in chrome folder
* create RestartFirefoxButton_Movable.uc.js file in chrome folder
* start firefox
* test restart button on nav bar next to hamburger button

Firefox Quantum compatible userChrome.js
http://github.com/Sporif/firefox-quantum-userchromejs

Gusar
 
Posts: 205
Joined: March 17th, 2006, 1:52 pm

Post Posted November 10th, 2019, 5:13 am

With XBL gone, any code that relies on it, so everything involving -moz-binding, indeed does not work anymore. So say goodbye to userChrome.js. There doesn't seem to be any replacement, there's no other way to load custom code like this anymore.

morat
 
Posts: 4004
Joined: February 3rd, 2009, 6:29 pm

Post Posted November 10th, 2019, 8:10 am

I tested...

The userChrome.js hack succeeds in the Firefox Portable 71.0b8 beta build.
The userChrome.js hack fails in the Firefox Portable 72.0a1 nightly build.

There are no errors in the browser console.

@Gusar

You can do similar hacks with the AutoConfig file.

Customizing Firefox using AutoConfig
http://support.mozilla.org/kb/customizing-firefox-using-autoconfig

Example
http://github.com/alice0775/userChrome.js/tree/master/72

AutoConfig is sandboxed by default on the release build. (i.e. can't use the Components object)

You can disable the sandbox by setting the general.config.sandbox_enabled pref to false in the autoconfig.js file.

Our long term plan is to remove the ability to turn off the sandboxing.

Firefox 62 Release Notes
http://www.mozilla.org/firefox/62.0/releasenotes/
Last edited by morat on November 17th, 2019, 8:40 am, edited 1 time in total.

therube

User avatar
 
Posts: 20551
Joined: March 10th, 2004, 9:59 pm
Location: Maryland USA

Post Posted November 17th, 2019, 7:47 am

(When I initially looked, didn't realize that all three files were need.
When looking later, yes I found the same as you.
Nothing noted in Error Console & the code no longer worked.)
Fire 750, bring back 250.
Mozilla/5.0 (Windows; U; Windows NT 6.1; en-US; rv:1.9.1.19) Gecko/20110420 SeaMonkey/2.0.14 Pinball CopyURL+ FetchTextURL FlashGot NoScript

morat
 
Posts: 4004
Joined: February 3rd, 2009, 6:29 pm

Post Posted January 10th, 2020, 10:18 am

Here are my config files in Firefox 72.

* <install directory>\defaults\pref\autoconfig.js

Code: Select all
pref("general.config.sandbox_enabled", false);
pref("general.config.filename", "mozilla.cfg");
pref("general.config.obscure_value", 0);

* <install directory>\mozilla.cfg

Code: Select all
// mozilla.cfg file needs to start with a comment line

// mozilla.cfg file is sandboxed by default i.e. can't use the Components object
// disable the sandbox by setting the general.config.sandbox_enabled pref to false

// run userChrome.js example.uc.js example.as.css example.css files in chrome folder
// do not run userChrome.css userContent.css example.js files in chrome folder

// browser-delayed-startup-finished topic supports the browser window only

// Firefox 68 uses the browser.xul page
// Firefox 69 uses the browser.xhtml page

Components.utils.import("resource://gre/modules/Services.jsm");
Services.obs.addObserver(function (aSubject, aTopic, aData) {
  var chromeWindow = aSubject;
  chromeWindow.setTimeout(function () {
    try {
      if (chromeWindow.userChromeJsMod) return;
      chromeWindow.userChromeJsMod = true;
      var chromeFiles = chromeWindow.FileUtils.getDir("UChrm", []).directoryEntries;
      var sss = Components.classes["@mozilla.org/content/style-sheet-service;1"].
        getService(Components.interfaces.nsIStyleSheetService);
      while (chromeFiles.hasMoreElements()) {
        var file = chromeFiles.getNext().QueryInterface(Components.interfaces.nsIFile);
        var fileURI = Services.io.newFileURI(file);
        if (file.isFile()) {
          if (/(^userChrome|\.uc)\.js$/i.test(file.leafName)) {
            Services.scriptloader.loadSubScriptWithOptions(fileURI.spec, {
              target: chromeWindow,
              charset: "UTF-8",
              ignoreCache: true,
            });
          } else if (/\.as\.css$/i.test(file.leafName)) {
            if (!sss.sheetRegistered(fileURI, sss.AGENT_SHEET)) {
              sss.loadAndRegisterSheet(fileURI, sss.AGENT_SHEET);
            }
          } else if (/^(?!(userChrome|userContent)\.css$).+\.css$/i.test(file.leafName)) {
            if (!sss.sheetRegistered(fileURI, sss.USER_SHEET)) {
              sss.loadAndRegisterSheet(fileURI, sss.USER_SHEET);
            }
          }
        }
      }
    } catch (e) {
      Components.utils.reportError(e); // [check] Show Content Messages
    }
  }, 10);
}, "browser-delayed-startup-finished", false);

* <profile directory>\chrome\RestartFirefoxButton_Movable.uc.js

Code: Select all
(function () {
  if (location != "chrome://browser/content/browser.xul" &&
      location != "chrome://browser/content/browser.xhtml") return;

  /* CustomizableUI
     http://developer.mozilla.org/docs/Mozilla/JavaScript_code_modules/CustomizableUI.jsm
     http://developer.mozilla.org/docs/Mozilla/JavaScript_code_modules/CustomizableUI.jsm/API-provided_widgets
  */

  try {
    CustomizableUI.createWidget({
      id: "__unique_identifier_restart_button", // should match id below
      type: "custom",
      defaultArea: CustomizableUI.AREA_MENUBAR,
   // defaultArea: CustomizableUI.AREA_NAVBAR,
      onBuild: function (aDocument) {
        var XUL_NS = "http://www.mozilla.org/keymaster/gatekeeper/there.is.only.xul";
        var toolbarbutton = aDocument.createElementNS(XUL_NS, "toolbarbutton");
        toolbarbutton.onclick = function (aEvent) {
          var win = aEvent.target.ownerDocument.defaultView;
          if (aEvent.button == 0) {
            if (aEvent.shiftKey) {
              Services.appinfo.invalidateCachesOnRestart();
              Services.prompt.alert(win, "Restart", "Invalidate caches on restart.");
            }
            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", "restart");
            if (cancelQuit.data) {
              Services.prompt.alert(win, "Restart", "Abort restart process.");
            } else {
              var appStartup = Components.classes["@mozilla.org/toolkit/app-startup;1"].
                getService(Components.interfaces.nsIAppStartup);
              appStartup.quit(appStartup.eAttemptQuit | appStartup.eRestart);
            }
          } else if (aEvent.button == 1) {
            if (aEvent.shiftKey) {
              Services.appinfo.invalidateCachesOnRestart();
              Services.prompt.alert(win, "Restart", "Invalidate caches on startup.");
            }
            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);
            if (cancelQuit.data) {
              Services.prompt.alert(win, "Restart", "Abort quit process.");
            } else {
              var prefBranch = Components.classes["@mozilla.org/preferences-service;1"].
                getService(Components.interfaces.nsIPrefBranch);
              var pref = "browser.sessionstore.resume_session_once";
              prefBranch.setBoolPref(pref, true);
              var appStartup = Components.classes["@mozilla.org/toolkit/app-startup;1"].
                getService(Components.interfaces.nsIAppStartup);
              appStartup.quit(appStartup.eAttemptQuit);
            }
          }
        };
        var dataUrl = "data:image/png;base64," +
          "iVBORw0KGgoAAAANSUhEUgAAABAAAAAQCAYAAAAf8/9hAAAABGdBTUEAANbY1E9YMgAAAB" +
          "h0RVh0U29mdHdhcmUAUGFpbnQuTkVUIHYzLjM2qefiJQAAA2hJREFUOE9tkm1MU1ccxg9F" +
          "YKIIxbdgw4e9GEQYoomArRVYwsIoEakUsRQ3KQpiF8SXMDdtajL8gho+TKeJyYxaFGyltg" +
          "ZK1bkurg4uQ0QMgjSbOrbwUoIglPbe9tm5NdGgO8mT3PM/9/md/8sJIv+3JOYwGk6miolY" +
          "HB4y5ZqeIcDfxD87SH4vmg5YJOZk4veOvm+XmOOE+XfOZp7qfya/+Ny7/dq/KNAPTafoHv" +
          "VH5LZdJWmNnxKxKSE8xzYQuvHCl3MBEnNSwv7OkVKrC0rrBDabXiLX7EbhbQ6VncCBLi9S" +
          "dT2TCdXM5PbGIURlndv7FiAxR0fm3W4qu+VC0c1RyJpGkWucQLZxGjKLF1tsfqjuAYcesj" +
          "ja60F568hcQFhWqyL95JNXiisvkHGyF+LaHmSfcXKlLS5UOGZRbGex7RcOOxwc1AyLCus7" +
          "gCWKuz/FVTH+5UrjhFDeMB68qamPrD2tjSk0n19/5IHr4B9uVHR6UeLwYGeHB5Vtw3MzEE" +
          "hNTuGWyz+LSs7r53924Rz5sCyF1hcVKtWvj69qZ3R9s9AOsPj2iRdHn7LQ2N4BhGU21IiK" +
          "6nct2/pDSfCaY2JqXkAVLJBa7CuK7b41BxgkH2Sw9hCDdVQrd//GhaTUVxBaez7dsHyQP+" +
          "R/4iVS2X1BEuN9CllEtVQQ93XaUlmtIkZ+XBkiPn2YxlbwcbJkm12hsY1AO+jDdwMcjjk5" +
          "fN/vQbzmXve8xJovApmk6mM/yDJoY3deqovKbzQESU2DfHl8hgHA3rYRqLt8+IrhoOnmUN" +
          "PtBm3cmEjZdoaIm8sFm0y/CuVXB5crm5+vqmJ80Xk3DNQcTRUUAFRSQHk3oO6ks3ZQkIM2" +
          "qd2NMusYZD862Y3HH/kyTz32FdIRp5/omwlNqddQc/gbAD9TXZ8Hh3tZlHb46bxZyK0z2G" +
          "yZhNwyjvzmYRS3DENtG8OiHFMLiZGtpmZB4BXyGRQ3DSGxumMqTfdw6pseD/bRMlR33Sho" +
          "nULBzXHsuDUONc1m9b52F1lZzfeFb+zrRaewNTy75U/yieZzEn9EGpFjuZ6q7XIW6l/MqA" +
          "z/oODiX96MusdDUTnGBvJxZSa1RL65PUDYYBCRxNoM+iWkmkc+Ko8mSSckJLletSD97B6S" +
          "VLebgvNIZGIsPV8410zIfzl/yL/mmVpFAAAAAElFTkSuQmCC";
        var tooltip = [];
        tooltip.push("", "", "L: restart application with previous windows and tabs");
        tooltip.push("M: quit application, open previous windows and tabs on startup");
        tooltip.push("R: open button context popup", "");
        tooltip.push("S+L: left click option and invalidate caches on restart");
        tooltip.push("S+M: middle click option and invalidate caches on startup", "");
        tooltip.push("The middle click option is for users that do not normally restore sessions.");
        var props = {
          id: "__unique_identifier_restart_button",
          class: "toolbarbutton-1 chromeclass-toolbar-additional",
          label: "Restart",
          tooltiptext: "Restart" + tooltip.join("\n"),
          style: 'list-style-image: url("' + dataUrl + '"); -moz-image-region: auto;',
        };
        for (var p in props) toolbarbutton.setAttribute(p, props[p]);
        return toolbarbutton;
      },
    });
  } catch (e) {
    Components.utils.reportError(e); // [check] Show Content Messages
  };
})();

Deploying Firefox in an enterprise environment
http://developer.mozilla.org/Firefox/Enterprise_deployment_before_60

Observer Notifications
http://developer.mozilla.org/docs/Mozilla/Tech/XPCOM/Observer_Notifications

CustomizableUI
http://developer.mozilla.org/docs/Mozilla/JavaScript_code_modules/CustomizableUI.jsm
http://developer.mozilla.org/docs/Mozilla/JavaScript_code_modules/CustomizableUI.jsm/API-provided_widgets
Last edited by morat on September 28th, 2020, 5:50 am, edited 1 time in total.

Kenosis
 
Posts: 65
Joined: November 11th, 2011, 5:43 am

Post Posted January 12th, 2020, 4:53 am

Thank you very much. Works perfect for me.

Cye3s
 
Posts: 20
Joined: December 28th, 2007, 9:53 pm

Post Posted September 27th, 2020, 7:11 pm

Dont work on 78.3 esr, sad

pintassilgo
 
Posts: 187
Joined: August 30th, 2013, 3:50 pm

Post Posted September 27th, 2020, 8:44 pm

It works using autoconfig as it always has. userChromeJS by XBL binding was an ugly hack and was removed.

Return to Firefox Builds


Who is online

Users browsing this forum: No registered users and 6 guests