I use chrome.browserAction.setBadgeText to add an icon to my extension browser icon that shows the number of tasks in the user's task list.

At that moment, when the user has zero tasks, I get the following:

However, I would prefer not to show the icon at all when the user has zero tasks.
Here is my code:
setBrowserActionBadge: function(allTasks) { var task_count; task_count = allTasks.filter(function(task) { task.isDone === false; }).length; task_count = task_count.toString(); if (task_count === 0) { task_count = ''; } chrome.browserAction.setBadgeText({ 'text': task_count }); chrome.browserAction.setBadgeBackgroundColor({ 'color': '#333333' }); };
This method runs every time tasks are checked or added, so it is updated in real time.
What would be ideal is something like chrome.browserAction.clearBadge , which I can run when the number of tasks is 0 to remove the icon.
javascript google-chrome google-chrome-extension
Benjamin humphrey
source share