javascript - Can you "plug in" to unhandled Promise rejections in Chrome? -


this question has answer here:

a while back, v8 gained capability detect promises rejected have no handlers attached (commit). landed in chrome nice console error, useful when you've made typo or forget attach handler:

example of chrome reporting rejected promise handlers

i add handler take action (e.g., reporting error reporting service) when happens, similar uncaught exception pattern:

window.addeventlistener("error", handler); 

alternatively, i'm looking mechanism can use automatically invoke sort of callback when promise rejected not handled on tick.

until window.addeventlistener('unhandledrejection', e => ...) here may hack own promise constructor creates original promise , calls catch on passing:

error => {   var errorevent = new errorevent('error', {     message: error.message,     error: error   });   window.dispatchevent(errorevent); // error listeners.   throw error; // prefer see errors on console. } 

but seems have patch then, catch , promise.reject -- lots of work.

someone may want write polyfill emit custom unhandledrejection event in such cases.


Comments