I am using a window.onerror=function(msg, url, linenumber) to send myself an email when a javascript error occurs. When I use my webpages (IE, FF, CHRM, ect) I do not receive any errors. However I am getting all kinds of errors emailed to me from other users that I cannot duplicate. I am probably getting an error happening on 1% of the users visiting the website so 1/100 page loads I get an error. Here are some:
- Syntax error: http://www.google-analytics.com/ga.js
- Error loading script: http://www.google-analytics.com/ga.js
- Error loading script: https://seal.thawte.com/getthawteseal?host_name=XXX&size=M&lang=en
- $(“input.datepicker”).datepicker is not a function
- Uncaught SyntaxError: Unexpected token
- Object doesn’t support this property or method
- Uncaught TypeError: Object [object Object] has no method ‘dialog’
- Syntax error: http://seal-cencal.bbb.org/logo/XXX
- Error: Permission denied to access property ‘toString’
What I don’t understand is the website 99% of the time is running without any errors and I can’t seem to get an error to happen for me on any browser I use. I am also tracking what browsers the users are using who send these errors and it’s random, all sorts of browsers and they are all newer FF, IE versions mainly.
How do you stop syntax errors on external code (but they work most of the time)…?
How come google and thawte scripts fail to load some people so often but never happens to me, is there a way to have a fallback to this?
The datepicker one, I can only assume its error out because jquery UI failed to load because jquery loads (otherwise it wouldn’t get called inside a document ready call) but I even have a localhost jquery UI script fallback include and it still happens..
Does anyone have a suggestion for me to help me further debug/fix these problems. The thing is, the website gets a lot of hits I am getting about 1 error emailed to me every minute (and it’s not the same user causing each error). If you have any suggestions let me know (remember the code and website work fine 99% of the time so I don’t think its a syntax problem on my end anywhere).
Thanks for your time.
You can’t really. Without a more detailed message investigation is quite impossible. Notice that sysntax errors might be caused by something else as well, their origin might not be in the external script. I doubt Google Analyticts serves invalid scripts.
They might use adblockers or similiar against those. Not everyone wants his web usage logged by google. Also, some proxies might ignore/block them, like intranet firewalls.
You could try serving them from your own domain as a proxy. Or just ignore them, I don’t think your app really needs a fallback for those.
Yes, that sounds likely. Or it just didn’t load before it was called.
Localhost? I guess you mean a copy on your server. Still, it depends on the details how the script and its fallback version are loaded.
A stack trace would help a lot to locate the user’s action that caused the error.