Created
April 26, 2015 00:53
-
-
Save JesseAldridge/b68d313682e30ea0c987 to your computer and use it in GitHub Desktop.
chrome notification bug reproduction
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
<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