Note that iconUrl should be the path from manifest.json to the image file, not from the background script.
You can use chrome.runtime.getManifest().version it to get the version of the extension.
If you want to send notifications from anywhere else than the background script, you must have a communication module between the notification sender and the background script to pass the notification details. Create a notification at background.js with that given detail. Sending notifications directly from content.js seems restricted. Check this post for more information.
Opening Links when notifications are clicked
Generally, you would need an event listener for each notification. However, there is a neat way to reduce duplicate codes.
The trick is to store the link in notificationId field and attach an event listener to the notifications. This way, you can only use one event listener to open multiple types of links.
It doesn't seem that this is the ultimate answer. While the notification opens up the intended page when the user clicks the notification right after it pops up, the notification does not open up the page on click if the notification is sent to the notification center. This post will be updated if I find a better solution.
Comments0
No comments yet. Be the first to share your thoughts.