Package Exports
- browser-unhandled-rejection
This package does not declare an exports field, so the exports above have been automatically detected and optimized by JSPM instead. If any package subpath is missing, it is recommended to post an issue to the original package (browser-unhandled-rejection) to support the "exports" field. If that is not possible, create a JSPM override to customize the exports field for this package.
Readme
browser-unhandled-rejection
A ponyfill/polyfill for browser Promise unhandledrejection events.
See: https://www.chromestatus.com/features/4805872211460096
Install
npm i browser-unhandled-rejectionor
yarn add browser-unhandled-rejectionUsage
Automatic polyfill
This automatically applies the polyfill to the global Promise object if it is needed.
import {auto} from 'browser-unhandled-rejection';
auto(); // Applies polyfill if necessary to window.PromiseManual polyfill
The following snippet is equivalent to auto():
import {polyfill} from 'browser-unhandled-rejection';
if (typeof PromiseRejectionEvent !== 'undefined') {
polyfill(); // Polyfills window.Promise
}Ponyfill
This may may useful if you don't want to mutate window.Promise:
import MyPromise from 'browser-unhandled-rejection';
window.addEventListener('unhandledrejection', () => {
console.log('unhandledrejection was triggered');
});
MyPromise.reject('will trigger unhandledrejection event');
new MyPromise((resolve, reject) => {
reject('will also trigger unhandledrejection event');
});