title: chrome extension onInstalled event
body: <p>I have a question about chrome extension install/update event. If I add the onInstalled event listener in a top level code in the background script, is there a time frame in which my event listener will catch that event?</p>
  
  <p>I'm asking this, because my demos showed that if I have some logic that executes before I hook onInstalled listener, it looks like it will never be executed, like that event happens in the meantime. </p>
  
  <p>Can someone explain to me with more details how this event works, in the context of other logic in the background script, or point me to some documentation, since I haven't been able to find anything useful. </p>
  
  <p>Thanks! </p>
  
  <p>Update @Noam Hacker : Due to a company policy I can't post any real code here, but I have some pseudo code that illustrates my problem :</p>
  
  <pre><code>/**
   * setup in which I miss onInstalled event
   */
  function firstLogicThatRunsOnBackgroundLoad() {
      // perform some logic
  
      // perform some asynchronous operations via generators and promises
      // which can take a while
  
      chrome.runtime.onInstalled.addListener(function (details) {
              if (details.reason == "install") {
                  // this logic never gets executed
              } else if(details.reason == "update") {
                  // perform some logic
              }
          });
  }
  
  /**
   * setup in which I catch onInstalled event 
   */
  function firstLogicThatRunsOnBackgroundLoad() {
      chrome.runtime.onInstalled.addListener(function (details) {
              if (details.reason == "install") {
                  // this logic executes
              } else if(details.reason == "update") {
                  // perform some logic
              }
          });
  
      // perform some logic
  
      // perform some asynchronous operations via generators and promises
      // which can take a while
  }
  </code></pre>