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."
function callback() { if (chrome.runtime.lastError) { console.log(chrome.runtime.lastError.message); } else { // Tab exists } } chrome.tabs.get(1234,callback);
source Chrome Extension error: "Unchecked runtime.lastError while running browserAction.setIcon: No tab with id"
Edit:
Chrome checks if the value of chrome.runtime.lastError was checked in a callback, and outputs a console message for this "unhandled async exception". If you do check it, it won't pollute the console.
From the comment by @Xan
If you love us? You can donate to us via Paypal or buy me a coffee so we can maintain and grow! Thank you!
Donate Us With