We would like to trap window.onerror so that we can do something intelligent with Javascript errors. Unfortunately it appears as though Prototype is doing something to defeat it? I''ve put together a little example which demonstrates this. If I load the following into Firefox and click on the text, I get an alert: <html> <head> <title>Error test</title> <script> window.onerror=function(){alert("error happened")} </script> <script type="text/javascript" src="prototype.js"/> </head> <body> <div onclick="nonexistent()">Click here for an error</div> </body> </html> If, on the other hand, I try it with the following (the only difference is the fact that prototype.js is loaded before the window.onerror handler is installed), I don''t: <html> <head> <title>Error test</title> <script type="text/javascript" src="prototype.js"/> <script> window.onerror=function(){alert("error happened")} </script> </head> <body> <div onclick="nonexistent()">Click here for an error</div> </body> </html> This is with Firefox 2.0.0.14 and Prototype 1.6.0.2 running on Leopard - I''ve not tested on other environments. I have Firebug installed, but get the same behavior whether it''s enabled or not. I''ve crawled through the Prototype source to see if it''s handling window.onerror itself, but as far as I can see it''s not touching it? Am I missing something? Thanks in advance for any help you can offer, Paul. --~--~---------~--~----~------------~-------~--~----~ You received this message because you are subscribed to the Google Groups "Ruby on Rails: Spinoffs" group. To post to this group, send email to rubyonrails-spinoffs-/JYPxA39Uh5TLH3MbocFFw@public.gmane.org To unsubscribe from this group, send email to rubyonrails-spinoffs-unsubscribe-/JYPxA39Uh5TLH3MbocFFw@public.gmane.org For more options, visit this group at http://groups.google.com/group/rubyonrails-spinoffs?hl=en -~----------~----~----~----~------~----~------~--~---
Paul Butcher wrote:> We would like to trap window.onerror so that we can do something > intelligent with Javascript errors. Unfortunately it appears as though > Prototype is doing something to defeat it? > ...A quick search shows that Prototype 1.6 does not add a window.onerror handler. If you have Firebug installed, it may attach a handler. Another option is to write a script to combine your JavaScript files into one file, wrap it in a try-catch block to process caught errors as you choose, and cache the combined file to a web-readable directory. - Ken Snyder --~--~---------~--~----~------------~-------~--~----~ You received this message because you are subscribed to the Google Groups "Ruby on Rails: Spinoffs" group. To post to this group, send email to rubyonrails-spinoffs-/JYPxA39Uh5TLH3MbocFFw@public.gmane.org To unsubscribe from this group, send email to rubyonrails-spinoffs-unsubscribe-/JYPxA39Uh5TLH3MbocFFw@public.gmane.org For more options, visit this group at http://groups.google.com/group/rubyonrails-spinoffs?hl=en -~----------~----~----~----~------~----~------~--~---
On Apr 17, 6:51 pm, Ken Snyder <kendsny...-Re5JQEeQqe8AvxtiuMwx3w@public.gmane.org> wrote:> A quick search shows that Prototype 1.6 does not add a window.onerror > handler. If you have Firebug installed, it may attach a handler.Yup - I performed the same search and couldn''t find anything. But how does that explain the behavior that I''m observing? Load prototype first and window.onerror doesn''t work, load it last and it does. Clearly it''s doing *something* - just not as obvious as directly installing a window.onerror handler... Cheers, Paul. --~--~---------~--~----~------------~-------~--~----~ You received this message because you are subscribed to the Google Groups "Ruby on Rails: Spinoffs" group. To post to this group, send email to rubyonrails-spinoffs-/JYPxA39Uh5TLH3MbocFFw@public.gmane.org To unsubscribe from this group, send email to rubyonrails-spinoffs-unsubscribe-/JYPxA39Uh5TLH3MbocFFw@public.gmane.org For more options, visit this group at http://groups.google.com/group/rubyonrails-spinoffs?hl=en -~----------~----~----~----~------~----~------~--~---
Paul Butcher wrote:> On Apr 17, 6:51 pm, Ken Snyder <kendsny...-Re5JQEeQqe8AvxtiuMwx3w@public.gmane.org> wrote: > >> A quick search shows that Prototype 1.6 does not add a window.onerror >> handler. If you have Firebug installed, it may attach a handler. >> > > Yup - I performed the same search and couldn''t find anything. But how > does that explain the behavior that I''m observing? Load prototype > first and window.onerror doesn''t work, load it last and it does. > Clearly it''s doing *something* - just not as obvious as directly > installing a window.onerror handler... > > Cheers, > > Paul.Check out PPK''s notes and test results on window.error : http://www.quirksmode.org/js/events_compinfo.html . Perhaps it has something to do with the limitations of window.onerror? So what are you trying to do with this callback exactly? - Ken --~--~---------~--~----~------------~-------~--~----~ You received this message because you are subscribed to the Google Groups "Ruby on Rails: Spinoffs" group. To post to this group, send email to rubyonrails-spinoffs-/JYPxA39Uh5TLH3MbocFFw@public.gmane.org To unsubscribe from this group, send email to rubyonrails-spinoffs-unsubscribe-/JYPxA39Uh5TLH3MbocFFw@public.gmane.org For more options, visit this group at http://groups.google.com/group/rubyonrails-spinoffs?hl=en -~----------~----~----~----~------~----~------~--~---
On 17 Apr, 20:17, Ken Snyder <kendsny...-Re5JQEeQqe8AvxtiuMwx3w@public.gmane.org> wrote: > Check out PPK''s notes and test results on window.error :http://www.quirksmode.org/js/events_compinfo.html . Perhaps it has > something to do with the limitations of window.onerror? Hmm - that page certainly doesn''t inspire confidence in window.onerror. > So what are you trying to do with this callback exactly? We''re in the process of writing a Javascript-intensive application. We''re all running Firebug, so if there''s a Javascript error, we know about it because we get the dreaded red cross in the status bar. But when we get to the point where we start beta testing with real users, we want them to tell us if something goes wrong. If they don''t have Firebug (and most of them won''t) nothing obvious happens when there''s an error. We want to display a large, obvious error message which they can tell us about so that we know exactly what''s gone wrong. We''ve already achieved this if an Ajax request goes wrong by registering onComplete and onException Ajax.Responders along the following lines: Ajax.Responders.register({ onComplete: function(request, transport, json) { if(!request.success()) // Report error }, onException: function(request, exception) { // Report error } }); But that''s no help if it''s "general" Javascript which throws an exception. If you (or anyone else) can suggest an alternative to window.onerror which achieves the desired result, I will be forever grateful! Thanks in advance, Paul. --~--~---------~--~----~------------~-------~--~----~ You received this message because you are subscribed to the Google Groups "Ruby on Rails: Spinoffs" group. To post to this group, send email to rubyonrails-spinoffs-/JYPxA39Uh5TLH3MbocFFw@public.gmane.org To unsubscribe from this group, send email to rubyonrails-spinoffs-unsubscribe-/JYPxA39Uh5TLH3MbocFFw@public.gmane.org For more options, visit this group at http://groups.google.com/group/rubyonrails-spinoffs?hl=en -~----------~----~----~----~------~----~------~--~---
Paul Butcher wrote:> ... > > But that''s no help if it''s "general" Javascript which throws an > exception. > > If you (or anyone else) can suggest an alternative to window.onerror > which achieves the desired result, I will be forever grateful! > > Thanks in advance, > > Paul. >It appears that remote error logging is a great application of window.onerror : http://sleepyhead81.blogspot.com/2005/08/javascript-error-logging-with-ajax.html You''re best bet may be to continue to figure out why the callback isn''t working when Prototype is loaded. You could try Event.observe(window, ''error'', errorHandler); One possible conflict I can think of is the properties that Prototype adds to Function.prototype or window. You could try getting window.onerror to fail by adding those properties one at a time. Also, what happens if you attach the window.onerror callback /before/ prototype is loaded? - Ken --~--~---------~--~----~------------~-------~--~----~ You received this message because you are subscribed to the Google Groups "Ruby on Rails: Spinoffs" group. To post to this group, send email to rubyonrails-spinoffs-/JYPxA39Uh5TLH3MbocFFw@public.gmane.org To unsubscribe from this group, send email to rubyonrails-spinoffs-unsubscribe-/JYPxA39Uh5TLH3MbocFFw@public.gmane.org For more options, visit this group at http://groups.google.com/group/rubyonrails-spinoffs?hl=en -~----------~----~----~----~------~----~------~--~---
Blush - it turns out that the problem has nothing whatsoever to do with Prototype. I have hit another issue though. I was loading Prototype with:> <script type="text/javascript" src="prototype.js"/>If instead of this I use:> <script type="text/javascript" src="prototype.js"></script>Then everything works fine. Foolish me - I thought that <script /> and <script></script> were equivalent. That''s a lesson learned! Except that window.onerror isn''t called for any Javascript in event handlers which are registered with addEventListener :-( http://groups.google.com/group/comp.lang.javascript/browse_thread/thread/871dac97b2eeeee1/94539a9355664c01?#94539a9355664c01 So we''ve ended up creating our own version of Event.observe in which we wrap the handler with try/catch. Messy, and error prone if we ever forget to use ''our'' version, but it works. Thanks for your help, Paul. -- paul.butcher->msgCount++ Snetterton, Castle Combe, Cadwell Park... Who says I have a one track mind? http://www.paulbutcher.com/ LinkedIn: http://www.linkedin.com/in/paulbutcher MSN: paul-q9qwgYRQEc9WkMItezQGDw@public.gmane.org AIM: paulrabutcher Skype: paulrabutcher --~--~---------~--~----~------------~-------~--~----~ You received this message because you are subscribed to the Google Groups "Ruby on Rails: Spinoffs" group. To post to this group, send email to rubyonrails-spinoffs-/JYPxA39Uh5TLH3MbocFFw@public.gmane.org To unsubscribe from this group, send email to rubyonrails-spinoffs-unsubscribe-/JYPxA39Uh5TLH3MbocFFw@public.gmane.org For more options, visit this group at http://groups.google.com/group/rubyonrails-spinoffs?hl=en -~----------~----~----~----~------~----~------~--~---