fiddler script, remove sessions using quickexec command.

366 views
Skip to first unread message

lcs...@gmail.com

unread,
Mar 22, 2017, 4:42:53 PM3/22/17
to Fiddler
I've searched all over, but couldn't find an answer.  I found how to do this with onBeginRequest, but what I am trying to do is a little different.

Essentially I look at fiddler traces sometimes all day long and well, a lot of these captures have tons of junk.

I added the following bit of code to OnExecAction so I could cleanup a newly loaded fiddler trace:

case "cleanup":
                UI.actSelectSessionsWithResponseHeaderValue("Content-Type", "image");
                UI.actRemoveSelectedSessions();
                UI.actSelectSessionsWithResponseHeaderValue("Content-Type", "text/javascript");
                UI.actRemoveSelectedSessions();
                UI.actSelectSessionsWithResponseHeaderValue("Content-Type", "text/css");
                UI.actRemoveSelectedSessions();
                FiddlerObject.StatusText="Cleaned up the Junk Requests";
                return true;



What I want is to remove all HTTPS CONNECTS (fiddler shows host = Tunnel To).

Any easy way to add this functionality to my script, or on loading of a fiddler.saz sessions?

Eric Lawrence

unread,
Mar 23, 2017, 6:23:51 PM3/23/17
to Fiddler
This example is adapted from the book:

       // Above the OnExecAction function, add
static function matchConnects(oS: Session) {
return oS.HTTPMethodIs("CONNECT");
}

In your Cleanup function, add:

FiddlerApplication.UI.actSelectSessionsMatchingCriteria(matchConnects);


Note that you can and probably should change your cleanup function to look like:

             case "cleanup":
                FiddlerApplication.UI.actSelectSessionsMatchingCriteria(matchJunk);
                UI.actRemoveSelectedSessions();
                FiddlerObject.StatusText="Cleaned up the Junk Requests";
                return true;

                 // Select all Junk in one shot
static function matchJunk(oS: Session) {
  if (oS.HTTPMethodIs("CONNECT")) return true;
          if (!oS.bHasResponse) return false; // Or true?
          var sMIME = oS.oResponse["Content-Type"].ToLower();
          if (sMIME.Contains("image") || sMIME.Contains("javascript") || sMIME.Contains("css")) return true;
          return false;
}

lcs...@gmail.com

unread,
Mar 24, 2017, 1:29:34 AM3/24/17
to Fiddler
Thanks that definitely helps, I purchased the debugging with fiddler book a long time ago, but it's nice to know that a 2nd edition has been released.  It's in my shopping cart.
I want to also thank you for the work you've done with fiddler.  I use fiddler day in and day out, it's amazing, and I owe you a debt of gratitude.

I'm trying to italicize and bold requests inside your function matchJunk like this, but it doesn't work.

if (oS.url.Contains("/idp/") || oS.url.Contains("/sp/") || oS.HTTPMethodIs("POST"))
{
oS["ui-italic"]="true";
oS["ui-color"]="orange";
}

what am i doing wrong!?

I tried studying the onExecAction bold command, and it's got uiBoldURI= sParams[1];..  What is confusing me is where oS: Session comes from, for example, in your matchJunk function above, you don't explicitly pass any object Session.  I need to know where in the book this is documented, as I can't find uiBoldURI defined anywhere either.  What am I missing here?

i tried invoking a function call directly from inside case "cleanup" like this:

formatRequests();

which is defined as:

static function formatRequests(oS: Session)
{
oS["ui-italic"]="true";
oS["ui-color"]="orange";
}

but that just complains about missing arguments.

Eric Lawrence

unread,
Mar 28, 2017, 10:51:21 AM3/28/17
to Fiddler
> What am i doing wrong!?

It's basically my fault. For performance reasons, Fiddler doesn't update the ViewItem's state based on the session flags (e.g. ui-italic) unless the Session changes state, or you explicitly tell it to. 

You can also simplify your code very slightly like this:

if (oS.uriContains("/idp/") || oS.uriContains("/sp/") || oS.HTTPMethodIs("POST"))
{
    oS["ui-italic"]="true";
    oS["ui-color"]="orange";
    oS.RefreshUI();
}

As for where oS comes from, the actSelectSessionsMatchingCriteria method invokes a delegate (in this case, matchJunk) for every Session in the Web Sessions list, passing that Session as the sole argument to the delegate method. If you wanted to mimic this without using the actSelectSessionsMatchingCriteria method, you'd call FiddlerApplication.UI.GetAllSessions() to return an array of all Sessions, then iterate over that array.

Reply all
Reply to author
Forward
0 new messages