For Firefox, I have a page that loads in a new tab after clicking a browser icon button. The background script for the page runs fine the first time but not when reloading the page, clicking the button again with a tab already open, or after having closed the tab and opening another one. I have to resave the script forcing the extension to be unloaded/reloaded for it to run correctly. Is there something in the manifest I need to include?
manifest.json
Update: I've isolated my problem to the below code. When refreshing the page or clicking the browser action button again, execution gets to and skips over the xhr.onreadystate = function() and so never gets to Main(). For anything that's been requested/received the xhr.onreadystate isn't changing.
Update 2: Execution makes one pass through to the Main() out of three. All variables retain their values from the first run through and seems to be screwing things up. How do I clear them after reloading the page or clicking the browser icon?
function GetData(request)
{
var xhr = new XMLHttpRequest();
xhr.onreadystatechange = function()
{
console.log(xhr.readyState + " : " + xhr.status)
if (xhr.readyState == 4 && xhr.status == 200)
{
re_data = JSON.parse(xhr.responseText);
Main();
}
}
xhr.open("GET", request, true);
xhr.send();
}