0

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();
}
Danja
  • 1
  • 2
  • No, what is in the *manifest.json* should not result in what you describe. We are going to need a *complete* [mcve] to know what is going on (i.e. including your *background.js* and *modify_page.js* files, or at least enough of them to duplicate the problem. – Makyen Oct 02 '16 at 07:20

1 Answers1

0

I figured out the issue and solution. I forgot once the background script is open it stays open for the lifetime of the extension. Thus, the variables aren't reset. whatever variables need to be reset have to be reset manually. As for reloading the page, only the webpage is reloaded and not the code which needs to be restarted manually (sent to appropriate function) in response to a button, link, or whatever.

Danja
  • 1
  • 2