Empresas
Empleos
  • Sobre nosotros
  • Soluciones
    • Publicación de vacantes
      Publica tu vacante y recibe candidatos calificados en 48h.
    • Evaluación de candidatos
      500+ pruebas técnicas y psicológicas, más anti-fraude.
    • Headhunting
      Búsqueda ejecutiva a la medida de principio a fin.
    • Nómina + EOR
      Dispersión de nómina y EOR en más de 15 países de LATAM.
  • Precios
  • Empleos

0

236
Vistas
Notification.requestPermission does not fire when it is automatically blocked by Chrome

So basically I have button which when clicked will trigger a call to Notification.requestPermission and depending on the users response I do some action.

The issue is that Notification.requestPermission does not actually fire when it is automatically blocked by Chrome.

This is my code

function askNotificationPermission(handler) {

    // checks to see if notification is actually supported
    function checkNotificationPromise() {
        try {
            // checks if promise based notification is okay
            Notification.requestPermission().then();
        } catch(e) {
            return false;
        }
        return true;
    }

    // Let's check if the browser supports notifications
    if (!('Notification' in window)) {
        console.log("This browser does not support notifications.");
    } else {

        if(checkNotificationPromise()) {
            window.console.log("requesting permission...")
            Notification.requestPermission()
                .then((permission) => {
                    window.console.log("PERMISSION", permission)
                    handler(permission);

                    window.console.log("finished handler")

                })

            window.console.log("done", Notification.permission)
        } else {
            Notification.requestPermission(function(permission) {
                handler(permission);
            });
        }
    }
}

Is there anyway to catch when notifications are automatically blocked?

about 4 years ago · Juan Pablo Isaza
Responde la pregunta
Encuentra empleos remotos

¡Descubre la nueva forma de encontrar empleo!

Top de empleos
Top categorías de empleo
Empresas
Publicar vacante Precios Comercial
Legal
Términos y condiciones Política de privacidad
© 2026 PeakU Inc. All Rights Reserved.
Andres GPT
Recomiéndame algunas ofertas
Necesito ayuda