How to catch errors with chrome.browserAction.setBadgeText()

45 views
Skip to first unread message

thdoan

unread,
Apr 17, 2018, 6:09:53 PM4/17/18
to Chromium-Extensions-Announce
Most browserAction methods allow me to catch errors such as invalid tab id by checking for chrome.runtime.lastError in the callback -- with the exception of chrome.browserAction.setBadgeText(), which doesn't accept callbacks. With this limitation, how do you guys catch invalid tab ids for chrome.browserAction.setBadgeText()?

To be consistent, I propose making this method return a Promise object as well (similar to setIcon() and other methods) so we can better catch such errors.

wOxxOm

unread,
Apr 18, 2018, 10:13:36 AM4/18/18
to Chromium-Extensions-Announce
Currently there's no reliable way to do so. You can verify the tab id exists using chrome.tabs.get and hope it won't become invalid (closed/replaced) during the call to setBadgeText, but even so it's far from being 100% reliable.

Chrome 67 adds callbacks to all pageAction/browserAction/action methods.

There are no concrete plans for Promises yet so simply continue using a third-party library like Mozilla's WebExtension polyfill.

thdoan

unread,
Apr 18, 2018, 4:46:24 PM4/18/18
to Chromium-Extensions-Announce
Thanks wOxxOm, v67 cannot come soon enough!
Reply all
Reply to author
Forward
0 new messages