d-_-b
d-_-b

Reputation: 23181

Inject script using fiddler, except for iframe requests

I'm using Fiddler to inject a javascript library like so:

if( oSession.HostnameIs("www.mysite.com") ) 
{
  oSession.utilReplaceInResponse('</head>','<script src="//myLibrary.js"></script></head>');
}

This works by prepending my script to the closing </head>.

I've noticed that this will also inject it in any iframes on the page, but would like to prevent this.

question: Is there a way to do this while excluding iframes within Fiddler's customRules.js file?

Note, I will not know what site will be loaded in these iframes, so a generic solution is needed.

Thanks!

Upvotes: 0

Views: 477

Answers (1)

EricLaw
EricLaw

Reputation: 57085

You're asking: "Can a proxy know whether or not a given request is for a top-level frame or for an iframe?"

The answer is basically "no." If you set the X-Download-Initiator option in IE (see http://blogs.msdn.com/b/fiddler/archive/2011/02/10/fiddler-is-better-with-internet-explorer-9.aspx) you can get some awareness, but this only works in IE and you shouldn't set this option except on your own computer.

Upvotes: 2

Related Questions