Chrome Desktop push notifications sound not working

I'm trying to play a sound in a push notification in Chrome Desktop. I have set the browser push notification on my site but it will not play the sound. I'm already passing the option for sound.

option = {
     'body' : 'This is tst Description',
     'icon' : 'icon.png',
     'silent' : 'false',
     'sound' : 'bell.mp3'
}

If there is another way to play a notification sound please let me know.


目前浏览器不支持Notification.sound,请参阅https://developer.mozilla.org/en/docs/Web/API/notification


You can try to use the chrome web-extension background_pages.

It will listen to the service worker and play the audio The simple method for it would be to requesting the URL in the service worker and capture it in the background script using the chrome.webRequest as mentioned in the link

chrome.webRequest.onBeforeRequest.addListener(
    callback, filter, opt_extraInfoSpec);

as mentioned in this thread

Update As mentioned in this link

Service Workers require a secure origin, such as HTTPS. chrome-extension:// pages are not HTTP/HTTPS, but are secure so this change becomes a necessary step to allow extensions to register a Service Worker.

"chrome-extension" is added as a scheme allowing service workers.

In the serviceworker script

First you need to register your extension in the manifest.json

  • Request the url in the service worker
  • Capture it in background script using the chrome.webRequest.onBeforeRequest.addListener
  • Play the sound in background.js
  • and as mentioned by @Alexander currently there is no support for the sound in the MDN


    或者可以在全局声明myAudio对象并在弹出通知之前或之后使用play()函数。

    myAudio = new Audio("alert_tone.mp3");
    
    var notification = new Notification("Hi there", options);
    myAudio.play();
    
    链接地址: http://www.djcxy.com/p/93718.html

    上一篇: 处理FCM设备组的刷新令牌

    下一篇: Chrome桌面版推送通知声音无效