Logo Questions Linux Laravel Mysql Ubuntu Git Menu
 

How to implement a notification popup with sound in chrome extension

Tags:

How to implement a notification popup with sound in chrome extension.

Just like the Checker Plus for Gmail

like image 901
shawnXiao Avatar asked Feb 17 '13 02:02

shawnXiao


People also ask

How do I add sound notifications to Chrome?

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.

Can Chrome extensions send notifications?

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.

How do I get pop up notifications on Chrome?

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.

Which Chrome extension API function would be used to make a notification appear in the system tray?

notifications. Use the chrome. notifications API to create rich notifications using templates and show these notifications to users in the system tray.


1 Answers

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.

like image 77
Free Avatar answered Oct 06 '22 05:10

Free