title: Debugging $apply already in progress
body: <p>I'm developing a Chrome Extension using AngularJS (so it is running in CSP mode). amServices.js contains a service that deals with Chrome native messaging. So at js/core/am/amServices.js:268:20 the relevant code is as follows:</p>
  
  <pre><code>chrome.runtime.onMessage.addListener(
    function (message, sender, sendResponse) {
      $rootScope.$apply(function () {
        if (message.type == 'login' &amp;&amp; message.state == 'ok') {
  //huge if/else if here for every kind of message
  </code></pre>
  
  <p>My understanding is that as all the code inside here is getting called asynchronously and can trigger modifications in most of the application views, $rootScope.$apply is mandatory. However, in what seems a totally random way, I sometimes get these in the console:</p>
  
  <pre><code>Error: [$rootScope:inprog] http://errors.angularjs.org/1.2.13/$rootScope/inprog?p0=%24apply
      at Error (native)
      at chrome-extension://hbfchfkepmidgcdfcpnodlnmfjhekcom/lib/angular/angular.min.js:6:450
      at n (chrome-extension://hbfchfkepmidgcdfcpnodlnmfjhekcom/lib/angular/angular.min.js:98:34)
      at h.$apply (chrome-extension://hbfchfkepmidgcdfcpnodlnmfjhekcom/lib/angular/angular.min.js:104:195)
      at chrome-extension://hbfchfkepmidgcdfcpnodlnmfjhekcom/js/core/am/amServices.js:268:20
      at Function.target.(anonymous function) (extensions::SafeBuiltins:19:14)
      at Event.dispatchToListener (extensions::event_bindings:394:22)
      at Event.dispatch_ (extensions::event_bindings:378:27)
      at Event.dispatch (extensions::event_bindings:400:17)
      at messageListener (extensions::messaging:192:31) 
  </code></pre>
  
  <p>No what bugs me about it is the fact that, unlike what is explained here:</p>
  
  <p><a href="https://stackoverflow.com/questions/20805534/why-doesnt-angular-ignore-subsequent-digest-invocations">Why doesn&#39;t Angular ignore subsequent $digest invocations?</a></p>
  
  <p>In my stack trace I'm not seeing two $apply calls, so I have no way to know where the conflic comes from. Additionally, I can't run AngularJS Batarang debug tool, as it doesn't work with CSP mode. </p>
  
  <p>I'm ignoring these errors without any apparent consequences, but I'm unsure wheter it really is safe to ignore them. Any ideas on how to know which two apply calls triggered the conflict?</p>