How to implement a notification popup with sound in chrome extension.
Just like the Checker Plus for Gmail
Instructions. On the settings page, make sure to click on the drop down next to Notification and select allow. Do the same for Sound. Once done close this tab.
How notifications work. By default, Chrome alerts you whenever a website, app, or extension wants to send you notifications. You can change this setting at any time.
Go to Settings > Privacy and Security > Site Settings, then scroll down to Notifications in the pop-up window that appears. From there, you can toggle the Sites Can Ask to Send Notifications switch that turns website notification prompts on or off.
notifications. Use the chrome. notifications API to create rich notifications using templates and show these notifications to users in the system tray.
I think that createHTMLNotification
has been deprecated since the accepted answer was written. For anyone happening upon this thread now, here's a method that works as of January 2014 assuming that you have notifications
permissions in your manifest:
background.js
createNotification();
audioNotification();
function audioNotification(){
var yourSound = new Audio('yourSound.mp3');
yourSound.play();
}
function createNotification(){
var opt = {type: "basic",title: "Your Title",message: "Your message",iconUrl: "your_icon.png"}
chrome.notifications.create("notificationName",opt,function(){});
//include this line if you want to clear the notification after 5 seconds
setTimeout(function(){chrome.notifications.clear("notificationName",function(){});},5000);
}
The general idea here is just that you'll send out the regular notification and then just use a normal JavaScript method for playing a sound immediately on the heels of the notification's creation. Of course there are other ways to do it and to organize it, but I think this is pretty clear and very easy to implement in most cases.
If you love us? You can donate to us via Paypal or buy me a coffee so we can maintain and grow! Thank you!
Donate Us With