Default Profile Directory Doesn’t Work in Firefox 46

It was recently discovered that support for using the defaults/profile directory to prepopulate a Firefox profile was removed in Firefox 46.

Here’s an AutoConfig file that adds back the functionality:

//
const {classes: Cc, interfaces: Ci, utils: Cu} = Components;
Cu.import("resource://gre/modules/Services.jsm");
Cu.import("resource://gre/modules/FileUtils.jsm");

if (!Services.prefs.prefHasUserValue("browser.startup.homepage_override.mstone")) {
  // New profile
  var defaultProfileDir = Services.dirsvc.get("GreD", Ci.nsIFile);
  defaultProfileDir.append("defaults");
  defaultProfileDir.append("profile");
  if (defaultProfileDir.exists()) {
    var profileDir = Services.dirsvc.get("ProfD", Ci.nsIFile);
    try {
      copyDir(defaultProfileDir, profileDir);
    } catch (e) {
      Components.utils.reportError(e);
    }
  }
}

function copyDir(aOriginal, aDestination) {
  var enumerator = aOriginal.directoryEntries;
  while (enumerator.hasMoreElements()) {
    var file = enumerator.getNext().QueryInterface(Components.interfaces.nsIFile);
    if (file.isDirectory()) {
      var subdir = aDestination.clone();
      subdir.append(file.leafName);
      try {
        subdir.create(Ci.nsIFile.DIRECTORY_TYPE, FileUtils.PERMS_DIRECTORY);
        copyDir(file, subdir);
      } catch (e) {
        Components.utils.reportError(e);
      }
    } else {
      try {
        file.copyTo(aDestination, null);
      } catch (e) {
        Components.utils.reportError(e);
      }
    }
  }
}

This should work for most file types, although it probably won’t work for bookmarks.html

I’ll also be adding this functionality to the next version of the CCK2 which will be released later today.

Please note: I reserve the right to delete comments that are offensive or off-topic.

Leave a Reply

Your email address will not be published. Required fields are marked *

