I'm trying to create an extension for chrome browser that'll display the battery level of the system (and do couple other stuff) with the BatteryStatusAPI. At first I'm just trying to display the battery level using simple canvas, but it doesn't seem to work.
manifest:
{
"manifest_version": 2,
"name": "Battery",
"description": "This extension shows the battery stats of the current device.",
"version": "1.0",
"browser_action": {
"default_icon": "battery_full.png",
"default_title": "Click Here!"
},
"background": {
"scripts": ["icon_changer.js"]
}
}
JavaScript:
var battery;
navigator.getBattery()
.then(function (b) {
battery = b;
}
);
function drawIcon() {
var clockCanvas = document.createElement("canvas");
clockCanvas.height = 19;
clockCanvas.width = 19;
var clockContext = clockCanvas.getContext("2d");
clockContext.textAlign = "center";
clockContext.textBaseline = "middle";
clockContext.font = "9px Arial";
clockContext.fillText(battery.level, 9, 10);
chrome.browserAction.setIcon({
imageData: clockContext.getImageData(0, 0, 19, 19)
});
}
drawIcon();
What do you think the problem is?