UNPKG

@gravityforms/utils

Version:
34 lines (32 loc) 799 B
/** * @module checkNotificationPromise * @description Check if the browser's notification api supports promise based requests. * * @since 1.0.0 * * @return {boolean} Whether the browser supports promise based notifications or not. * * @example * import { checkNotificationPromise } from "@gravityforms/utils"; * * function Example() { * if ( checkNotificationPromise() ) { * window.Notification.requestPermission().then( ( permission ) => { * handlePermission(); * } ); * } else { * window.Notification.requestPermission( ( permission ) => { * handlePermission(); * } ); * } * }; * */ export default function checkNotificationPromise() { try { window.Notification.requestPermission().then(); } catch ( e ) { return false; } return true; }