Suppose I have the following code on my Chrome extension base page.
var opts; chrome.storage.local.get(options, function(result) { opts = result[options]; }); chrome.runtime.onMessage.addListener(function(request, sender, response) { if (request.message === 'getOpts') response(opts); });
In my script content, I access opts when sending messages.
chrome.runtime.sendMessage({'message': 'getOpts'}, function(response) { console.log(opts); });
Is there any guarantee that options will be determined before the contents of the script are run? For example, when the browser starts, the background page will be executed, and, presumably, the callback to chrome.storage.local.get will be added to the message queue of the background page. Is Chrome ready to end this queue before entering content scripts?
I could call chrome.storage.local.get from the contents of the script, but my question is more general, since I have additional processing of asynchronous messages on my background page. At the moment, my content script is checking the source page to make sure everything is ready (using the interval to check), but I'm not sure if such checks are needed.
source share