Hello Community!
I try to make my first Add-on. The Add-on will read data from a sensor over a webservice and prefill a form of a given site.
I have the following draft:
function myFunction() {
var request = new XMLHttpRequest();
// readData.php is the server-side script that communicates with WebJson and delivers the answer
request.open("POST", "https://jsonplaceholder.typicode.com/posts", true);
request.setRequestHeader("Content-Type", "application/json");
request.addEventListener('load', function(event) {handleResponse(request)});
request.send('{"opcode":"read", "seq":0, "name":["Memory.TestInteger"]}');
}
function handleResponse(request)
{
var j = JSON.parse(request.responseText);
var i = j['id'];
document.querySelector('input[name = "q"]').value = i;
}
var myVar = setInterval(myFunction, 2000);
When I open the google page and add the code in the Console all two seconds the value “101” will be witten in the search form. Everything is perfect.
But wrapped into an Add-on as content_script it will not work. I have added several permission in the manifest.json. But the XMLHttpRequest is not working.
Is there someome with a good idea or similar observations?
Thank you.