i want to create a google chrome extension that notify user when a new record in the mysql DB is added ! there is someone who can help me ? Thank you.
-
Chrome supports desktop notifications natively.– Dan DascalescuFeb 11, 2014 at 5:47
-
Did you find it working? Can you share your source code?– AnupalDec 19, 2015 at 10:56
-
Well. You could use a php script to communicate to the mySQL DB and make an ajax call to the php script from your chrome extension– Jay GhoshDec 29, 2016 at 18:23
2 Answers
Please refer to this page.
Use the chrome.notifications API to create rich notifications using templates and show these notifications to users in the system tray.
https://developer.chrome.com/docs/extensions/reference/notifications/
chrome.notifications.create(
"name-for-notification",
{
type: "basic",
iconUrl: "image.jpeg",
title: "This is a notification",
message: "hello there!",
},
function () {}
);
You can create notification like this.
EDIT: Please do not forget to add the "notifications"
permission in the manifest.json
file
-
thank you but i'm asking how to communicate with my mysql DB and count the number of entries for example (this number will appear using the chrome notification api). Sep 14, 2013 at 13:19
-
I guess you have to first check if chrome notifications are turned on or not.– PG1Jun 21, 2014 at 7:51
-
1very importan! : do not forget to add the "notifications" permission in the manifest.json Sep 9, 2020 at 14:01
you can also use the notification from the window object like that
and -- very importan! : do not forget to add the "notifications" permission in the manifest.json
function init() {
if (!window.Notification) {
alert('notSupport');
} else if (Notification.permission === "granted") {
console.log('grant notification')
installNotification = createInstallNotification();
} else if (Notification.permission !== 'denied') {
console.log('denied init notes')
Notification.requestPermission(function (permission) {
console.log('ask init notes',permission)
if (permission === 'granted') {
installNotification = createInstallNotification();
}else{
alert('doNotDenied')
}
})
}
// end init
}
function createInstallNotification() {
return new Notification('installSuccess', {
body: 'text body'
, tag: 'uniqe-numer-here'
})
}