What's a surefire way of detecting whether a user has Firebug enabled?
If firebug is enabled, window.console will not be undefined. console.firebug will return the version number.
Check for the console
object (created only with Firebug), like such:
if (window.console && window.console.firebug) {
//Firebug is enabled
}
It may be impossible to detect.
Firebug has multiple tabs, which may be disabled separately, and, are now not enabled by default.
GMail as it is can only tell whether or not I have the "console" tab enabled. Probing further than this would likely require security circumvention, and you don't want to go there.
You can use something like this to prevent firebug calls in your code from causing errors if it's not installed.
if (!window.console || !console.firebug) {
(function (m, i) {
window.console = {};
while (i--) {
window.console[m[i]] = function () {};
}
})('log debug info warn error assert dir dirxml trace group groupEnd time timeEnd profile profileEnd count'.split(' '), 16);
}
Keep in mind in Chrome window.console also returns true or [Object console]
.
Furthermore, I would check whether Firebug is installed with
if (window.console.firebug !== undefined) // firebug is installed
Below is what I get in Safari and Chrome, no firebug installed.
if (window.console.firebug) // true
if (window.console.firebug == null) // true
if (window.console.firebug === null) // false
The Is-True and Is-Not Operators obviously do type coercion, which should be avoided in JavaScript.