Logo Questions Linux Laravel Mysql Ubuntu Git Menu
 

How can I get the result of a webrequest in a Google Chrome extension?

When I listen to all the HTTP Request with the Chrome API , how can I get the actual data recieved from it?

I mean if the request is made on a php page (XMLHttpRequest), how can I get the content of this page?

.

I am now quering the data with an ajax request. But this isn't a good solution.

The main problem is when the request uses POST method. The data recieved from the ajax query is not the same as the data recived from the HttpRequest.

like image 412
Paul Fournel Avatar asked Jul 04 '13 08:07

Paul Fournel


1 Answers

Sorry for that you can't get response body via webRequest, and what I do is try a ajax request to request the url for the second time. It's ugly, I have to request the content using background script, but It does work.

var get=function(url,callback){
var xmlRequest=new XMLHttpRequest();
xmlRequest.open('GET',url,true);
xmlRequest.send();

xmlRequest.onreadystatechange=function(){
 if(xmlRequest.readyState==4){
   callback(xmlRequest.responseText);
  }
 };
};

you can get the response body from xmlRequest.responseText

like image 155
Arnold Avatar answered Oct 18 '22 20:10

Arnold