Gary Sieling

Adding an “Export to Excel” Option in Fiddler

Fiddler (HTTP proxy for Windows) is a valuable tool for finding out what is happening in an external environment (e.g. when a client uses IE).

It’s sometimes helpful to pull it’s data into Excel – this allows you to highlight dramatic deviations.

The scripting API allows you to do this – drop the following code into the Fiddler script file-

public static ToolsAction("Copy Request Timings to Excel")
function DoHighlightSlowRequests() {
  var oSessions = FiddlerApplication.UI.GetAllSessions();
     
  var s: String = "";
  s = s +
    "Index\t" +
    "URL\t" +
    "Is HTTPS\t" +
    "Response Code\t" +
    "Request Bytes\t" +
    "Response Bytes\t" +
         
    "ClientConnected\t" +
    "ClientBeginRequest\t" +
    "ClientDoneRequest\t" +
         
    "ServerConnected\t" +
    "FiddlerBeginRequest\t" +
    "ServerGotRequest\t" +   
    "ServerBeginResponse\t" +
    "ServerDoneResponse\t" +
    "ClientBeginResponse\t" +
    "ClientDoneResponse\t" +
         
    "DNSTime\t" +
    "GatewayDeterminationTime\t" +
    "TCPConnectTime\t" +
    "HTTPSHandshakeTime\t" +
         
    "Request Transmission Time\t" +
    "Server Time Spent\t" +
    "Response Transmission Time\t" +
    "Transmission time (down + up)\t" +
    "Total Round Trip Time" +
    "\r\n";
  for (var x:int = 0; x < oSessions.Length; x++){
    var session = oSessions[x]
    var timer = session.Timers
    // use tabs intead of CSV because
    // Excel and .NET have incompatible 
    // expectations for unicode format
         
    var t = oSessions[x].Timers
    var transmissionTime = 
      new TimeSpan(t.ServerGotRequest.Ticks - 
                   t.FiddlerBeginRequest.Ticks).Milliseconds
    var serverTimeSpent = 
      new TimeSpan(t.ServerDoneResponse.Ticks - 
                   t.ServerGotRequest.Ticks).Milliseconds 
    var responseTransmissionTime = 
      new TimeSpan(t.ServerDoneResponse.Ticks - 
                   t.ServerBeginResponse.Ticks).Milliseconds 
    var totalTransferTime = 
      transmissionTime + responseTransmissionTime
    var roundTripTime = 
      new TimeSpan(t.ClientDoneResponse.Ticks - 
                   t.ClientBeginRequest.Ticks).Milliseconds 
         
    var transmissionTimeStr = 
      transmissionTime < 0 ? "" : transmissionTime + ""
    var serverTimeSpentStr =  
      serverTimeSpent < 0 ? "" : serverTimeSpent + ""
    var responseTransmissionTimeStr = 
      responseTransmissionTime < 0 ? "" : responseTransmissionTime + ""
    var totalTransferTimeStr = 
      totalTransferTime < 0 ? "" : totalTransferTime + ""
    var roundTripTimeStr =
      roundTripTime < 0 ? "" : roundTripTime + ""
            
    s = s +
        x + "\t" +
        oSessions[x].url + "\t" +
        oSessions[x].isHTTPS + "\t" +
        oSessions[x].responseCode + "\t" +
        oSessions[x].requestBodyBytes.Length + "\t" +
        oSessions[x].responseBodyBytes.Length + "\t" +               
             
        oSessions[x].Timers.ClientConnected.Ticks + "\t" +
        oSessions[x].Timers.ClientBeginRequest.Ticks + "\t" +
        oSessions[x].Timers.ClientDoneRequest.Ticks + "\t" +
             
        oSessions[x].Timers.ServerConnected.Ticks + "\t" +
        oSessions[x].Timers.FiddlerBeginRequest.Ticks + "\t" +
        oSessions[x].Timers.ServerGotRequest.Ticks + "\t" +
        oSessions[x].Timers.ServerBeginResponse.Ticks + "\t" +
        oSessions[x].Timers.ServerDoneResponse.Ticks + "\t" +
        oSessions[x].Timers.ClientBeginResponse.Ticks + "\t" +
        oSessions[x].Timers.ClientDoneResponse.Ticks + "\t" +
            
        oSessions[x].Timers.DNSTime + "\t" +
        oSessions[x].Timers.GatewayDeterminationTime + "\t" +
        oSessions[x].Timers.TCPConnectTime + "\t" +              
        oSessions[x].Timers.HTTPSHandshakeTime + "\t" +
             
        transmissionTimeStr + "\t" + 
        serverTimeSpentStr + "\t" + 
        responseTransmissionTimeStr + "\t" + 
        totalTransferTimeStr + "\t" + 
        roundTripTimeStr +
        "\r\n";
  }
  System.Windows.Forms.Clipboard.SetText(
    s.ToString(), 
    TextDataFormat.Text);     
}
Exit mobile version