Exactly when does the background script in a chrome extension get run?
up vote 0 down vote favorite In my chrome extension, I have a background script that will fetch some data that it will need using a XMLHttpRequest . // note that this code is in the global scope i.e. outside of any function // also note that I got this code from the page talking about XMLHttpRequest var myData = var xhr = new XMLHttpRequest() xhr.onreadystatechange = handleStateChange xhr.open("GET", "...", true) xhr.send() function handleStateChange() myData = Object.values(JSON.parse(xhr.responseText)) I want to know when will xor.send() be run. I observed that every time I reload the extension by pressing on the button, xhr.send() will be called. I also observed that opening a new tab/window doesn't cause the background script to be run again. I also found this page, that the background page gets "loaded" and "unloaded", but it says very little about when the code in the global scope of the background script is run. Does ...