Empresas
Empregos
  • Sobre nós
  • Soluções
    • Publicação de vagas
      Publique sua vaga e receba candidatos qualificados em 48h.
    • Avaliações de candidatos
      Mais de 500 testes técnicos e psicológicos, mais anti-fraude.
    • Headhunting
      Busca executiva personalizada do início ao fim.
    • Folha de Pagamento + EOR
      Dispersão de folha e EOR em mais de 15 países da LATAM.
  • Preços
  • Empregos

0

239
Visualizações
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 à pergunta
Encontrar trabalhos remotos

Descubra a nova forma de encontrar um emprego!

melhores empregos
Principais categorias de trabalho
Empresas
Postar vaga Preços Comercial
Jurídico
Termos e Condições Política de privacidade
© 2026 PeakU Inc. All Rights Reserved.
Andres GPT
Recomende algumas ofertas para mim
Preciso de ajuda