Fiddler: Programmatically add word to Query string

15 posts, 0 answers
  1. nasekt
    nasekt avatar
    40 posts
    Member since:
    Aug 2014

    Posted 03 Sep 2014 Link to this post

    I'm tired of manually adding "dog" every time I search the web.

    For example:

    I do not want the "dog" appearing in my search results

    https://www.google.com/search?q=cat+-dog

    https://www.google.com/search?q=baseball+-dog

    I'm new to Fiddler,So please give me a good hint.

    Thanks
  2. Eric Lawrence
    Admin
    Eric Lawrence avatar
    833 posts

    Posted 03 Sep 2014 Link to this post

    You edit the url using the oSession.fullUrl property inside the OnBeforeRequest handler.

    See http://blogs.telerik.com/fiddler/posts/13-07-15/understanding-fiddlerscript for a good introduction to FiddlerScript, including details of how to manipulate the fullUrl property.


    Regards,
    Eric Lawrence
    Telerik
     

    Check out the Telerik Platform - the only platform that combines a rich set of UI tools with powerful cloud services to develop web, hybrid and native mobile apps.

     
  3. nasekt
    nasekt avatar
    40 posts
    Member since:
    Aug 2014

    Posted 03 Sep 2014 in reply to Eric Lawrence Link to this post

    Another question:

    I want to know,if I can hide  the words in  the search box 

    http://i.stack.imgur.com/P3ZTz.jpg

    Thanks.
  4. Eric Lawrence
    Admin
    Eric Lawrence avatar
    833 posts

    Posted 03 Sep 2014 Link to this post

    Fiddler can modify the HTML response to make any change you like, including changing JavaScript or text on the page. However, there's no standard way to do this (every page on the internet works differently) and overall the task that you're embarking upon here is a bit silly.

    Regards,
    Eric Lawrence
    Telerik
     

    Check out the Telerik Platform - the only platform that combines a rich set of UI tools with powerful cloud services to develop web, hybrid and native mobile apps.

     
  5. nasekt
    nasekt avatar
    40 posts
    Member since:
    Aug 2014

    Posted 03 Sep 2014 in reply to Eric Lawrence Link to this post

    I totally love the HTML response,Now I just want to scrape/hide  the word in the search box without changing the search results(specifically Google)

    I know Fiddler can do this very easily,but I don't know where to start from? This task is important to me.

    Thank you 

    Looking forward to your reply.
  6. Eric Lawrence
    Admin
    Eric Lawrence avatar
    833 posts

    Posted 04 Sep 2014 Link to this post

    Inside OnBeforeResponse, use the GetResponseBodyAsString() method on the Session object to get the response content as a string. This obviously works only for responses that are strings.

    Use the utilSetResponseBody method to assign the body of the response to the string of your choosing.


    Regards,
    Eric Lawrence
    Telerik
     

    Check out the Telerik Platform - the only platform that combines a rich set of UI tools with powerful cloud services to develop web, hybrid and native mobile apps.

     
  7. nasekt
    nasekt avatar
    40 posts
    Member since:
    Aug 2014

    Posted 06 Sep 2014 in reply to Eric Lawrence Link to this post

    Sorry for being dumb as a rock,but Fiddler does not add text to the URL.

  8. Eric Lawrence
    Admin
    Eric Lawrence avatar
    833 posts

    Posted 10 Sep 2014 Link to this post

    Your screenshot is showing Fiddler adding the text to the URL. Note that when you change the URL this way, the browser doesn't know that it has changed; it only knows if you send back a HTTP/307 redirect that informs the browser of the new URL.

    Another thing to be aware of is that the URL part including and after the # is called the "URL Fragment". URL Fragments are kept on the clientside and are never sent to the server. They're typically examined by clientside javascript (e.g. AJAX code) to perform operations without navigating the main page.

    Regards,
    Eric Lawrence
    Telerik
     

    Check out the Telerik Platform - the only platform that combines a rich set of UI tools with powerful cloud services to develop web, hybrid and native mobile apps.

     
  9. nasekt
    nasekt avatar
    40 posts
    Member since:
    Aug 2014

    Posted 10 Sep 2014 in reply to Eric Lawrence Link to this post

    Another question:I’ve scripted it to append a string to the URL and when I keep issuing the request it keeps appending over and over again

    In OnBeforeRequest function

    if (oSession.uriContains("www.youtube.com/results?search_query=")) {

    var sText = "+test1+test2+test3";

    oSession.fullUrl = oSession.fullUrl + sText;
     }

    visual info: http://imgur.com/oRp24Ux,RvxtQTO,LniAECS#0

    How can I fix this ?

    Thank you for your time

  10. Eric Lawrence
    Admin
    Eric Lawrence avatar
    833 posts

    Posted 10 Sep 2014 Link to this post

    Your best bet for basic programming questions is a general purpose programming Q&A site like StackOverflow.

    To prevent adding text to a string multiple times, one approach would be to check to see whether that text is already in the string before adding it.

    Regards,
    Eric Lawrence
    Telerik
     

    Check out the Telerik Platform - the only platform that combines a rich set of UI tools with powerful cloud services to develop web, hybrid and native mobile apps.

     
  11. nasekt
    nasekt avatar
    40 posts
    Member since:
    Aug 2014

    Posted 10 Sep 2014 in reply to Eric Lawrence Link to this post

    Really sorry to bother you,

    I will keep it small,Can I add JQuery code to fiddler?

    var keywordInput = $('input[name="-adult"]');
    $('input[name="SearchButton"]').click(function() {
    window.location = 'http://example.com?kwd=' + encodeURIComponent(keywordInput.val());
    });

    Thank you for your time.



  12. Eric Lawrence
    Admin
    Eric Lawrence avatar
    833 posts

    Posted 11 Sep 2014 Link to this post

    You could inject jQuery code into pages, although doing so would likely break them if they already used jQuery.

    You can't use jQuery in Fiddler itself (e.g. in the script) since jQuery expects to run in the browser, and Fiddler isn't a browser.

    Regards,
    Eric Lawrence
    Telerik
     

    Check out the Telerik Platform - the only platform that combines a rich set of UI tools with powerful cloud services to develop web, hybrid and native mobile apps.

     
  13. nasekt
    nasekt avatar
    40 posts
    Member since:
    Aug 2014

    Posted 13 Sep 2014 in reply to Eric Lawrence Link to this post

    Really sorry for crossposting, but your given answer from Stackoverflow is not working, it does not even append .

    I tried it several times, but no luck. Please help me

    if (oSession.uriContains("www.youtube.com/results?search_query="))
    {
    var str = oSession.fullUrl;
    var sAppend = "+test1+test2+test3";
    if (oSession.fullUrl.indexOf(sAppend, str.length - sAppend.length) !== -1)
    {
    oSession.fullUrl = str + sAppend;
    }
    }
  14. nasekt
    nasekt avatar
    40 posts
    Member since:
    Aug 2014

    Posted 19 Sep 2014 Link to this post

    Really sorry for the inconvenience, I know this is not the appropriate site to post, but it's urgent.

    The problem with this code is that it appends string to the very end of the URL 


    if (oSession.uriContains("&q="))
    {
    var str = oSession.fullUrl;
    var sAppend = "+test1+test2+test3";
    if (!oSession.uriContains(sAppend))
    {
    oSession.fullUrl = str + sAppend;
    }
    }


    So, How can I place +test1+test2+test3 right next to search?q= ?

    Example:www.google.co.uk/search?site=webhp&source=hp&q=+test1+test2+test3&aqs=chrome..69i57.1582j0j4&sourceid=chrome&es_sm=122&ie=UTF-8

    I tried the below code, but it takes me to google+ site

    if (oSession.uriContains("&q="))
    {
    var str = oSession.fullUrl.IndexOf("&q=") ;
    var sAppend = "+test1+test2+test3";
    if (!oSession.uriContains(sAppend))
    {
    oSession.fullUrl = oSession.fullUrl.Substring( 0,oSession.fullUrl.IndexOf("&q=")) + sAppend ;
    }

    }

    Where did I go wrong?

    Thank you for your time. 
  15. nasekt
    nasekt avatar
    40 posts
    Member since:
    Aug 2014

    Posted 19 Sep 2014 in reply to nasekt Link to this post

    if (oSession.uriContains("search?q=")) 

    {
    var str = oSession.fullUrl;
    var sAppend = "+test1+test2+test3";
    if (!oSession.uriContains(sAppend))
    {
    oSession.fullUrl = str.replace( "search?q=","search?q=+test1+test2+test3" );
    }
    }

    This code works,but when I click Next page in google. It browser freezes completely. Any ideas?

Back to Top