When using Firefox, I encounter an issue where a page I have designed loads in a new tab after clicking a browser icon button. The background script runs smoothly the first time, but encounters problems upon reloading the page, clicking the button again with a tab already open, or opening another tab after closing one. To resolve this, I find myself having to resave the script and force the extension to be unloaded/reloaded for it to function correctly.
Update: After further investigation, I have identified that the problem lies within the code below. Whenever the page is refreshed or the browser action button is clicked again, the execution reaches and skips over the xhr.onreadystatechange function, thus failing to reach Main(). It appears that the xhr.onreadystatechange is not changing even after requests/responses have been made.
Update 2: Upon closer inspection, I have observed that the execution of the code only successfully reaches Main() on one out of three passes. All variables maintain their values from the initial run, which seems to be causing disruptions. How can I clear these variables 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();
}