Hello all. I am trying to write my first add-on using WebExtensions (it is quite complex for a first extension). I need to process the results of all Google searches within a session (session = queries using the same Google page). I have the following code:
manifest.json:
{
"manifest_version": 2,
"name": "MyAddon",
"version": "0.0.1",
"description": "My Add-on",
"icons": {
"48": "icons/icon-48.png"
},
"applications": {
"gecko": {
"id": "myaddon@local",
"strict_min_version": "42.0"
}
},
"content_scripts": [
{
"matches": ["*://www.google.com/*"],
"js": ["index.js"]
}
]
}
index.js:
var pageUrl = window.location.href;
var req = new XMLHttpRequest();
req.open("GET", pageUrl, true);
req.onreadystatechange = function() {
if(req.readyState == 4 && req.status == 200) {
handleResponse(req.responseText);
};
};
req.send();
function handleResponse(pageContent) {
// Do some processing ...
}
It does exactly what I need for the first search (using the address bar). However, the add-on loads the first time I enter a Google page, does what it has to, then stops. It only reloads when I refresh the page or make another query from the address bar.
I need to find a way to reload the add-on when I make another search using the search field and do the processing again, but without losing the work from the previous searches. I suppose I’ll have to use cookies, but I’m not there yet.
I tried to use req.addEventListener("load", someFunction)
instead of/besides req.onreadystatechange()
, but it didn’t solve the problem. Any ideas?
Thank you!