Prefs

Overview

Fiddler 2.3 includes a new preferences management system which is accessible to script and extensions. The system is designed to be somewhat similar to the preferences system within Firefox (e.g. type about:config in Firefox to view the preferences).

  • The Preference values are automatically serialized to and deserialized from the registry. (Note: See the "Magic Names" section below).

Preference Naming

  • Preference names are not case-sensitive.
  • Preference names must contain ASCII A-Z, numbers, dots, and dashes only.
  • Preference names must be between 1 and 255 characters in length.
  • Prefs containing the word ephemeral will not be saved or loaded from the registry
  • Prefs containing the word internal cannot be created or updated by extensions or script

The current preferences list is here

The IFiddlerPreferences Interface

Fiddler's Preference object will be found at FiddlerApplication.Prefs; it exposes the IFiddlerPreferences interface.

    public interface IFiddlerPreferences
    {
        // Indexer
        string this[string sName] {get; set; }
 
        // Setters
        void SetBoolPref(string sPrefName, bool bValue);
        void SetInt32Pref(string sPrefName, Int32 iValue);
        void SetStringPref(string sPrefName, string sValue);
 
        // Getters
        bool GetBoolPref(string sPrefName, bool bDefault);
        string GetStringPref(string sPrefName, string sDefault);
        Int32 GetInt32Pref(string sPrefName, Int32 iDefault);
        void RemovePref(string sPrefName);
 
        // Change Notification
        PreferenceBag.PrefWatcher AddWatcher(string sPrefixFilter, EventHandler<PrefChangeEventArgs> pcehHandler);
        void RemoveWatcher(PreferenceBag.PrefWatcher wliToRemove);
    }

Storing Preferences

You can store preferences using the Prefs.SetStringPref, Prefs.SetBoolPref, or Prefs.SetInt Pref APIs.

Alternatively, you can use the default indexer to store a string preference directly.

Using Fiddler's QuickExec box, you can store a preference like so:

prefs set your.pref.name "your pref value"

If you need to include a quote in your preference, add a leading backslash:

prefs set something.I.said "I said \"Don't Run!\" loudly."

Note: If storing a path, you should either add trailing whitespace or omit the final backslash:

prefs set fiddler.config.path.captures "F:\Work\Captures"

Alternatively type about:config or click View > Tabs > Preferences to use the editing grid to add, edit, or remove preferences.

Retrieving Preferences

You can retrieve preferences using the Prefs.GetStringPref, Prefs.GetBoolPref, or Prefs.GetIntPref APIs.

Alternatively, you can use the default indexer to retrieve a string preference directly.

Using Fiddler's QuickExec box, you can show a preference like so:

prefs show your.pref.name

or simply type

about:config

to show them all.

Removing Preferences

You can delete a Preference by calling Prefs.Remove("flagname").

Using Fiddler's QuickExec box, you can remove a preference like so:

prefs remove your.pref.name

Notification of Changes in Extensions

You can subscribe to receive notifications when preferences within a given branch change by attaching a Watcher.

oWatcher = FiddlerApplication.Prefs.AddWatcher(string sPrefixToMatch, EventHandler<PrefChangeEventArgs> fnToNotify);

Note that the PrefChangeEventArgs' ValueString member will be null if the preference is being removed.

To ensure proper garbage collection of objects, be sure to remove the Watcher when it is no longer needed.

FiddlerApplication.Prefs.RemoveWatcher(oWatcher);

Notification of Changes in FiddlerScript

To prevent a Watcher reference from preventing garbage collection of the script engine, scripts should instead use the WatchPreference function.

static function FnChange(o: Object, pceA: PrefChangeEventArgs){
    if (null != pceA){
        MessageBox.Show(pceA.PrefName + " changed to: " + pceA.ValueString); 
    }
    else{
        MessageBox.Show("Unexpected.");
    }
}
 
static function Main()
{
    FiddlerObject.WatchPreference("fiddler.", FnChange);
}

Fiddler will automatically take care of detaching the Watcher when a script engine unloads.

Profiles

Future versions of the Fiddler Preference system will support Profiles.

Unless otherwise stated, the content of this page is licensed under Creative Commons Attribution-ShareAlike 3.0 License