DebugBar Forums
 
 HOME 
 DOWNLOAD 
 BUY 
 DOC / WIKI 
 FORUM 
 CONTACT 
Stay tuned : rss feed

Forum Home


advanced search

You are not logged in.

Announcement

Forums are now closed as we moved them to google groups. You can use the following Google Groups to discuss about DebugBar and IETester products:

#1 2008-08-05 09:06:11

timohear
New member

Can't detect presence of CompanionJS

With IE7 and CompanionJS 0.3 we're trying to detect capability of console using:

              if (console.log != null) {
                console.log(text);
               }

However this raises an error "Object doesn't support this property or method"

Inspecting console methods in VS 2005 QuickWatch shows all methods present, but attempts to test their existence all fail.

What is the recommended way to test capability of CompanionJS console?

Many thanks,

Tim

Offline

 

#2 2008-08-05 09:26:41

fabrice
DebugBar Support

Re: Can't detect presence of CompanionJS

Hi,

You can try to use the js provided with companion.JS on install : firebugx.js (taken from firebug).

The file should be on the Companion.JS install folder (default is c:\program files\Core Servìces\Companion.JS).

The test on the file is if "(!window.console"

Hope this helps.

Offline

 

#3 2008-08-05 10:45:04

timohear
New member

Re: Can't detect presence of CompanionJS

Hello Fabrice,

Merci pour la réponse à la vitesse de l'éclair. We are detecting the existence of the console using "window.console", but afterwards we test for the console capabilities. For instance the Safari console doesn't support console.debug. With CompanionJS installed our current logging wrapper crashes due to the capability test.

Is there a way to detect that the console is CompanionJS so that we can skip the capability testing?

Offline

 

#4 2008-08-05 10:56:13

fabrice
DebugBar Support

Re: Can't detect presence of CompanionJS

OK, I see. There are 2 solutions :

1/ Check if this is IE or Safari using javascript browser detection.

2/ I can try to add some property like "console.version" (returns 0.3) and "console.companionjs" (returns true) so the client knows which console implementation is used.
If you like the idea, I can implement it before launching v0.4

Offline

 

#5 2008-08-05 11:13:25

timohear
New member

Re: Can't detect presence of CompanionJS

Thank you Fabrice,

We'll go with the IE detection for now, thanks for the suggestion. Extra properties would be nice in 0.4.

You might find come across a fair amount of people with a similar problem though. If you google for:
"if (console.log"
"if (console.debug"
"typeof(console.log"
"typeof(console.debug"

There's a few interesting pages, for instance Dojo seems to do a fair bit of capability testing here:
http://trac.dojotoolkit.org/changeset/13755

and this version of firebugx.js was recently posted on the extjs forum to prevent null pointer errors on the safari console.debug:

(function(){
  // firebugx.js optimized for compressability and Safari
  var win = window, emptyFn = function(){}, names = ["log", "debug", "info", "warn", "error", "assert", "dir", "dirxml", "group", "groupEnd", "time", "timeEnd", "count", "trace", "profile", "profileEnd"];
  if (!win.console) {
    win.console = {};
  }
  var console = win.console;
  for (var i = 0; i < names.length; ++i) {
    if (!console[names[i]]) {
      console[names[i]] = emptyFn;
    }
  }
})();

Offline

 

#6 2008-08-05 21:00:56

fabrice
DebugBar Support

Re: Can't detect presence of CompanionJS

On IE with Companion.JS, another way to check if a method is implemented is to use :

if ("log" in console)

This is working on my IE browser.

Offline

 

#7 2008-08-07 17:00:39

fabrice
DebugBar Support

Re: Can't detect presence of CompanionJS

OK, I found a possible solution :

I will add an option to either inject "console" in the window, or to inject javascript code to create a console object. On the second option, I will wrap the native C++ object into this js object so "if (console.log)" will work. This will inject some JS code into the window, but the code should not be very intrusive.

Tell me if you like this idea.

Offline

 

#8 2008-08-10 13:16:50

fabrice
DebugBar Support

Re: Can't detect presence of CompanionJS

Hi,

I corrected this problem on the new Companion.JS version. Now "console" is a javascript object and "console.log" is working !
So you can check whether "console" has a property or method using "if (console.log)" (to test "log" method for instance).

Note that I have added 2 properties "provider" and "currentVersion" which return "Companion.JS" and "0.4.1" for the 0.4.1 version to the "console" object as well.

Offline