mozilla
Your Search Results

    Custom about: URLs

    This page describes how to register a new about: URL for your extension.

    Firefox 4 and later

    In the following code snippets, make the following replacements:

    • UUID: A UUID in format {00000000-0000-0000-0000-000000000000}.
    • SITENAME: the about: name you want to register. For example, if you wanted about:badgers, this would be badgers.
    • PATH/TO.JS: relative path to the new JS file, generally components/aboutSITENAME.js.
    • DESTINATION: a URL for what you your about: URL to load. This URL should already work. It will typically be a chrome: URL for some of your extension's content.
    • OBJECTNAME: a JS object name for your component. Can be anything - something matching SITENAME and PATH/TO.JS is good, like AboutBadgers.

    In chrome.manifest:

    component UUID PATH/TO/JS
    contract @mozilla.org/network/protocol/about;1?what=SITENAME UUID

    In a new JS file, at a location matching what you put as PATH/TO.JS:

    const Cc = Components.classes;
    const Ci = Components.interfaces;
    
    Components.utils.import("resource://gre/modules/XPCOMUtils.jsm");
    
    function OBJECTNAME() { }
    OBJECTNAME.prototype = {
      classDescription: "about:SITENAME",
      contractID: "@mozilla.org/network/protocol/about;1?what=SITENAME",
      classID: Components.ID("UUID"),
      QueryInterface: XPCOMUtils.generateQI([Ci.nsIAboutModule]),
      
      getURIFlags: function(aURI) {
        return Ci.nsIAboutModule.ALLOW_SCRIPT;
      },
      
      newChannel: function(aURI) {
        let ios = Cc["@mozilla.org/network/io-service;1"].getService(Ci.nsIIOService);
        let channel = ios.newChannel("DESTINATION", null, null);
        channel.originalURI = aURI;
        return channel;
      }
    };
    const NSGetFactory = XPCOMUtils.generateNSGetFactory([OBJECTNAME]);

    Prior to Firefox 4

    You have to replace SITENAME with your chosen name for the URL. Your URL will be "about:SITENAME". Also you'll have to generate a unique UUID for your page and replace YOUR-UUID with it. CHROMEDIR is the path to the file you want to display with your about: URL.

    const Cc = Components.classes;
    const Ci = Components.interfaces;
    
    Components.utils.import("resource://gre/modules/XPCOMUtils.jsm");
    
    function AboutSITENAME() { }
    AboutSITENAME.prototype = {
      classDescription: "about:SITENAME",
      contractID: "@mozilla.org/network/protocol/about;1?what=SITENAME",
      classID: Components.ID("{YOUR-UUID}"),
      QueryInterface: XPCOMUtils.generateQI([Ci.nsIAboutModule]),
      
      getURIFlags: function(aURI) {
        return Ci.nsIAboutModule.ALLOW_SCRIPT;
      },
      
      newChannel: function(aURI) {
        let ios = Cc["@mozilla.org/network/io-service;1"].getService(Ci.nsIIOService);
        let channel = ios.newChannel("chrome://CHROMEDIR",
                                     null, null);
        channel.originalURI = aURI;
        return channel;
      }
    };
    
    function NSGetModule(compMgr, fileSpec)
      XPCOMUtils.generateModule([AboutSITENAME]);
    

    After that, you should edit the Manifest file and add:

    EXTRA_PP_COMPONENTS = \
          aboutSITENAME.js \
        $(NULL)
    

     This makes sure that your file will be pre-processed and copied into browser/components/ .

    Document Tags and Contributors

    Tags: 
    Contributors to this page: Sheppy, Np, yarrkov, Wikiwide, MichaelKohler, Noitidart
    Last updated by: Np,