Opened 11 years ago

Closed 11 years ago

#6849 closed defect (fixed)

default console.* wrappings may not work on Safari 3.1/Dojo 1.1

Reported by: guest Owned by: James Burke
Priority: high Milestone: 1.2
Component: Core Version: 1.1.1
Keywords: Cc: alex, jayant.b.sai@…, James Burke, tvachon, jvargas@…, Adam Peller, Mike Wilcox
Blocked By: Blocking:

Description

calling console.debug() from the web inspector w/ Dojo 1.1 throws an error

Change History (17)

comment:1 Changed 11 years ago by James Burke

Cc: James Burke added

It looks like we need to override window.console with a new object, not just add methods to the existing object. Not sure yet how to delegate to native window.console.log for the logging: my first pass at it did not work, but it was part of a larger project with other variables in play. But defining window.console to an object we can modify allows us to define functions on the console object.

comment:2 Changed 11 years ago by tvachon

Just want to note that this causes bugs all over the place, due to fairly extensive use of console.debug in Dojo core and libraries. Is there a known good workaround until a fix is released?

Note that I've found even adding

if (!console.debug) console.debug = console.log;

after the dojo.js script include doesn't fix the issue completely, as it appears console.debug becomes undefined again at some point after this.

I'll be working on a workaround today in order to fix some Cosmo bugs (https://bugzilla.osafoundation.org/show_bug.cgi?id=12146 for example), and will update here with further information.

comment:3 Changed 11 years ago by tvachon

Well, that was quick. It looks like the specific problem I was having can be solved with

dojo.addOnLoad(function(){

if (!console.debug) console.debug = console.log;

});

for now, though I'm still concerned about other bugs due to console.debug calls between whenever console is being redefined and when the onload functions fire.

comment:4 Changed 11 years ago by tvachon

Cc: tvachon added

comment:5 Changed 11 years ago by tvachon

After more testing, it looks like whatever is causing console.debug to become undefined happens in another thread (or, possibly, a javascript async callback) as the precise point in the code flow at which this happens changes from load to load, apparently non-deterministically.

Not entirely sure about the best way to proceed with this one, so I'll probably just be working around as best I can.

As an aside, this appears to be a non-issue in webkit trunk:

https://bugs.webkit.org/show_bug.cgi?id=19153

comment:6 Changed 11 years ago by guest

The following seems to workaround the problem. Put it in a script tag prior to loading dojo

if (/3[\.0-9]+ Safari/.test(navigator.appVersion)) {

window.console = {

origConsole: window.console, log: function(s){

this.origConsole.log(s);

}, info: function(s){

this.origConsole.info(s);

}, error: function(s){

this.origConsole.error(s);

}, warn: function(s){

this.origConsole.warn(s);

}

};

}

comment:7 Changed 11 years ago by guest

Sorry, for the bad wiki formatting. Should have previewed.

  if (/3[\.0-9]+ Safari/.test(navigator.appVersion))
  {
      window.console = {
          origConsole: window.console,
          log: function(s){
              this.origConsole.log(s);
          },
          info: function(s){
              this.origConsole.info(s);
          },
          error: function(s){
              this.origConsole.error(s);
          },
          warn: function(s){
              this.origConsole.warn(s);
          }
      };
  }

comment:8 Changed 11 years ago by alex

Owner: changed from anonymous to alex
Status: newassigned

comment:9 Changed 11 years ago by alex

Cc: jvargas@… added

comment:10 Changed 11 years ago by James Burke

Note that this is an issue only if djConfig.isDebug is false. with djConfig.isDebug = true, I see messages going to our firebug lite console with Safari 3.1.1.

Also, with #1368 fixed, there is a build option to strip console.debug calls from builds.

So I am wondering if we can just leave this ticket as-is, since we have some mitigations for it, and from tvachon's comment, this is is fixed in webkit nightlies, so hopefully next webkit release fixes it.

The thing that bothers me is the code bloat in dojo base to get this to work. We cannot just define console.debug for the isDebug false case, we have to define a complete console object just for safari.

comment:11 Changed 11 years ago by Adam Peller

Cc: Adam Peller Mike Wilcox added

comment:12 Changed 11 years ago by Mike Wilcox

If I understand this ticket correctly, the original issue seems to be using the command line in the Safari web inspector with dojo loaded.

This isn't reccomended. Firebug Lite takes over the console namespace, nullifying the web inspector's console. Plus, Firebug Lite has a command line that could be used. But more importantly, if djConfig is set to false, dojo adds a console object and adds blank methods, which again takes over the window.console:

http://trac.dojotoolkit.org/browser/dojo/trunk/_base/_loader/bootstrap.js line 90

I've also proposed a new debugging code base. The ticket is named FirebugX, but it's grown past that. It can add most of the FB features in a browser's standard debugger. This would allow logging to the web inspector, and also keep its command line working.

But even with that package, isDebug will kill Safari's console.

If I misinterpreted the problem, please clarify with a test case, and I will help to resolve it.

comment:13 Changed 11 years ago by alex

mike:

I think you misunderstand. The issue isn't that firebug lite wraps or doesn't wrap the console.* apis, it's that somehow, in the situation outlined, the method are not being correctly created. This seems to be related to how things are set up via DOH, and not simply an issue with isDebug vs. non-isDebug.

comment:14 Changed 11 years ago by Adam Peller

(In [14532]) Workaround to fix errors in DOH in Safari where console.debug is used. Fixes #7189, refs #6849

comment:15 Changed 11 years ago by Jared Jurkiewicz

Other than bloat, is there a reason that the above suggestion couldn't be added to bootstrap to fix the issue, since it works around the problem okay on DoH, etc? I've actually seen this problem before in non-DOH cases and I have no idea what exactly triggers it such that console.debug starts failing.

comment:16 Changed 11 years ago by James Burke

Owner: changed from alex to James Burke
Status: assignednew

I am also seeing generic issues with console.debug not being defined in Safari, when running without firebug lite.

I wonder if it is enough to run the build with console.* calls being stripped (new for Dojo 1.2) to avoid this issue with our releases, and hopefully when the webkit trunk is released, this problem will go away.

Not the most robust solution, but I am really not liking the bloat to base to fix this problem.

I'll assign the ticket to me, to make sure I get the CDN builds documented to use the console stripping. I'll also see if I can plug in the console.debug stripping as part of the standard.profile.js build file.

comment:17 Changed 11 years ago by James Burke

Resolution: fixed
Status: newclosed

(In [14787]) Fixes #6849: stop-gap solution to avoid flaky Safari 3 definition of console.debug, by stripping out console.debug calls in the standard build. Apparently the issue is fixed in a webkit nightly, so once that gets released, this should no longer be an issue.

Note: See TracTickets for help on using tickets.