title: Get battery level JavaScript
body: <p><strong>/!\ THE USE OF window.navigator.battery <a href="https://developer.mozilla.org/en-US/docs/Web/API/Navigator/battery#Quick_Links" rel="noreferrer">IS STRONGLY DISCOURAGED</a> AND THIS ISSUE IS NOW NOT WORTH CHECKING THANK YOU /!\</strong></p>
  
  <p>I want to get the battery level of the current system. Here is the output I intend to get:</p>
  
  <p><strong>If desktop (no battery)</strong>
  Battery level : 100%</p>
  
  <p><strong>If laptop</strong>
  Battery level : XXX% (depending the level)</p>
  
  <p>So I tried the snippet of the Mozilla Foundation over <a href="https://developer.mozilla.org/en/docs/Web/API/Navigator/battery" rel="noreferrer"><code>window.navigator.battery</code></a> in my <strong><a href="https://jsfiddle.net/" rel="noreferrer">JSFiddle</a></strong>.</p>
  
  <p><strong>The problem :</strong> Running Chrome 20+ version (currently 46), I still have an error on the console :</p>
  
  <blockquote>
    <p>Uncaught TypeError: Cannot read property 'addEventListener' of undefined</p>
  </blockquote>
  
  <p>So what I understand is the object <code>battery</code> instantiated with the supposed battery level is returning nothing.</p>
  
  <p>Did someone figured this out already ?</p>
  
  <p><em>The point of my algorithm when this snippet works is to define which action the user cannot perform regarding the remaining battery level. For example, I don't want the user to engage a heavy action that could probably lower his battery level to a critical point and make the critical action fail.</em></p>