Issue 481856 in chromium: new Notification() no longer works on Android

317 views
Skip to first unread message

chro...@googlecode.com

unread,
Apr 28, 2015, 6:17:31 AM4/28/15
to chromi...@chromium.org
Status: Untriaged
Owner: ----
Labels: Type-Bug Pri-2 Cr-UI-Notifications OS-Android

New issue 481856 by mattga...@chromium.org: new Notification() no longer
works on Android
https://code.google.com/p/chromium/issues/detail?id=481856

Version: Chrome 42.0.2311.109, Chrome 43.0.2357.38 and tested on Chrome 44
OS: Android

What steps will reproduce the problem?
1. Open up this page: http://jsbin.com/rexede/latest/quiet/
2. Click the show notification button
3. Allow notifications

What is the expected output? What do you see instead?
No notification is shown and in the console the following message is
logged: "Uncaught TypeError: Failed to construct 'Notification': Illegal
constructor. Use ServiceWorkerRegistration.showNotification() instead."

This is really not OK for two reasons.

1.) Desktop will show the notification, meaning its different to mobile.
This means we have an inconsistent web platform on Chrome.
2.) To use "ServiceWorkerRegistration.showNotification()" to the best of my
knowledge, you'd need HTTPS to register a sw and you'd an empty service
worker at the very least which is not trivial for some large sites.

Originally reported here:
http://stackoverflow.com/questions/29774836/failed-to-construct-notification-illegal-constructor/29895431


--
You received this message because this project is configured to send all
issue notifications to this address.
You may adjust your notification preferences at:
https://code.google.com/hosting/settings

chro...@googlecode.com

unread,
Apr 28, 2015, 6:18:31 AM4/28/15
to chromi...@chromium.org
Updates:
Cc: pe...@chromium.org joh...@chromium.org

Comment #1 on issue 481856 by mattga...@chromium.org: new Notification() no
(No comment was entered for this change.)

chro...@googlecode.com

unread,
Apr 28, 2015, 7:38:32 AM4/28/15
to chromi...@chromium.org

Comment #2 on issue 481856 by mattga...@chromium.org: new Notification() no
Relevant to this is:
https://groups.google.com/a/chromium.org/forum/#!topic/blink-dev/BygptYClroM

Matt Falkenhagen pointed out the above - thank you.

From the post - we can't use Notifications on Android because they can
easily get into a weird state.

Is there a way to detect that the Constructor isn't supported? Originally
was going to suggest removing the Notification API from the page
altogether, but realised the permission part of the API is being used for
push.

Am I missing a trick to detect this?

chro...@googlecode.com

unread,
Apr 28, 2015, 8:23:39 AM4/28/15
to chromi...@chromium.org

Comment #3 on issue 481856 by joh...@chromium.org: new Notification() no
`new Notification()` is on the path to deprecation[1], because it
implicitly assumes that the page will outlive the notification, which is
very unlikely on mobile (and far from guaranteed on desktop too).

Hence we will never implement it on Android. We might one day remove it on
desktop too, after a deprecation period.

Websites should use ServiceWorkerRegistration.showNotification() instead
whenever it is available.

The best way I can think of to feature-detect `new Notification()` is to
try it (*before* you have permission) and catch the error:

function isNewNotificationSupported() {
if (!window.Notification || !Notification.requestPermission)
return false;
if (Notification.permission == 'granted')
throw new Error('You must only call this *before* calling
Notification.requestPermission(), otherwise this feature detect would bug
the user with an actual notification!');
try {
new Notification('');
} catch (e) {
if (e.name == 'TypeError')
return false;
}
return true;
}

You could then use it like this:

if (window.Notification && Notification.permission == 'granted') {
// We would only have prompted the user for permission if new
// Notification was supported (see below), so assume it is supported.
doStuffThatUsesNewNotification();
} else if (isNewNotificationSupported()) {
// new Notification is supported, so prompt the user for permission.
showOptInUIForNotifications();
}

[1]: https://github.com/whatwg/notifications/issues/26
Reply all
Reply to author
Forward
0 new messages