Notification permission dialog is not called in Chrome/firefox mobile

Asked

Viewed 49 times

0

I’m trying to make a notification using the Notification on Chrome/firefox mobile, however I cannot request permission for the user. I put a alert to show what is the current page notification permission, which is running from a server locally, and appears denied even though it did not show the dialogue requesting such permission.

I also checked the Chrome and firefox settings to see if it was configured there for Perguntar antes and both are ok. Also not in the list of blocked websites

In desktop browsers both Chrome and firefox run normally requesting permission if you don’t have it and triggering the notification if the permission is granted.

This here is the code I’m testing I took him from the mozzila Developers a little adapted for me to "debug" in mobile browser:

<button type="button" onclick="showNotification()">btn1</button>
<button type="button" onclick="mostrarNot()">btn2</button>
<script>
  navigator.serviceWorker.register('sw.js');

  function showNotification() {
    Notification.requestPermission(function(result) {
      alert("rapaz ate ta sendo chamado aqui")
      if (result === 'granted') {
        navigator.serviceWorker.ready.then(function(registration) {
          registration.showNotification('Vibration Sample', {
            body: 'Buzz! Buzz!',
            vibrate: [200, 100, 200, 100, 200, 100, 200],
            tag: 'vibration-sample'
          });
        });
      }
    });
  }
  
  function mostrarNot(){
    Notification.requestPermission().then(function(permission) { alert(permission)});
  }
</script>

He even enters the function of requesting the notification but gets there and already ta denied like I said. inserir a descrição da imagem aqui

  • 1

    This can happen in 3 situations: 1 - If it is in private tab; 2 - If permission has already been denied; 3 - If the site does not have SSL (works only with IP 127.0.0.1 or with the address localhost, even without ssl).

  • The situation 1 I have not tested, the situation 2 I do not remember denying, in which case how to proceed? is the situation 3 the server is running on 127.0.0.1 but I am accessing from my mobile on the local network.

  • I tested here using a notebook on the network and accessing the server and it does not really appear the dialog on the desktop, my problem probably fits in case 3- that the server does not have the ssl certificate. I’ll put an ssl certificate here in dev environment and test if it was

  • The dialogue has been resolved but the notification is not triggered. In addition, the page keeps this information that the page is not safe https://i.imgur.com/Wc8f4nx.png

  • If you are still testing from your notebook, try the following https://developers.google.com/web/updates/2015/05/notifying-you-of-changes-to-notifications

  • in case I want to send this notification in the background I will use the service worker, but in the mobile browser how would I do it? I tested the 'serviceWoker' in navigator and gave false

Show 1 more comment

1 answer

0


The problem was that I was trying to access within my local network and without the certificate does not work. The solution was to use the ngrook to expose the application via internet and access with his certificate.

Browser other questions tagged

You are not signed in. Login or sign up in order to post.