title: Listening to an event from my greasemonkey script
body: <p>I'm trying to figure out how to listen to an event emitter from my greasemonkey script, but I keep getting access violation errors (<code>Permission denied to access object</code>).</p>
  
  <p><strong>Page</strong><br>
  The page contains a simple event emitter:</p>
  
  <pre class="lang-js prettyprint-override"><code>var emitter = function(){
      this.events = {};
  }
  
  emitter.prototype.on = function(eventName, closure){
      this.events[eventName] = this.events[eventName] || [];
      this.events[eventName].push(closure);
  };
  
  emitter.prototype.emit = function(eventName, data){
      if(this.events[eventName]){
          this.events[eventName].forEach(function(fn){
              return fn(data);
          });
      }
  }
  
  var test = new emitter();
  test.emit('test', {data:'test'});
  </code></pre>
  
  <p><strong>Script</strong><br>
  This throws an access violation error (this used to work a while ago, but I guess it got patched or something):</p>
  
  <pre><code>unsafeWindow.test.on('test', function(data){
      console.log(data);
  });
  </code></pre>