Chrome Extension communicate with rest web service
The API you're looking for is called XMLHttpRequest
(also known as "AJAX"). Read the documentation at https://developer.chrome.com/extensions/xhr for more information.
Here's an example:
chrome.browserAction.onClicked.addListener(function(tab) {
var link = tab.url;
var x = new XMLHttpRequest();
x.open('GET', 'http://example.com/?whatever=' + link);
x.onload = function() {
alert(x.responseText);
};
x.send();
});
Note. The XMLHttpRequest
API is asynchronous. This means that you cannot do something like this:
...
var result;
x.onload = function() {
result = x.responseText;
};
x.send();
alert(result); // Does not behave as you expect!