browser-unhandled-rejection

Run browser and node tests with coverage reports

Downloads in past

Stats

StarsIssuesVersionUpdatedCreatedSize
browser-unhandled-rejection
2871.0.25 years ago6 years agoMinified + gzip package size for browser-unhandled-rejection in KB

Readme

browser-unhandled-rejection
!build statusbuild-badgebuild-href !dependencies statusdeps-badgedeps-href !npm versionnpm-badgenpm-href
A ponyfill/polyfill for browser Promise unhandledrejection events.
See: https://www.chromestatus.com/features/4805872211460096
!sauce labs test statussauce-badgesauce-href

Install

npm i browser-unhandled-rejection
or
yarn add browser-unhandled-rejection

Usage

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.Promise

Manual 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');
});