Skip to content

Instantly share code, notes, and snippets.

@JesseAldridge
Created April 26, 2015 00:53
Show Gist options
  • Star 0 You must be signed in to star a gist
  • Fork 0 You must be signed in to fork a gist
  • Save JesseAldridge/b68d313682e30ea0c987 to your computer and use it in GitHub Desktop.
Save JesseAldridge/b68d313682e30ea0c987 to your computer and use it in GitHub Desktop.
chrome notification bug reproduction
<p> Note: You need to open via an http server for notifications to work. </p>
<input id='the-input'>
<div id='timer'>timer</div>
<script type="text/javascript">
start_time = new Date()
setInterval(function() {
document.getElementById('timer').textContent = Math.floor(
(new Date() - start_time) / 1000)
}, 1000)
if (!("Notification" in window))
console.log("This browser does not support desktop notification")
if (Notification.permission !== 'granted')
Notification.requestPermission(function (permission) {
console.log('permission:', permission)
Notification.permission = permission;
});
function show_notification() {
if (Notification.permission === "granted") {
this.notification && this.notification.close()
this.notification = new Notification("Hi there!");
this.notification.onclick = function(x) {
window.focus();
document.getElementById('the-input').focus()
// this.cancel();
this.close();
};
setTimeout(show_notification, 10000)
}
}
setTimeout(show_notification, 10000)
</script>
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment