2

the below code generates a notification which automatically goes away in 20 secs on chrome .. I don't get why this is happening ...!!! the document says that default timeout value of notification is 8 secs , then why it takes 20 secs to dismiss the notif,,,

and i know the require_interaction flag is not stable but ...do any of you have any idea as to if it works with only a specific chrome version etc ...!

self.registration.showNotification(title, {
        body: body,
        icon: icon,
        tag: tag,
        data: notificationData,
        vibrate: vibrate,
        requireInteration:'true'

Update the issue was requireInteraction flag spelling .. ..my bad ...!!

sideshowbarker
  • 81,827
  • 26
  • 193
  • 197
Aman Satija
  • 1,865
  • 2
  • 15
  • 16

1 Answers1

4

The timeout in the implementation is indeed 20 seconds so the documentation should probably be fixed.

https://code.google.com/p/chromium/codesearch#chromium/src/ui/message_center/message_center_style.cc&cl=GROK&l=60&rcl=1452142029

require interaction should be stable already. It shipped in M47 which is the stable version as far as I know.

http://blog.chromium.org/2015/10/chrome-47-beta-idle-time-work-splash.html

Also note that the flag is called requireInteraction (with a C) the msdn doc seems wrong there as well.

Edit: Note that as chrome moves to native (OS provided) notifications the timeout is now defined by the underlying OS. For example in MacOS is 5 seconds. Different versions of linux and Windows 10 (once Chrome switches to native notifications in that platform) will be different as well.

Miguel Garcia
  • 1,029
  • 5
  • 14
  • 4
    And I just went ahead and updated mdn while at it :) – Miguel Garcia Jan 07 '16 at 11:59
  • my chrome ver no is Version 47.0.2526.106 (64-bit)...can you think of any reason as to why the notification doesn't stick around ...!!!and why the requireInterAction flag is not working in my case ? – Aman Satija Jan 07 '16 at 12:14
  • 1
    Works for me in the same version (linux and Mac) can you go to https://tests.peter.sh/notification-generator/ and display a notification there with the require interaction box ticked? If it sticks it's probably an issue with your code :) – Miguel Garcia Jan 07 '16 at 12:32
  • Oh and try requireInteration: true (without the quotes) – Miguel Garcia Jan 07 '16 at 12:34
  • your test page notification works for me in my chrome ,...!! – Aman Satija Jan 07 '16 at 12:56
  • there must be something in my code , i tried without the quotes true , even that is not working ... probably i might have called dismiss notifications some where let me double check – Aman Satija Jan 07 '16 at 13:18
  • yeah the without quotes was just to make it sane. javascript will interpret any non empty string as true. – Miguel Garcia Jan 07 '16 at 13:20
  • notice i copied the flag name requireInteration from the same document https://developer.mozilla.org/en-US/docs/Web/API/ServiceWorkerRegistration/showNotification notice the missing 'c' in requireInteraction ,,, is it right ?? is that the flag ?? – Aman Satija Jan 07 '16 at 14:01
  • Edited the answer to reflect that as well. requireInteraction is the correct spelling – Miguel Garcia Jan 07 '16 at 16:17
  • on OS X it's 5s default – rogerdpack Jan 05 '18 at 21:39
  • I updated the answer, the actual timeout length is not reliable anymore since most browsers are now using the underlying OS notification platform which defines their own timeouts – Miguel Garcia Mar 22 '18 at 08:29