Skip to content

Instantly share code, notes, and snippets.

@jscher2000
Created July 27, 2019 01:31
Show Gist options
  • Select an option

  • Save jscher2000/ad268422c3187dbcbc0d15216a3a8060 to your computer and use it in GitHub Desktop.

Select an option

Save jscher2000/ad268422c3187dbcbc0d15216a3a8060 to your computer and use it in GitHub Desktop.
Browser Console script to reload userChrome.css
/*
Code to paste and run in the Browser Console
Requires devtools.chrome.enabled => true in about:config
Tested in Firefox 68.0.1 on Windows
*/
// Create references to APIs we'll use
var ss = Cc["@mozilla.org/content/style-sheet-service;1"].getService(Ci.nsIStyleSheetService);
var io = Cc["@mozilla.org/network/io-service;1"].getService(Ci.nsIIOService);
var ds = Cc["@mozilla.org/file/directory_service;1"].getService(Ci.nsIProperties);
// Get the chrome directory in the current profile
var chromepath = ds.get("UChrm", Ci.nsIFile);
// Specific file: userChrome.css or userContent.css
chromepath.append("userChrome.css");
// Morph to a file URI
var chromefile = io.newFileURI(chromepath);
// Unregister the sheet
if(ss.sheetRegistered(chromefile, ss.USER_SHEET)){
ss.unregisterSheet(chromefile, ss.USER_SHEET);
}
// Reload the sheet
ss.loadAndRegisterSheet(chromefile, ss.USER_SHEET);
@jscher2000

Copy link
Copy Markdown
Author

@gabrielpetry

gabrielpetry commented Apr 18, 2020

Copy link
Copy Markdown

you can embrace on a loop, if you are as lazy as I am.

setInterval(() => {
    /*
       Code to paste and run in the Browser Console
       Requires devtools.chrome.enabled => true in about:config
       Tested in Firefox 68.0.1 on Windows
    */

    // Create references to APIs we'll use
    var ss = Cc["@mozilla.org/content/style-sheet-service;1"].getService(Ci.nsIStyleSheetService);
    var io = Cc["@mozilla.org/network/io-service;1"].getService(Ci.nsIIOService);
    var ds = Cc["@mozilla.org/file/directory_service;1"].getService(Ci.nsIProperties);
      
    // Get the chrome directory in the current profile
    var chromepath = ds.get("UChrm", Ci.nsIFile);

    // Specific file: userChrome.css or userContent.css
    chromepath.append("userChrome.css");

    // Morph to a file URI
    var chromefile = io.newFileURI(chromepath);

    // Unregister the sheet
    if(ss.sheetRegistered(chromefile, ss.USER_SHEET)){
      ss.unregisterSheet(chromefile, ss.USER_SHEET);
    }

    // Reload the sheet
    ss.loadAndRegisterSheet(chromefile, ss.USER_SHEET);
}, 1000)

@Lassebq

Lassebq commented Jul 22, 2023

Copy link
Copy Markdown

How would you do the same with userContent.css? I want to refresh userContent.css on all tabs, kinda how vscode's live server does it.
EDIT: Replacing userChrome.css does exactly that

@omnigenous

Copy link
Copy Markdown
Uncaught ReferenceError: Cc is not defined

@brookerose1312

brookerose1312 commented Oct 21, 2024

Copy link
Copy Markdown

@omnigenous

Requires devtools.chrome.enabled => true in about:config

@omnigenous

Copy link
Copy Markdown

@brookerose1312 I have it enable same issue

@jscher2000

Copy link
Copy Markdown
Author
Uncaught ReferenceError: Cc is not defined

@brookerose1312 I have it enable same issue

Make sure you are using the Browser Console (Ctrl+Shift+J on Windows), not the page-level Web Console (Ctrl+Shift+K on Windows).

@rempas

rempas commented Jun 7, 2025

Copy link
Copy Markdown

It works but the "userChrome.css" code is applied to the page and not the browser itself...

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