I am building desktop notification into my a chrome extension that I am working on. The functionality I need required that the user be taken to the tab that caused the notification when they click on the notification window. I can get that working using the chrome.tabs API, but what I can't manage to figure out is how to bring Chrome to the front when the notification is clicked.
I know window.focus() is disabled in chrome, but this is definitely possible to do since that's the behavior of the Gmail desktop notifications.
On Windows, click the Start button and then Settings. In the navigation pane on the left, choose System, then Notifications. At the top of the page, make sure Notifications is on by swiping the button to the right. In the Notifications from apps and other senders section, make sure Google Chrome is turned on as well.
Chrome notifications usually appear during your browsing experience. It alerts you whenever a site or app is sending you a notification. If users accept the notifications from a website, they start getting notifications. Google Chrome is a popular browser.
notification = webkitNotifications.createNotification(...)
notification.onclick = function(){
window.focus();
this.cancel();
};
notification.show()
...works as expected, without any additional permissions.
Use chrome.tabs.update(tabId, {active: true});
to focus a tab (not to be confused with chrome.windows.update
).
The tabId
is often obtained via the Tab
type. This object is passed to many methods/event listeners (sometimes via the MessageSender
type).
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