I'm trying to set the badge text for my chrome extension with the code below:
chrome.pageAction.setBadgeText({"text":'3'})
This throws an error Object #<Object> has no method setBadgeText
.
Description. Use browser actions to put icons in the main Google Chrome toolbar, to the right of the address bar. In addition to its icon, a browser action can have a tooltip, a badge, and a popup.
A browser action is a button that your extension adds to the browser's toolbar. The button has an icon, and may optionally have a popup whose content is specified using HTML, CSS, and JavaScript.
I have used the canvas feature to get the same result. Here the code that i used.
window.setInterval(function() {
chrome.pageAction.setIcon({imageData: draw(10, 0), tabId: tabId});
}, 1000);
function draw(starty, startx) {
var canvas = document.getElementById('canvas');
var context = canvas.getContext('2d');
var img = new Image();
img.src = "icon_16.png"
img.onload = function () {
context.drawImage(img,0,2);
}
//context.clearRect(0, 0, canvas.width, canvas.height);
context.fillStyle = "rgba(255,0,0,1)";
context.fillRect(startx % 19, starty % 19, 10, 10);
context.fillStyle = "white";
context.font = "11px Arial";
context.fillText("3",0,19);
return context.getImageData(0, 0, 19, 19);
}
here you can chage the positon and color of text you want to show.
No, it is not possible with page actions
But it is possible with browser actions.
Excerpt:
page action docs
Parts of the UI Like browser actions, page actions can have an icon, a tooltip, and popup; they can't have badges, however. In addition, page actions can be grayed out. You can find information about icons, tooltips, and popups by reading about the browser action UI.
What you can do is to replace the current image with another that has a badge included in the image.
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