Sending Notifications on Chrome Extension
Warning
Over a year old. May be outdated
The goal is to...
- Send a notification when a Chrome extension gets installed or updated, with different text for each.
- Open a specific link when the notification is clicked.
Sending Notifications
Also available on GitHub
- Note that
iconUrlshould be the path frommanifest.jsonto the image file, not from the background script. - You can use
chrome.runtime.getManifest().versionto get the extension version. - To send from anywhere other than the background script, you must have a communication module between the sender and the background script to pass the notification details, then create it at
background.js. Sending directly fromcontent.jsseems restricted. More in this post.
Opening Links when notifications are clicked
Generally, you would need an event listener for each notification. There's a neater way that cuts the duplicate code.
Store the link in the notificationId field and attach one event listener to the notifications. That way you can only use one event listener to open multiple types of links.
Additional Readings
chrome.notificationssection on Google Chrome Developer Docs- Open URLs in Chrome Notifications on Stack Overflow
Note: Added June 19, 2020
This doesn't seem to be the final answer though. Click right after the popup and the page opens. Click later in the notification center and it doesn't. I'll update this if I find something better.
Backlinks1
221119