7

I want to listen to incoming notifications on the chrome browser for sites like google, facebook, whatsapp etc. I saw that the hack mentioned here which no longer works because webkitNotifications.createNotification is deprecated. Some of these sites use service workers, so I wonder if I can use webAPIs like ServiceWorkerRegistration.getNotifications(), PushManager, ServiceWorkerGlobalScope or even the Notification API? I've been reading around and cannot find anything to do this. I don't mind a hack as well. Can anything be done using selenium? Is it possible at all? If not, I'll not waste more time on it. Cheers!

Note: I'm looking for a solution where I can listen to notifications on other websites, not mine.

BDL
  • 21,052
  • 22
  • 49
  • 55
Kaushik Evani
  • 1,154
  • 9
  • 17
  • What a general purpose? Do you want to collect your notifications in one place? Browser doesn't allow you to mess with a context of other pages from your page. Maybe extension can, but i'm not sure. – Dmitry Manannikov May 18 '17 at 07:03
  • 1
    I want to listen to incoming notifications from WhatsApp – Kaushik Evani May 23 '17 at 06:55

1 Answers1

3

I needed exact same thing. I assume you are looking for Chrome extension or App. I had no ways to access or intercept notifications shown through service workers (usually ones shows even after browser close). But the ones using Notications API in page you can simply customize Notications with your version of object as mentioned in: Event Listener for Web Notification

Put this in content script of extension and load before page is loaded in Chrome and listen to every events raised from page.

John Park
  • 56
  • 4
  • Excellent! I actually tried what you suggested before. But I could not get it to actually run it in the page context and load it before the page is loaded. Here, the page being WhatsApp. Your answer actually led me to a solution through the link to [answer](https://stackoverflow.com/a/36868084/5148395) you cited. So I just [nativified](https://github.com/jiahaog/nativefier) web.whatsapp.com, and am now capturing desktop notifications using – Kaushik Evani Jun 12 '17 at 14:35
  • contd... stack didn't allow me to edit the comment... using `dbus-monitor "interface='org.freedesktop.Notifications'"`. – Kaushik Evani Jun 12 '17 at 14:42
  • I wrote a extension that captures Notification events with all data required and have another Chrome app that listens to messages. Extension uses message API to communicate data to App which it writes to file as auto file writing isn't permitted through extension. – John Park Jun 14 '17 at 10:19
  • @JohnPark is that extension public somewhere? Would love to use it too – dcts Jun 12 '22 at 09:37