Is it possible to read the tab notifications (facebook, twitter, gmail etc shows a notification count) through a google chrome extension. So that I can display an desktop alert whenever a new notification arrives.
Click on Notifications & actions . Click on the app Google Chrome and toggle the switch On or Off to show notifications in action center, control the number of notification visible in the action center, control sound, set priority of notification in the action center and many more. Once completed, Close the window.
You could do this by periodically checking the titles of all relevant tabs, extracting the current notification number (if available) and notifying the user if a change in the number of notifications is detected.
However, depending on how often you perform this check the user will likely notice before you. An alternative approach would be to use content scripts to inject JavaScript (again, only to relevant pages - facebook etc) that listens to changes in the page's title
element and sends a message to your background page when one is detected which should then display a desktop notification.
I didn't know if this would work originally as I wasn't aware that title
changes could be listened to but a quick Google provided this answer;
how to listen for changes to the title element?
So all you should need to do is change the code in that question's answer to send a message to your background page instead of showing an alert. For example;
function titleModified() {
chrome.extension.sendRequest({
title: document.title
});
}
The background page must have an onRequest listener that would then attempt to parse the title received and determine whether or not a notification has been made.
Remember to correctly setup the permissions in your manifest in order to inject the JavaScript when your users are on the target sites as well as using desktop notifications.
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