Welcome to OGeek Q&A Community for programmer and developer-Open, Learning and Share
Welcome To Ask or Share your Answers For Others

Categories

0 votes
411 views
in Technique[技术] by (71.8m points)

javascript - Intercepting XHR with JS - Not getting all the results shown in Chrome devtools from the network panel

I am trying to intercept XHR made from a website to be able to display the data from the response in a more user friendly way. The ones that are interesting to me are showing up in the network panel using google chrome devtools and I can read the request / response without any issue there.

However, if I try to intercept them with Javascript in the console for instance, I'm intercepting all XHR excepting the ones that are sent to the API containing the useful informations.

From this screenshot, I'm able to display the ones that start by "bz?_" but not the one named "api/". The request URL for the "api/" one doesn't belong to the same domain. But if I am able to see them in network panel, shouldn't I also be able to see them in the console?

I have been using this code:

(function() {
    var proxied = window.XMLHttpRequest.prototype.open;
    window.XMLHttpRequest.prototype.open = function() {
        console.log( arguments );
        return proxied.apply(this, [].slice.call(arguments));
    };
})();

I don't understand why the messages aren't appearing since the open method has been overriden...

I have also tried using the Live HTTP Headers extension Live HTTP Headers extension to peak at the requests and they intercept the same ones excepting the one of interest.

The only way I was able to display some info about the interesting XHR was to manually open the javascript file in Chrome "Sources" panel and insert some "console.log" line where the XHR is created. In the JS file, it is simply used like a new XHMLHttpRequest and then calling the open method...

       // somewhere in the huge JS file
                load: function(url) {
                    this.request = new XMLHttpRequest;
                    
                    // some other stuff done there
                    
                    this.request.open(this.parent.method, url, !0);
                                   
                    console.log(this.request);

Thank you in advance!


与恶龙缠斗过久,自身亦成为恶龙;凝视深渊过久,深渊将回以凝视…
Welcome To Ask or Share your Answers For Others

1 Reply

0 votes
by (71.8m points)
等待大神答复

与恶龙缠斗过久,自身亦成为恶龙;凝视深渊过久,深渊将回以凝视…
OGeek|极客中国-欢迎来到极客的世界,一个免费开放的程序员编程交流平台!开放,进步,分享!让技术改变生活,让极客改变未来! Welcome to OGeek Q&A Community for programmer and developer-Open, Learning and Share
Click Here to Ask a Question

...