I am hesitant to ask yet another "too much recursion" question, but I'm totally lost for ideas.
I am getting a "too much recursion" error during my .ready(), which is unhelpfully occurring:
Very sporadically (ie once a month) for me
Pretty much every other time I have to do a demo using someone else's computer (of course)
On FF, Chrome, IE9 etc, on our dev, prod and test systems
And it's getting trapped deep inside the bowels of jQuery (1.10.2). Specifically, at this line of Sizzle, inside Sizzle.attr.
I've tried to "force" this bug to appear by using low memory VMs, but that doesn't seem to help. I'm stumped as to how to find where this is occurring, since I can't get a stack trace. I've got no minimal example either, since I can't make the bug happen.
The most likely candidate is something like triggering an event inside its handler, but I can't see how that would occur only sometimes, on load?
How can I try and find what is happening?
Any help or tips or links most welcome. If it's useful, I'm using jQuery, jQuery UI, and OpenLayers.
Try looking at a JS stacktrace when it errors to see the call chain - for a recursion problem this should show you what's recursing. You can see this with dev tools in the browser, for example in Firefox use Firebug's 'script' tab and use the 'stack' output tab.
Just noticed you'd said you'd tried to get a stack trace. Try putting a breakpoint at the line you know is bad and looking at the stacktrace to see if/when it seems to be recursing into some function above that line.
Related
I#ve a very strange problem calling a simple function in JavaScript.
Just for example, even a simple:
click
or:
click
gives me an Uncaught TypeError: object is not a function.
But ONLY in Chrome and ONLY on my Notebook. On my Workstation (same system, exactly same Chrome Version) and in every single other browser this line works as expected.
Im Working with JS since a few years, but this error drives me nuts since days.
The Website comes with scriptaculous and some handwritten JS, but nothing really special.
scriptaculous works well, JS-Console shows no errors except the one #Chrome on my Notebook.
Anyone of you ever had this before?
I#ve really no idea whats going on.
My suggestion is to assign it via javascript and not like an inline attribute. Sometimes you get odd behaviour setting it as an attribute.
You could use jQuery:
jQuery('.myClickableLink').click(function(){ alert(123) })
I think that's a simpler way.
I am betting you have a pop up blocker installed on that machine that hijacks window.alert. Disable the plugins and see if it works correctly. [Normally a pop up blocker does this]
use
window.alert('msg)';
it will work...
I'm having problems getting the window.load() event to fire on this site.
The problem occurred last night and no js or php errors are being output.
Which is making it particularly difficult to pinpoint the problem.
If you take a look at the file syrp.home.main.js, you'll see all sections within the homepage are initialised one by one. I've tried going through and commenting out each, however this didn't lend any insight to the problem.
I've looked at the JS Profiler in Chrome Dev tools but i haven't been able to narrow it down to a memory leak or infinite loop within a function yet. This could be because i'm not familiar enough with the JS Profiler.
Any tips as to what to look at next would be very much appreciated.
Thanks,
Cam
Located the problem, a coool 6 hours later.
I had declared my function that window.load() called as a var.
GLOBAL.els.$WINDOW.load(onPageLoad);
var onPageLoad = function(){};
changing it back to;
GLOBAL.els.$WINDOW.load(onPageLoad);
function onPageLoad(){};
note to self,
never do that again.
I saw several specific questions about this problem - getting typeerror object doesn't support this property or method in IE8, each with its specific answer.
Suppose I have a large website with lots of code ... I don't know what specific snippet is causing this error.
Is there a general method to debug this? I've tried with the IE Developer Tools, and it doesn't break on error. Is this caused by incorrect javascript syntax? Should I try something like js lint?
What's the correct, general way to identify and deal with this problem?
OK, so I turned to the age old solution and started to delete massive chunks of code from my project until the problem was "fixed". This helped me locate the problematic file.
I then proceeded to delete function by function until I found this little snippet: str.trim(). A quick search turned this up.
Update: Actually, I just realized something ... the problem was just a normal exception, and passing it to alert() masked the details. If you let such exceptions go to the top, then whatever browser you use will display useful line information. So, the next time it happens to me, I'm going to look for a way to make the exceptions fly high outside of the top level function. The catch wasn't in my code, it was jQuery, so I'm still not quite sure how to do it.
I wrote a hefty script in JS and I want to optimize it to run faster, but going through function by function and performing a "speed test" is taking too long. Anyone know of a better way? I've heard you can use firebug, but I haven't found any helpful links of how to go about that..
The page I'm optimizing is here:
http://flanvas.com/development/flanvas/examples/custom-class.html
I'm specifically trying to optimize the flanvas.js which is here:
http://flanvas.com/development/flanvas/flanvas.js
Any direction of where to go from is very helpful. Thanks!
Use FireBug, or the Developer Tools in Safari or Chrome. In Safari/Chrome, go to the "Profiles" tab, click the "Enable Profiling" button, and hit the 'record' button. After you've done enough testing, hit it again to capture the profile.
You'll get a wonderful list breaking down your functions by the time they took, the time other functions that they called took, and multiple ways to sort it.
Rather than walk you through this, I'll give you some of the Google searches you should have done before asking this question:
http://www.google.com/search?q=profiling+javascript+firebug
http://www.google.com/search?q=profiling+javascript+chrome
You want to do profiling first for your javascript code to find which part of the code is the slowest. Of course, the main tool for that is firebug. Firebug is a very great tool for profiling.
You may also want to see this question for some more help:
What is the best way to profile javascript execution?
If you are using Firefox, firebug is a good tool, it can also give you some basic ideas on how to speed up javascript.
More at http://getfirebug.com/whatisfirebug
You can download it as JS code, and add it to your file if you are using other browser.
Still, there are other tools around, if that doesn't help... but it is a good start
I get an error message from Firefox "Unresponsive script". This error is due to some javascript I added to my page.
I was wondering if the unresponsiveness are caused exclusively by code loops (function calling each other cyclically or endless "for loops") or there might be other causes ?
Could you help me to debug these kind of errors ?
thanks
One way to avoid this is to wrap your poor performant piece of code with a timeout like this:
setTimeout(function() {
// <YOUR TIME CONSUMING OPERATION GOES HERE>
}, 0);
This is not a bullet proof solution, but it can solve the issue in some cases.
According to the Mozzila Knoledgebase:
When JavaScript code runs for longer than a predefined amount of time, Firefox will display a dialog that says Warning: Unresponsive Script. This time is given by the settings dom.max_script_run_time and dom.max_chrome_script_run_time. Increasing the values of those settings will cause the warning to appear less often, but will defeat the purpose: to inform you of a problem with an extension or web site so you can stop the runaway script.
Furthermore:
Finding the source of the problem
To determine what script is running too long, click the Stop Script button on the warning dialog, then go to Tools | Error Console. The most recent errors in the Error Console should identify the script causing the problem.
Checking the error console should make it pretty obvious what part of your javascript is causing the issue. From there, either remove the offending piece of code or change it in such a way that it won't be as resource intensive.
EDIT: As mentioned in the comments to the author of the topic, Firebug is highly recommended for debugging problems with javascript. Jonathan Snook has a useful video on using breakpoints to debug complex pieces of javascript.
We need to follow these steps to stop script in Firefox.
Step 1
Launch Mozilla Firefox.
Step 2
Click anywhere in the address bar at the top of the Firefox window, to highlight the entire field.
Step 3
Type "about:config" (omit the quotes here and throughout) and press "Enter." A "This might void your warranty!" warning message may come up; if it does, click the "I'll be careful, I promise!" button to open the page that contains all Firefox settings.
Step 4
Click once in the "Search" box at the top of the page and type "dom.max_script_run_time". The setting is located and displayed; it has a default value of 10.
Step 5
Double-click the setting to open the Enter Integer Value window.
Step 6
Type "0" and click "OK" to set the value to zero. Firefox scripts now run indefinitely, and will not throw any script errors.
Step 7
Restart Mozilla Firefox.
Excellent solution in this question: How can I give control back (briefly) to the browser during intensive JavaScript processing?, by using the Async jQuery Plugin. I had a similar problem and solved it by changing my $.each for $.eachAsync
there could be an infinite loop somewhere in the code
start by commenting out codes to identify which section is causing it
too many loops: there might be a chance that your counter variable name clashes, causing the variable to keep resetting, causing the infinite loop.
try as much as possible to create hashes for your objects so much so that read time is O(1) and in a way caching those data
avoid using js libs as some of the methods might cause overheads. eg. .htm() vs .innerHTML
setTimeout() yes and no -- depends on how you chunkify your codes