title: How to get Chrome Extension chrome.alarms firing consistently
body: <p>I'm seeing some inconsistency with the chrome.alarms api for a chrome extension that I can't quite make sense of.</p>
  
  <p><strong>Background</strong></p>
  
  <p>I'm creating an alarm that is to fire every day at 9:30am, however it doesn't fire anywhere near 9:30am. When it does, it appears to be when I've 'woken' up the extension, either by interacting with the popup, or toggle enable/disable on the extension. I don't see any consistency, else I would be thinking it's a timezone issue of some sort.</p>
  
  <p>I've verified that the alarms are indeed set, and set for the correct time. In the popup I'm doing a simple <code>chrome.alarms.getAll</code> and dumping out all the alarms &amp; their times.</p>
  
  <p>So everything seems to be set correctly and ready to go, but then they sadly don't fire even, 1 full day after the time they were set for.</p>
  
  <p><strong>My Thoughts</strong></p>
  
  <p>The only thing I can figure is the <code>background.js</code> is being <a href="https://developer.chrome.com/extensions/event_pages#lifetime" rel="nofollow noreferrer">unloaded as it isn't "needed"</a>. But in theory the <a href="https://developer.chrome.com/extensions/event_pages#transition" rel="nofollow noreferrer">alarms Api should load background.js</a> back up when they fire.</p>
  
  <p>It's also possible I need to add <code>"background": { "persistent": false }</code> explicitly to my <code>background.js</code>? Or maybe I should bite the bullet and say <code>true</code>... but ideally it shouldn't be persistent I would think.</p>
  
  <p>How do I get my alarms to be consistent and behave as I expect them, firing at 9:30am?</p>
  
  <p><strong>Files</strong></p>
  
  <p>background.js</p>
  
  <pre><code>// Create alarm when receiving an onMessage with 'createAlarm'
  chrome.runtime.onMessage.addListener(function(request, sender, sendResponse){
      if(request.action == 'createAlarm') {
          chrome.alarms.create('MyAlarm', {
              when: moment().hour(9).minute(30).unix() * 1000
          });
      }
  });
  
  // onAlarm, create notification
  chrome.alarms.onAlarm.addListener(function(alarm) {
      chrome.notifications.create({
          type: 'basic',
          iconUrl: 'images/icon-128.png',
          title: 'Hello World!',
          message: 'I am a notification!'
      });
  });
  </code></pre>
  
  <p>manifest.json</p>
  
  <pre><code>{
      ...
      "background": {
          "scripts": [
              "bower_components/moment/min/moment.min.js",
              "scripts.es5/background.js"
          ]
      },
      "permissions": [
          ...
          "background",
          "notifications",
          "alarms"
      ]
  }
  </code></pre>
  
  <p>Related: <a href="https://stackoverflow.com/questions/17727734/how-to-use-chrome-alarms-for-google-chrome-extension">How to use chrome.alarms for Google Chrome extension</a></p>