No, there’s no limitation of a surrounding closure type or anything like that in Javascript.
As far as I can tell this code should do the trick.
/*...*/
.done(function(data) {
if(data._total > 0) {
chrome.browserAction.setBadgeText({ text: 'On' });
}
});
But the issue may be that it needs to be run in the background.js instead of popup.js assuming that popup.js isn’t the background script and you have a background.js.