Tuesday, 1 October 2013

WebKit: attaching Web Notification to onmessage event

WebKit: attaching Web Notification to onmessage event

WebKit has a bug where it requires you to attach an event listener before
you can request the user's permission for Web Notifications. Please by all
means correct me if I'm wrong about this.
I've been working to combine Server Sent DOM events and Web Notifications
to notify users of new emails. Chrome 29 gets as far as the commented out
alert though I receive no request from Chrome to enable/disable Web
Notifications.
Here is what I've got...
if ('EventSource' in window)
{//Server Sent DOM Events
var es = new EventSource('../mail/sse/');
if (window.webkitNotifications &&
window.webkitNotifications.checkPermission()!=0)
{
es.addEventListener('message',function()
{//alert('test, this alert executes successfully when not commented.');
window.webkitNotifications.requestPermission();
},false);
}
}

No comments:

Post a Comment