Check if a website is making X http request with javascript - Stack Overflow

I've been searching for a while but all I could find was examples on how to actually make those re

I've been searching for a while but all I could find was examples on how to actually make those requests...

What I'm trying to do is to check if a website is making an http request after I click a button to X site

Ex. .txt

I'm guessing there a way to get all the outgoing requests and then filter the list but I can't even get the requests

What I've done so far is just inserting the eventlistener to check that X button has been clicked and then is when I'd like to check for those requests.

<script language="javascript">
document.getElementById("button").addEventListener('click', buttonClicked, true);

function buttonClicked(){
    -->Check requests made after button is clicked.<--
}
</script>

I've been searching for a while but all I could find was examples on how to actually make those requests...

What I'm trying to do is to check if a website is making an http request after I click a button to X site

Ex. http://test.s3.amazonaws./test/1.txt

I'm guessing there a way to get all the outgoing requests and then filter the list but I can't even get the requests

What I've done so far is just inserting the eventlistener to check that X button has been clicked and then is when I'd like to check for those requests.

<script language="javascript">
document.getElementById("button").addEventListener('click', buttonClicked, true);

function buttonClicked(){
    -->Check requests made after button is clicked.<--
}
</script>
Share edited Nov 13, 2015 at 17:03 the 21.9k12 gold badges74 silver badges102 bronze badges asked Jan 7, 2012 at 2:03 Alvaro ArreguiAlvaro Arregui 6091 gold badge6 silver badges9 bronze badges 6
  • 1 Have you heard about FireBug? It's an great tool for checking HTML/JS/Network stuff. You can simply trace if a page sends HTTP requests to anywhere! getfirebug./network – powtac Commented Jan 7, 2012 at 2:06
  • Don't understand wath you mean with Check requests made after button is clicked.. Do you like to get the file? – Gabriel Santos Commented Jan 7, 2012 at 2:07
  • Nowadays you don't even need Firebug. All modern browsers have these tools built in (including Firefox, just recently; the lead developer of Firebug has a new job so the Mozilla folks needed to step it up). – T.J. Crowder Commented Jan 7, 2012 at 2:08
  • what do you intend to do actually? are you just capturing <a> clicks? or checking if they are trying to point you to as site? – Joseph Commented Jan 7, 2012 at 2:08
  • @powtac i knoow you can do that, i've checked all the requests made and there are tons of them and I'm only interested in one. I just want to get the plete request url to later insert it in a webpage – Alvaro Arregui Commented Jan 7, 2012 at 4:25
 |  Show 1 more ment

1 Answer 1

Reset to default 9

I made a basic script for this a while ago, basically you just wrap the built-in XMLHttpRequest.

(function() {
  'use strict';
  var oldXHR, stateChangeHandler, prop;

  oldXHR = window.XMLHttpRequest;

  stateChangeHandler = function (evt) {
    switch (this.readyState) {
      case oldXHR.OPENED:
        console.log('Request was made', this, evt);
        break;
      case oldXHR.DONE:
        console.log('Request finished', this, evt);
        break;
    }
  };

  function newXHR() {
    var xhr = new oldXHR();
    xhr.addEventListener('readystatechange', stateChangeHandler);
    return xhr;
  }

  // Copy original states and toString
  for (prop in oldXHR)
    newXHR[prop] = oldXHR[prop];

  window.XMLHttpRequest = newXHR;
})();

发布者:admin,转转请注明出处:http://www.yc00.com/questions/1742290906a4416168.html

相关推荐

发表回复

评论列表(0条)

  • 暂无评论

联系我们

400-800-8888

在线咨询: QQ交谈

邮件:admin@example.com

工作时间:周一至周五,9:30-18:30,节假日休息

关注微信