@@ -129,22 +129,39 @@ window.scriptObserver = new MutationObserver(callback);
129129// Start observing the target node for configured mutations
130130window . scriptObserver . observe ( mainScripts , config ) ;
131131
132+ let Metrics = null ;
133+
132134window . onerror = function ( msg , url , line , ...err ) {
133135 console . error ( "Caught Critical error from: " + url + ":" + line + " message: " + msg , ...err ) ;
136+ if ( Metrics ) {
137+ Metrics . countEvent ( Metrics . EVENT_TYPE . ERROR , "uncaught" , "main.js" ) ;
138+ }
134139 return true ; // same as preventDefault
135140} ;
136141
142+ window . addEventListener ( "unhandledrejection" , function ( event ) {
143+ console . error ( "Caught unhandledrejection from: " , event ) ;
144+ if ( Metrics ) {
145+ Metrics . countEvent ( Metrics . EVENT_TYPE . ERROR , "unhandled" , "rejection" ) ;
146+ }
147+ return true ; // same as preventDefault
148+ } ) ;
149+
137150define ( function ( require ) {
138151
139152
140153 // Load compatibility shims--these need to load early, be careful moving this
141154 // Event dispatcher must be loaded before worker comm https://github.com/phcode-dev/phoenix/pull/678
142- require ( [ "utils/Compatibility" , "utils/EventDispatcher" ] , function ( ) {
155+ require ( [ "utils/Metrics" , "utils/Compatibility" , "utils/EventDispatcher" ] , function ( ) {
156+ Metrics = require ( "utils/Metrics" ) ;
143157 // Load the brackets module. This is a self-running module that loads and runs the entire application.
144158 try {
145159 require ( [ "brackets" ] ) ;
146160 } catch ( e ) {
147161 console . error ( 'Critical error when loading brackets. Trying to reload again.' ) ;
162+ if ( Metrics ) {
163+ Metrics . countEvent ( Metrics . EVENT_TYPE . ERROR , "loadErr" , "reload" ) ;
164+ }
148165 window . location . reload ( ) ;
149166 }
150167 } ) ;
0 commit comments