Skip to content

Instantly share code, notes, and snippets.

@jotapeluiz
Created March 22, 2019 04:07
Show Gist options
  • Select an option

  • Save jotapeluiz/056a755e37544ce738a4b5c7f047f8bd to your computer and use it in GitHub Desktop.

Select an option

Save jotapeluiz/056a755e37544ce738a4b5c7f047f8bd to your computer and use it in GitHub Desktop.
const messaging = firebase.messaging();
messaging.onMessage(function(payload) {
if (!("Notification" in window)) {
console.warn("Este navegador não suporta notificações de desktop");
} else {
const data = JSON.parse(payload.data.notification);
const notification = new Notification(data.title, data);
notification.onclick = function(event) {
event.preventDefault();
window.open(data.click_action, "_blank");
this.close();
}
}
});
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment