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

232
Visualizações
Using Notifications API in an IFrame [chrome, javascript]

I'm trying to write a plugin for a website, the website always loads this plugin as an iframe. I would like to send browser notifications to the user, using this api: https://developer.mozilla.org/en-US/docs/Web/API/Notification/requestPermission Only problem is the API doesn't seem to support asking permission from an iframe.

Is there any way I can make this work? I also tried this solution: How subscribe pushManager via iframe in Chrome?)

"The only alternative (that we have used for Pushpad Express for example) is to redirect to open a new window from the iframe, then ask permission from the top level window and finally redirect back." and asking the permission from there, but it never asks me for permission, so the value stays denied.

Unfortunately that also doesn't seem to work for me, I open a new windows and ask for permission but it also just never shows the request.

Does anybody have some other ideas?

Edit 1:

I am trying to do it this way now:, it opens a new window but still no luck with asking the permission:

function openAndPush() {
    var win = window.open("", "", "width=400,height=400");
    win.test = function () {
        askNotificationPermission();
    }
    win.test();
    setTimeout(function () {
        win.document.body.appendChild(element);
        console.log('New script appended!')
    }, 10000);
}

Edit 2: Got the code working by asking permission in a new window, it executes this piece of code:

if (Notification.permission === "granted") {
        console.log("[App] @!@@!!@!@!@!@!@!@!@")
        var notification = new Notification("Hi there!");
    }

Which means permissions are granted, but I'm still not seeing a desktop notification. Website is https, chrome settings checked, and no errors. Anybody got a suggestion?

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