Notification.requestPermission(). So, here is a barebones and complete solution proving that you can get notifications to work on current (2019) Chrome for Android (Note: I used jQuery simply for brevity): Rather, you have to invoke the code in response to user interactivity like a click. That means that you can't simply invoke the notification when the document loads. Notifications are shown by running JavaScript on the user's device. This feature is often used with the Push API to inform the user of time-sensitive information, such as breaking news events or received messages. According to the Chrome debugger, the Notification API is only allowed in response to a user gesture. What are Notification Triggers Web developers can display notifications using the Web Notifications API. The answer above simply didn't work for me when I pasted it into a barebones page, but I discovered why. After much investigation, I can easily see why many people have had mixed results. I really wanted to prove the API could work for me on my current (2019) version of Chrome (70) for Android. I found documentation that seemed to indicate Chrome for Android was supported too, but it didn't work for me. It even worked without issues on Mobile FF. node_modules/.bin/web-push generate-vapid-keysġ // server.js 2 require ( 'dotenv' ).config( ` ) ġ4 font-family : "Roboto", "HelveticaNeue", "Helvetica Neue", Helvetica, Arial, sans-serif ġ // client/main.I had no trouble with the Notification API on Windows Desktop. You can generate the VAPID key pair by running the command below from the root of your project directory. VAPID keys are a pair of public and private keys which is used to restrict the validity of a push subscription to a specific application server, and also to identify the server that is sending the push notifications. The web-push library relies on a set of VAPID keys to work.
0 Comments
Leave a Reply. |