Logo Questions Linux Laravel Mysql Ubuntu Git Menu
 

Adding a delay in FiddlerScript

Tags:

fiddler

I would like to add a uniform delay to responses in all sessions that Fiddler intercepts. The use of "response-trickle-delay" is unacceptable, since that doesn't actually introduce a uniform delay, but rather delays each 1KB of transfer (which simulates low bandwidth, rather than high latency).

The only reference I could find was here, which used the following atrocity (DO NOT USE!):

static function wait(msecs) 
{ 
var start = new Date().getTime(); 
var cur = start; 
while(cur – start < msecs) 
{ 
cur = new Date().getTime(); 
} 
}

and wait(5000); is inserted into OnBeforeResponse.

As expected, it locked up my computer and started overheating my CPU and I had to quit Fiddler.

I'm looking for something:

  • Less stupid, and
  • As simple as possible.

It looks like FiddlerScript is written in JScript.NET, and from what I gather there is a setTimeout() function, but I'm having trouble calling it (and I don't know JavaScript or .NET at all). Here is my OnBeforeResponse:

static function OnBeforeResponse(oSession: Session) {
    if (m_Hide304s && oSession.responseCode == 304) {
        oSession["ui-hide"] = "true";
    }
    setTimeout(function(){},1000);
}

It just gives a syntax error at the setTimeout line. Can setTimeout() be used from a FiddlerScript to introduce uniform delay?

like image 683
DumpsterDoofus Avatar asked Jul 23 '15 00:07

DumpsterDoofus


1 Answers

FiddlerScript uses JScript.NET, which can reference .NET assemblies, and System.Threading contains Sleep.

  1. In Tools > Fiddler Options > Extensions, add the path to System.Threading.dll. On my machine, this was located at C:\Windows\Microsoft.NET\Framework\v4.0.30319.
  2. In FiddlerScript, add import System.Threading;.
  3. You can now add lines like Thread.Sleep(1000).
like image 172
Peter Richter Avatar answered Jan 02 '23 23:01

Peter Richter