Skip to content

Commit 4edcc9d

Browse files
committed
Added support for mobile Chrome
1 parent 6e0dca8 commit 4edcc9d

3 files changed

Lines changed: 26 additions & 10 deletions

File tree

push.js

Lines changed: 25 additions & 9 deletions
Original file line numberDiff line numberDiff line change
@@ -110,21 +110,39 @@
110110
* @return {void}
111111
*/
112112
create_callback = function (title, options) {
113+
var notification,
114+
wrapper;
113115

114116
/* Set empty settings if none are specified */
115117
options = options || {};
116118

117119
/* Safari 6+, Chrome 23+ */
118120
if (w.Notification) {
119121

120-
notification = new w.Notification(
121-
title,
122-
{
123-
icon: (isString(options.icon) || isUndefined(options.icon)) ? options.icon : options.icon.x32,
124-
body: options.body,
125-
tag: options.tag,
122+
try {
123+
notification = new w.Notification(
124+
title,
125+
{
126+
icon: (isString(options.icon) || isUndefined(options.icon)) ? options.icon : options.icon.x32,
127+
body: options.body,
128+
tag: options.tag,
129+
}
130+
);
131+
} catch (e) {
132+
if (w.navigator) {
133+
w.navigator.serviceWorker.register('sw.js');
134+
w.navigator.serviceWorker.ready.then(function(registration) {
135+
registration.showNotification(
136+
title,
137+
{
138+
body: options.body,
139+
vibrate: options.vibrate,
140+
tag: options.tag
141+
}
142+
);
143+
});
126144
}
127-
);
145+
}
128146

129147
/* Legacy webkit browsers */
130148
} else if (w.webkitNotifications) {
@@ -349,8 +367,6 @@
349367
* @return {void}
350368
*/
351369
self.create = function (title, options) {
352-
var notification,
353-
wrapper;
354370

355371
/* Fail if the browser is not supported */
356372
if (!self.isSupported) {

push.min.js

Lines changed: 1 addition & 1 deletion
Some generated files are not rendered by default. Learn more about customizing how changed files appear on GitHub.

sw.js

Whitespace-only changes.

0 commit comments

Comments
 (0)