Sometimes there is tab Id stored in a variable and you need to check if tab still exists before doing something with it (because users can close tabs at any time). I've found this solution:
chrome.tabs.get(1234567, function(tab) {
if (typeof tab == 'undefined') {
console.log('Tab does not exist!');
}
});
It works but it has quite serious disadvantage. It writes error message into console like this:
Error during tabs.get: No tab with id: 1234567.
And this is not an exception. So try/catch can't help. It's just a message in console.
Any ideas?
UPDATE: This error now looks like "Unchecked runtime.lastError while running tabs.get: No tab with id: 1234567."
See Question&Answers more detail:
os 与恶龙缠斗过久,自身亦成为恶龙;凝视深渊过久,深渊将回以凝视…