0

I have a minix ks controller which is working from plug and doesn't have a battery. However I'm getting battery data from JS navigator object:

enter image description here

This is what I'm getting from getBattery method:

enter image description here

But I need to detect there is no battery in the device to not show battery indicator on the screen. Is there any way in JS to detect there is no battery at all?

Olga
  • 119
  • 1
  • 1
  • 12
  • That's not the format of what `getBattery` returns. How are you getting the battery status? – Tom Mar 30 '22 at 09:34
  • updated the post with object I'm getting in navigator – Olga Mar 30 '22 at 10:13
  • @Olga That seems to be wrong, which browser are you using? `navigator.getBattery` returns a promise and also navigator does not have a battery property anymore (Chrome v99.0.4844.84). The battery propety was deprecated. `getBattery` gives you access to `[charging]: boolean`, `[chargingTime]: number`, `[dischargingTime]: number` and `[level]: number`. – Palladium02 Mar 30 '22 at 10:30
  • I added one more picture on the object returned by getBattery() – Olga Mar 30 '22 at 10:43
  • @Olga Ah ok, it seems like you are using an older version of a browser. You could make a guess based on the chargingTime property which defaults to 0 if the device cannot provide the information. But I am not sure if that is a 100% accurate way of doing it as there might be a different reason for why the charging time was not provided by the device e.g. missing permission. https://www.w3.org/TR/battery-status/#the-batterymanager-interface – Palladium02 Mar 30 '22 at 10:46
  • 1
    Reading the BatteryManager MDN docs, they say if there is no battery the `level` defaults to 1. – Tom Mar 31 '22 at 08:00

0 Answers0