1

Hi I am developing a chrome extension. Now my extension can get and send request with user on click . But i want when user navigates any site extension on background will send a POST request each time user loads a new page on browser. I have tried to look for any examples or tutorials but ended up nothing specific. Can someone refer any link or working example how chrome listens when user loads a new page and send POST request ?

1 Answer 1

10

In your background page:

chrome.tabs.onUpdated.addListener( function(tabId, changeInfo, tab) {

    if(changeInfo.status == "loading"){

        var request = new XMLHttpRequest();

        request.open("POST", "http://www.oh-hi-denny.com/", true);
        request.setRequestHeader("Content-Type", "application/json;charset=UTF-8");
        request.send(JSON.stringify({denny: 1, mark: 1, johnny: 0}));
    }
});
3
  • hi . I tried that. but i am continiously getting internal server error 500.
    – user12
    Commented Sep 17, 2015 at 14:00
  • 1
    That can have a number of reasons, none of which is the code above. You have to look for the error in the server or in your request. Can you reproduce this error with postman?
    – cviejo
    Commented Sep 17, 2015 at 14:14
  • 2
    Where have you uploaded it? You should probably post a different question about this.
    – cviejo
    Commented Sep 18, 2015 at 8:22

Your Answer

By clicking “Post Your Answer”, you agree to our terms of service and acknowledge you have read our privacy policy.

Not the answer you're looking for? Browse other questions tagged or ask your own question.