1

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?

davyioner
  • 111
  • 1
  • 9

1 Answers1

0

Turns out this works, but I had browser notifications disabled on my Windows system. Hope this helps someone who wastes a day on the same problem!

You can find the setting under Notifications&Actions:

locd

davyioner
  • 111
  • 1
  • 9