Skip to content

Instantly share code, notes, and snippets.

@juliobitencourt
Created June 28, 2023 15:06
Show Gist options
  • Star 0 You must be signed in to star a gist
  • Fork 0 You must be signed in to fork a gist
  • Save juliobitencourt/b646c757e297745e57e7661b1eb98dc0 to your computer and use it in GitHub Desktop.
Save juliobitencourt/b646c757e297745e57e7661b1eb98dc0 to your computer and use it in GitHub Desktop.
Browser Desktop Notifications
export default async () => {
if (!window.Notification) {
console.log('Browser does not support notifications.')
return
}
if (Notification.permission === 'granted') {
const not = new Notification('Hi there', {
body: 'How are you doing?',
icon: 'https://cdn-icons-png.flaticon.com/512/4980/4980801.png'
})
return
}
await Notification.requestPermission(p => {
if (p === 'granted') {
new Notification('Hi there', {
body: 'How are you doing?',
icon: 'https://cdn-icons-png.flaticon.com/512/4980/4980801.png'
})
return
}
console.log('User blocked notifications')
})
}
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment