Logo Questions Linux Laravel Mysql Ubuntu Git Menu
 

Can an ember(-cli) app trigger window.onerror?

Is there any kind of javascript error that is not handled by onerror in an ember(-cli) application? In other terms, is there any need to add a handler to window.onerror?

In my tests I could not come up with any error that would no be handled by Ember's onerror. Syntax errors didn't get past ember-cli's build process.

like image 980
pogopaule Avatar asked Jan 29 '16 15:01

pogopaule


1 Answers

EmberJS does an excellent job of containing errors that happen within its boundaries. Errors caused by your Ember code should all get funneled into the Ember-specific handler.

However, browser JavaScript is a complicated beast. Any JavaScript errors that happen outside of Ember would not be captured internally and may only be exposed by the global window.onerror. Some examples of these could include:

  • Unbounded callbacks into native functions like setTimeout and addEventListener
  • Non-ember JavaScript libraries and integrations, such as Stripe, Twitter, or Advertisements
  • Browser-extension script that can interact with the DOM in unpredictable ways.

To get a complete picture of what is happening with your visitors, you should probably attach to both Ember.onerror and window.onerror and send the reports back to your logs. Even if you are not actively developing, browser changes can cause sudden bugs to appear in your application. Like this webkit bug that caused ember to throw errors. There are good options to record errors automatically from Ember apps, like TrackJS.

Disclosure: I am one of the founding developers of TrackJS, so I've debugged a lot of errors :)

like image 81
Todd Gardner Avatar answered Sep 30 '22 13:09

Todd Gardner