utils/notify.js
async function notify({ title, message, icon = 'default', timeout, }) { try {
	if (!Notifications) { console.info('notify', arguments[0]); return false; }
	const create = !open; open = true; const options = {
		type: 'basic', title, message,
		iconUrl: (/^\w+$/).test(icon) ? (await getIcon(icon)) : icon,
	}; !isGecko && (options.requireInteraction = true);
	try { (await Notifications[create || isGecko ? 'create' : 'update'](
		'web-ext-utils:notice', options,
	)); } catch (_) { open = false; throw _; }
	clearNotice(timeout == null ? -1 : typeof timeout === 'number' && timeout > 1e3 && timeout < 30 ** 2 ? timeout : 5000);
	onhide && onhide(); onclick = onhide = null;
	return new Promise(done => { onclick = () => done(true); onhide = () => done(false); });
} catch (_) { try {
	console.error(`failed to show notification`, arguments[0], _);
} catch (_) { } } return false; }
async function notify({ title, message, icon = 'default', timeout, }) { try {
	if (!Notifications) { console.info('notify', arguments[0]); return false; }
	const create = !open; open = true; const options = {
		type: 'basic', title, message,
		iconUrl: (/^\w+$/).test(icon) ? (await getIcon(icon)) : icon,
	}; !isGecko && (options.requireInteraction = true);
	try { (await Notifications[create || isGecko ? 'create' : 'update'](
		'web-ext-utils:notice', options,
	)); } catch (_) { open = false; throw _; }
	clearNotice(timeout == null ? -1 : typeof timeout === 'number' && timeout > 1e3 && timeout < 30 ** 2 ? timeout : 5000);
	onhide && onhide(); onclick = onhide = null;
	return new Promise(done => { onclick = () => done(true); onhide = () => done(false); });
} catch (_) { try {
	console.error(`failed to show notification`, arguments[0], _);
} catch (_) { } } return false; }
async function notify ( { title , message , icon = 'default' , timeout , } ) { try { if ( ! Notifications ) { console . info ( 'notify' , arguments [ 0 ] ) ; return false ; } const create = ! open ; open = true ; const options = { type : 'basic' , title , message , iconUrl : ( / ^\w+$ / ) . test ( icon ) ? ( await getIcon ( icon ) ) : icon , } ; ! isGecko && ( options . requireInteraction = true ) ; try { ( await Notifications [ create || isGecko ? 'create' : 'update' ] ( 'web-ext-utils:notice' , options , ) ) ; } catch ( _ ) { open = false ; throw _ ; } clearNotice ( timeout == null ? - 1 : typeof timeout === 'number' && timeout > 1e3 && timeout < 30 ** 2 ? timeout : 5000 ) ; onhide && onhide ( ) ; onclick = onhide = null ; return new Promise ( done => { onclick = ( ) => done ( true ) ; onhide = ( ) => done ( false ) ; } ) ; } catch ( _ ) { try { console . error ( ` ` , arguments [ 0 ] , _ ) ; } catch ( _ ) { } } return false ; }
Displays a basic notification to the user.
@param  {string}   .title    Notification title.
@param  {string}   .message  Notification body text.
@param  {string}   .icon     Notification icon URL or one of [ 'default', 'info', 'warn', 'error', 'success', ]
to choose and/or generate an icon automatically.
@param  {natural?} .timeout  Timeout in ms after which to clear the notification.
@return {boolean}            Whether the notification was clicked or closed (incl. timeout).
Displays a basic notification to the user .