简体   繁体   中英

Can Firebug be required to run my website?

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

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.

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.

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.

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();

The technical post webpages of this site follow the CC BY-SA 4.0 protocol. If you need to reprint, please indicate the site URL or the original address.Any question please contact:yoyou2525@163.com.

 
粤ICP备18138465号  © 2020-2024 STACKOOM.COM