Here is my code in a content script, with MV3:
var checkVariable;
chrome.storage.sync.get('mykey', function(result) {
checkVariable = result.mykey;
alert ("1: " + checkVariable);
});
alert ("2: " + checkVariable);
if (checkVariable === true) {
// Various stuff
}
The second alert message executes first and returns undefined then the first alert executes returning, the correct value. The problem is that the if condition also executes before retrieving the correct value from storage.
What's the way to run this sequentially?