Contents

Notification

A notification that can be displayed to the user.

import { Notification } from '@mobrowser/api';

Example 

import { Notification } from '@mobrowser/api';

const notification = new Notification({
  title: 'Hello',
  body: 'This is a notification.',
  icon: app.getPath('appResources') + '/notification.png'
})
notification.on('clicked', () => {
  console.log('Notification clicked')
})
notification.show()

Methods 

constructor() 

constructor(options: NotificationOptions): void;

Creates a new notification.

ParameterTypeDescription
optionsNotificationOptionsThe options for constructing the notification.

show() 

show(): void;

Displays the notification. If the notification was previously fired, the old notification is hidden and a new one is shown.

Example 

import { Notification } from '@mobrowser/api';

const notification = new Notification({ title: 'Hello', body: 'World' })
notification.show()

dismiss() 

dismiss(): void;

Programmatically dismisses the notification. This method removes the notification from the Notification Center on macOS, Action Center on Windows, and the System Notification area on Linux.

It’s safe to dismiss a notification, and then invoke the show() method.

Example 

import { Notification } from '@mobrowser/api';

const notification = new Notification({ title: 'Hello', body: 'World' })
notification.show()
setTimeout(() => notification.dismiss(), 3000)

Events 

‘displayed’ 

on(event: 'displayed', listener: () => void): void;
off(event: 'displayed', listener: () => void): void;

Emitted when the notification is displayed to the user.

Example 

import { Notification } from '@mobrowser/api';

const notification = new Notification({ title: 'Hello', body: 'World' })
notification.on('displayed', () => {
  console.log('Notification displayed')
})
notification.show()

‘replyReceived’ 

on(event: 'replyReceived', listener: (reply: string) => void): void;
off(event: 'replyReceived', listener: (reply: string) => void): void;

Emitted when the user replies to the notification via the inline reply field. The reply: may contain empty strings. Normalize with trim() and ignore empty strings if that matches your product rules.

Example 

import { Notification } from '@mobrowser/api';

const notification = new Notification({
  title: 'New message',
  hasReply: true,
  replyPlaceholder: 'Type a reply…'
})
notification.on('replyReceived', (reply: string) => {
  console.log('User replied:', reply)
})
notification.show()

‘clicked’ 

on(event: 'clicked', listener: () => void): void;
off(event: 'clicked', listener: () => void): void;

Emitted when the user clicks the notification body.

Example 

import { Notification } from '@mobrowser/api';

const notification = new Notification({ title: 'Hello', body: 'World' })
notification.on('clicked', () => {
  console.log('Notification clicked')
})
notification.show()

‘dismissed’ 

on(event: 'dismissed', listener: (reason: NotificationDismissalReason) => void): void;
off(event: 'dismissed', listener: (reason: NotificationDismissalReason) => void): void;

Emitted when the notification is dismissed by the user or the system. Query the reason: to see the dismissal reason.

Example 

import { Notification, NotificationDismissalReason } from '@mobrowser/api';

const notification = new Notification({ title: 'Hello', body: 'World' })
notification.on('dismissed', (reason: NotificationDismissalReason) => {
  console.log('Notification dismissed:', reason)
})
notification.show()

‘failed’ 

on(event: 'failed', listener: (error: string) => void): void;
off(event: 'failed', listener: (error: string) => void): void;

Emitted when the notification fails to be displayed. The error: contains a human-readable description of the failure.

Example 

import { Notification } from '@mobrowser/api';

const notification = new Notification({ title: 'Hello', body: 'World' })
notification.on('failed', (error: string) => {
  console.error('Notification failed:', error)
})
notification.show()