30 thoughts on “Default Profile Directory Doesn’t Work in Firefox 46

  1. Mike, what’s your recommended way to cope with bootstrapped extensions?

    I looked into extensions.bootstrappedAddons, there are extensions that require their stuff to be written there in order to show up immediately (e.g. uBlock Origin). According to my knowledge I have to generate a json object containing the extension’s id, type, version and multiprocessCompatible variable. I already managed to get the relevant data out of a xpi, but I’m unsure how to achieve

    {“uBlock0@raymondhill.net”:{“version”:”1.7.4″,”type”:”extension”,”descriptor”:”C:\\Program Files (x86)\\Mozilla Firefox\\profile\\extensions\\uBlock0@raymondhill.net.xpi”,”multiprocessCompatible”:true,”runInSafeMode”:false}}

    for the prefs.js setting.
    How would you do it?

  2. This sucks, I just have a simple batch file that would install and copy the file to Firefox directory and when the user launches Firefox for the first time the file in the browser folder would just copy to the profile. Is there a easier way doing this without modifying all this stuff? It’s very confusing.

  3. Hello,

    I’m trying to implement the autoconfig functionality with the config file you have provided, but I seem to be missing something.

    I’ve created an autoconfig.js file inside of C:\Program Files (x86)\Mozilla Firefox\defaults\pref with the following content:
    pref(“general.config.filename”, “firefox.cfg”);
    pref(“general.config.obscure_value”, 0);

    I’ve created firefox.cfg at the root of C:\Program Files (x86)\Mozilla Firefox with the content directly from your post.

    My profile is stored at C:\Program Files (x86)\Mozilla Firefox\browser\defaults\profile, per the standard that functioned up until Firefox 46, which is the release that they removed the default profile functionality in.

    Thoughts on what I’m missing here?

    Thanks!

    • My code uses defaults/profile not browser/defaults/profile.

      You can add defaultProfileDir.append(“browser”); right after querying the directory for that to work.

  4. Hi Mike, I was wondering if you knew how to add a default mailto: handler. I’d like to configure the organization’s webmail as default handler for mailto: links, so I’ve tried searching for options on about:config but I only stumbled upon the ones shipped with Firefox and not mine. Thanks for the awesome CCK2, it’s really useful!

  5. Some of files was copied with this script, but mimetypes.rdf – not copied or was replaced.
    How to add to default mimetypes.rdf file records like this:

    ………

    ………………..
    In existing profile I can edit mimetype.rdf, but I want to make modifications in default file for new profiles.
    Before version 46.0 profile was created from “defaults” folder but now this didn`t work

  6. I stuck an autoconfig.js file with the content from your post above with the copyDir function and nothing seems to happen. I tried multiple locations for the profile files, including:
    c:\Program Files\Mozilla Firefox\defaults\profile

    Are there any other changes needed to get the autoconfig to work?

    The only reason I need the above is that I am having one issue with CCK2 (which worked great otherwise). We use self-signed certificates, so was using Cert Overrides tab to add them. The problem is that if the certificate server is down when the browser is initially launched, the certificates are never imported for that user until the user’s Mozilla profile is cleaned up and Firefox is re-launched when the server is up. The only thing I can think of to get around this is to get the copy profile working again which we used prior to Firefox 46.

    Any ideas?
    Thank You.

    • Did you make the changes to defaults/pref to enable the autoconfig? Can you add some prefs to autoconfig?

      As far as the self signed certs go, the way it works is that it does a preconnect to the server in question and marks them as valid.

      It should be a one time thing though…

      I think what I’ll look into is allowing the CCK2 to create cert override.txt

      • I don’t have any experience customizing Firefox, but all I did was create an autoconfig.js file with the exact contents from the code above (the copyDir function) and stuck it in defaults/pref. There is nothing else in that file. What else do I need to do to enable autoconfig because nothing seems to be happening. Every time I read about autoconfig, they always mention creating and referencing mozilla.cfg in the autoconfig, but all I want to do is copy the default profile. Do I still need a mozilla.cfg in this case?

        For the certificate issue, the preconnect takes place when the user launches the browser. In our disconnected system, there is a decent chance that the server may not be available when they launch the browser. Because it is a one-time thing, the preconnect fails and the overrides never get added. If the cert_override.txt is a way around this, that would definitely work.

        • Just tested, the autoconfig.js is working because it does find the mozilla.cfg and I can set preferences.

          The above code still doesn’t copy my profile for new users though. Is there a way to debug the autoconfig script? Alerts don’t work, is there a way to output text to a log file?

            • It is copying the files from the default profile fine, but…

              Once the browser is initially started, it overwrites the preferences that were copied in. The only thing that is working for me are the certificates and bookmarks. All about:config preferences are overwritten and the initial display of the menu/toolbar does not work.

              I guess I’ll have to use a combination of CCK2 and the profile copy of the certificates (cert_override.txt and cert8.db) in order to get everything I need. This is getting messy.

              • You can use the CCK2 to do the same thing as cert overrides and cert8.db.

                Is there something specific that’s not working?

                • Like I mentioned in my original post, using the overrides requires the certificate server to be available when the user first launches Firefox. In our system this is very common. Since this is a one-time thing, the overrides never get added.

  7. It work for me. Thank you.

    By the way I use >>>lockPref(“browser.startup.homepage_override.mstone”,”ignore”);<<>>if (!Services.prefs.prefHasUserValue(“extensions.lastPlatformVersion”)) {<<<

  8. Hi Mike,
    I am trying to distribute Firefox 50 with a default profile by adding an edited localstore.rdf.
    The file is getting copied over within the new profile thanks to your above script, but with the new profile it doesn’t seem to have any effect. Also, in other new profiles without configuration, localstore.rdf doesn’t appear anymore.
    Do you know if this has changed recently?

    • I think with Firefox 50 localstore.rdf was replaced with another file.

      My suggestion would be that you check a new profile and look for a different file. I’ll check as well.

  9. Hi Mike,

    I used the below userChrome.css code for FF 45 to hide the ‘Help, About, Check for updates’ button. This code does not work for version 50, nor can I get anything to work in a userChrome.css file now.

    #updateSeparator, #checkForUpdates { display: none !important; }
    #enableAppUpdate { display: none !important; }

    Any ideas on what broke and how to hide the button in version 50?

    Thanks.

  10. When I try to download CCK2 I get “Firefox prevented this site from asking you to install software on you computer.” I click on Allow and I get this message ” github.com The Add-on could not be downloaded because of a connection failure” Any idea how I can get around this error.
    sarah