Created
March 14, 2011 11:42
-
-
Save latentflip/869030 to your computer and use it in GitHub Desktop.
Gives a growl like popup if a page has an error. Useful under development.
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
-if RAILS_ENV == 'development' | |
:javascript | |
$(function() { | |
var notify = function(icon, title, body) { | |
if (window.webkitNotifications.checkPermission() == 0) { | |
var popup = window.webkitNotifications.createNotification( | |
icon, title, body); | |
popup.show(); | |
return true; | |
} | |
} | |
//Bind the popup to window.onerror | |
window.onerror = function(str, url, line) { | |
notify("", "JS Error", str+'\n'+url+':'+line); | |
}; | |
}); |
It would be pretty easy to package this up in an extension, and then you can set the target URLs for the extension to include localhost, 0.0.0.0, etc or any other places that you want to show it. That would avoid the need for changing your Chrome security prefs globally and having debug code in your Rails views.
Good idea, I might just do that. Thanks.
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment
There may be a better way to do this, but:
When writing JS I often make a silly little typo or something that I don't notice unless I:
This little snippet uses Chrome's desktop notifications (unobtrusive pop-ups a bit like growl's) to give you an alert if there's an error on the page. Here I am only enabling it in dev. mode for obvious reasons.
I couldn't be bothered having it asking for & enabling permissions, so I have just enabled mine globally in chrome prefs.
Is there a better way of solving this problem?