Fyrecrypts
Fyrecrypts

Reputation: 1

Is it possible to access external XMLHttpRequests within a Chrome extension?

Essentially, I'm creating a Chrome extension that needs to read a request being sent by the website to one of their internal servers and returns a JSON object which I would like my extension to be able to read.

I've wanted to use something I've found (probably here, I've done so much research I kinda forget). This would allow me to see any XMLHttpRequest.open calls, however it appears within the extension it's using a local XMLHttpRequest.


XMLHttpRequest.prototype.realOpen = XMLHttpRequest.prototype.open;

var myOpen = function(method, url, async, user, password) {
    this.onreadystatechange = function()
    {
        if (this.readyState == 4)
            alert(this.responseText);
    }
    //call original
    this.realOpen (method, url, async, user, password);
}

//ensure all XMLHttpRequests use our custom open method
XMLHttpRequest.prototype.open = myOpen;

What I want is to use this xhr to trigger my extension into action, anyone have any idea how I can do this?

Upvotes: 0

Views: 1206

Answers (1)

Fox32
Fox32

Reputation: 13560

Look here for informations about Cross-Origin XMLHttpRequests and an example. You need to allow your extension to request from an specific domain (or "http://*/").

Upvotes: 1

Related Questions