I currently have quite the predicament. An if statement I have written – which evaluates to true – is not being executed. The execution continues to the else. I’ll include a piece of the code in hopes that it will aid in determining what’s going on.
I’m building a google chrome extension, and my popup.html is making a request to my content script, which is returning some values. After this I use the variables obtained to perform the if statement logic.
var timer;
var status;
chrome.tabs.getSelected(null, function(tab)
{
chrome.tabs.sendRequest(tab.id, {method : 'GetTimer'},
function(response)
{
timer = response.Timer;
});
chrome.tabs.sendRequest(tab.id, {method : 'GetStatus'},
function(response)
{
status = response.Status;
});
});
// here is where the issue is occuring
if (status && status === bg.StopText)
{
}
When I breakpoint on the if statement itself, I can see that status is equal to “Stop”, and bg.StopText is also equal to “Stop”. Furthermore, when I copy
status && status === bg.StopText
into my console and execute it, the result is true.
Can anyone see if there is an issue I’m glossing over, and possibly some steps I could take to troubleshoot this further?
You have a race condition. If you send request, you can’t check status until the request returns, it’s asynchronous. When you pause execution, it allows time for the async call to complete and looks like you have a value already.