views:

258

answers:

4

I'm working on a new project which has some complex javascript. I can't post any code so that's not what my question is about.

I have a script which works in Firefox 3.0. It was pointed out that the script did not work in Firefox 3.5, so I'm trying to make it work. Indeed the script didn't produce the expected results, so I installed the latest version of Firebug , enabled the console and refreshed the page.

And wow, it worked.

No errors, warnings nothing.

So I disabled the console, and then it didn't work anymore...

What's going on here? The Firebug console somehow changes something in Firefox that makes my script work? Any advice on what next? (besides asking future visitors to install Firebug...)

+7  A: 

It sounds to me like there's a chance you have a threading problem, and FireBug is analyzing and possibly slowing down one of the threads so that it has time to complete before the next step is resolved.

Are you possibly utilizing ajax, and something is waiting on that response? Or possibly you're doing something on or after the load of an object that is depending on something else in the DOM?

NateDSaint
This would make sense since firefox's javascript engine seems to get faster with every release.
Zoidberg
I don't know if that's right, but +1 for the good analysis
marcgg
I am using ajax yes, i think however Justin is right about the console.log() :)
Ropstah
It's a good idea to check on that Ajax while you're at it. I had a similar issue once using AJAX with Google Maps, where I alerted what a variable was, and that somehow magically fixed the code. Multiple Bald Spots Later, it turned out while the alert window was up, freezing the next step, it had time to load and fixed my threading issue.
NateDSaint
Javascript doesn't have threads, does it? You can have asynchronous code that'll be executed at a later point in time, but it's still not multi-threaded.
August Lilleaas
Javascript doesn't utilize "threads" in the traditional sense unless you specify them via extraction outside of the xhmtlrequest, via http://ajaxian.com/archives/multi-threaded-javascript but the asynchronous loading issues are similar in concept. So more specifically, a "timing" issue, in this case perhaps.
NateDSaint
+10  A: 

Could it be something as simple as forgetting to comment a call to console.log() somewhere in your javascript?

If you have hanging references, and the user doesn't have Firebug installed, you're going to get a runtime error that will halt execution of the script.

Justin Niessner
+1 This seems like the most likely culprit
patros
Yeah this sounds pretty likely too. I thought about it for a second but assumed since you didn't have firebug installed at first it wouldn't be there, but after reading this answer just realized there's a good chance if you copied and pasted code some debugging was sitting there. +1
NateDSaint
I dunno, I have to give the benefit of the doubt to the developer that he would be able to recognize such an obvious error.
Zoidberg
I'm reading it and i'm feeling so stupid at the same time :). However Mushex what first answering...
Ropstah
This has happened to me as well. `console.log` will break everything if `console` isn't available, which it in most browsers.
August Lilleaas
+6  A: 

Check in your code for console.log(), console.debug().Calling window.console objects methods throws an error if console is undefined (as expected).

In most cases you can easily delete or comment that lines.

Mushex Antaranian
Thanks! You were first answering, so credit is yours :)
Ropstah
@ropstah Not that it's important...but check your math. This is the last answer, not the first.
Justin Niessner
Whoops, you are right, i was indeed under influence while reading "8 minutes ago" by Mushex and your "9 minutes ago" Justin... :)
Ropstah
A: 

I wrote a simple wrapper for firebug (I just use debug but it should give you what you need to duplicate the other methods) that only writes when the console is there so I can use firebug, don't need to go comment out my debug statements and it doesn't break sites for people without it.

If you use this code then use fbconsole.debug instead of console.debug you will never have this problem:

function fbconsole () {
    this.debug = function (val) {
        if(typeof(console) !== 'undefined' && console != null) {
            console.debug(val);
            }
        }
    }
var fbconsole = new fbconsole();
Gypsy Rogers
Nice, but i think it's better you remove the debug statements before anything goes live :)
Ropstah