Reputation: 1
I need to set a text at top of icon buts coming down as of now. I am using using setbadgetext in chrome extension as follows
chrome.tabs.executeScript(tabId, {code: chrome.browserAction.setBadgeText ( { text: 'hi' } )}, function() {
});
So the text hi appear to the bottom right of extension icon.i want it at the top.
Please suggest.Any js hack or chrome additions welcome.
Upvotes: 0
Views: 1727
Reputation: 31131
You can't adjust the position of the text in the badge.
You will need to draw an icon on the fly (canvas) with text in the proper place and set it dynamically.
From the chrome.browserAction docs:
ImageDataType
( imagedata ) Pixel data for an image. Must be an ImageData object (for example, from a canvas element).
Example from Dynamic Chrome Extension Icons:
var canvas = document.getElementById('canvas');
var context = canvas.getContext('2d');
// ...draw to the canvas...
var imageData = context.getImageData(0, 0, 19, 19);
chrome.browserAction.setIcon({
imageData: imageData
});
Also see Drawing text using a canvas
Upvotes: 2