forked from eljeffeg/SmartCopy
-
Notifications
You must be signed in to change notification settings - Fork 0
Expand file tree
/
Copy pathbackground.js
More file actions
30 lines (29 loc) · 1.19 KB
/
background.js
File metadata and controls
30 lines (29 loc) · 1.19 KB
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
/**
* Possible parameters for request:
* action: "xhttp" for a cross-origin HTTP request
* method: Default "GET"
* url : required, but not validated
* data : data to send in a POST request
* variable : pass private variable into the callback
*
* The callback function is called upon completion of the request
*
* Call to verify HistoryLink authentication to Geni & query Family Data
* */
chrome.runtime.onMessage.addListener(function(request, sender, callback) {
if (request.action == "xhttp") {
var xhttp = new XMLHttpRequest();
var method = request.method ? request.method.toUpperCase() : 'GET';
xhttp.onload = function() {
var valrtn = {source: xhttp.responseText, variable: request.variable};
callback(valrtn);
};
xhttp.open(method, request.url, true);
if (method == 'POST') {
xhttp.setRequestHeader("Content-Type", "application/x-www-form-urlencoded"); //"application/json;charset=UTF-8"
//xhttp.setRequestHeader("Content-length", request.data.length);
}
xhttp.send(request.data);
return true; // prevents the callback from being called too early on return
}
});