Can Firebug be required to run my website?
Asked Answered
C

4

5

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...)

Cenis answered 11/9, 2009 at 19:41 Comment(0)
U
10

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.

Upper answered 11/9, 2009 at 19:46 Comment(4)
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. +1Sedgewake
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.Dansby
I'm reading it and i'm feeling so stupid at the same time :). However Mushex what first answering...Cenis
This has happened to me as well. console.log will break everything if console isn't available, which it in most browsers.Stanch
S
7

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?

UPDATE: For those stumbling upon this now, "threads" in JavaScript really only exist in abstraction (web workers, etc). I was mis-using the term. I was really thinking of an asynchronous action that returned before another one was ready.

Sedgewake answered 11/9, 2009 at 19:43 Comment(5)
This would make sense since firefox's javascript engine seems to get faster with every release.Dansby
I am using ajax yes, i think however Justin is right about the console.log() :)Cenis
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.Sedgewake
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.Stanch
Javascript doesn't utilize "threads" in the traditional sense unless you specify them via extraction outside of the xhmtlrequest, via 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.Sedgewake
A
6

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.

Approve answered 11/9, 2009 at 19:47 Comment(3)
@ropstah Not that it's important...but check your math. This is the last answer, not the first.Upper
Whoops, you are right, i was indeed under influence while reading "8 minutes ago" by Mushex and your "9 minutes ago" Justin... :)Cenis
Another good idea is to include firebugx.js in your javascript, it'll add a fake console object to the window that ignores all your console.log calls.Frohman
S
0

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();
Snifter answered 22/1, 2010 at 20:24 Comment(1)
Nice, but i think it's better you remove the debug statements before anything goes live :)Cenis

© 2022 - 2024 — McMap. All rights reserved.