Fix emit events on 'window' and 'document' objects