Firefox does a get request to the server. It get's HTML page in response. There is a part of this HTML response page that needs to be modified. There is jQuery code in the Head section of the HTML:
<Head>
..
<script type="text/javascript">
jQuery(document).ready(function(){
init(var1, var2, var3, var4);
});
</script>
..
</Head>
The goal is to:
Point 1 I do with Fiddler that is connected to Firefox through proxy settings. Currently I don't know how to do points 2, 3 and 4 automatically. I've started to use Fiddler only recently and the documentation doesn't have examples of how to do it.
Is there easier way to send/modify requests/responses based on server requests/responses in Windows automatically using other programs?
Thank You for Your help!
You can rewrite server response on the fly with Fiddlers CustomRules
script:
FiddlerScript
tab: %userprofile%\Documents\Fiddler2\Scripts\CustomRules.js
file in your editor and locate static function OnBeforeResponse(oSession: Session) {
.)Amend its body - simple string to string replacement:
if (oSession.oResponse.headers.ExistsAndContains("Content-Type","text/html")){
oSession.utilDecodeResponse();
oSession.utilReplaceInResponse('find','replace');
oSession.utilReplaceInResponse('something','anything');
}
Alternatively regexp:
if (oSession.oResponse.headers.ExistsAndContains("Content-Type", "html")){
oSession.utilDecodeResponse();
var oBody = System.Text.Encoding.UTF8.GetString(oSession.responseBodyBytes);
var oRegEx = /([a-z]+) and ([a-z]+)/gi;
oBody = oBody.replace(oRegEx, "$2 swapped $1");
oSession.utilSetResponseBody(oBody);
}
(This will supposedly not work in cases when response was NOT UTF-8.)
The script file is "live": any change you save in it while Fiddler is running is propagated (it plays sound on file change, or different sound when you break something with corresponding prompt in Fiddler window).
Docs: http://docs.telerik.com/fiddler/KnowledgeBase/FiddlerScript/ModifyRequestOrResponse
Btw for dead simple incoming file replacement, you can use AutoResponder:
Disclosure: I do not know much about this, just happened to be messing with Fiddler today and tried this certain stuff myself just now. I suppose that there might be more robust approaches and perhaps even more intelligent proxies with incorporated HTML parsers or such which would fit your problem better; dumb string replacements cannot compete with real HTML parser and so on, but this is the first and yet the only solution I know about.