Open Bug 1350572 Opened 7 years ago Updated 2 years ago

Console.dirxml should use format specifiers

Categories

(DevTools :: Console, defect, P3)

52 Branch
defect

Tracking

(Not tracked)

People

(Reporter: domfarolino, Unassigned)

Details

User Agent: Mozilla/5.0 (X11; Linux x86_64) AppleWebKit/537.36 (KHTML, like Gecko) Chrome/54.0.2840.100 Safari/537.36

Steps to reproduce:

Run the following code in the console:

```
console.dirxml("Dominic %s", "Farolino")
// and
var elem = document.createElement('h1');
console.dirxml("%O", elem, elem)
```


Actual results:

Results:

> Dominic %s Farolino

and

> %O <h1> <h1>


Expected results:

The expected results should be:

> Dominic Farolino

and the output of the second run should be either

> <h1> <h1>

or

> Object { , XX more...} <h1>

I believe the default for Firefox would be the two header tags sitting next to each other which might be a little misleading (since it implies that the %O specifier took no affect), but until the spec gets changed both are valid as long as the output is a potentially-expandable representation of a JavaScript object that is fine (i.e I can expand it to see properties etc).

-----------

In short, `dirxml` should use format specifiers, and furthermore the format specifiers just as `log` does now. I'm guessing that would be an easy fix since `log` already behaves in this way.
Component: Untriaged → Developer Tools: Console
Based on https://console.spec.whatwg.org/#dirxml, it does appear that case 1 should display as you suggest.

Case 2 isn't as clear to me, since DOM nodes are intended to be converted to a DOM Tree representation prior to running the Logger algorithm.  Formatting on %O is defined as "An object with generic JavaScript object formatting is a potentially expandable representation of a generic JavaScript object", so seems like there's some discretion here.
Status: UNCONFIRMED → NEW
Ever confirmed: true
Priority: -- → P3
Sorry for the delay. I'm a little confused about your second paragraph. Right now FF displays three things, the literal string "%O", and then two DOM tree represented nodes. This is because as it stands, `dirxml` does not take into account format specifiers. So it should take in account format specifiers and sub out the "%O" with one of the passed in objects, and print either:

`<h1> <h1>`

or (where the discretion you mention comes into play I believe)

`Object{, propertiesHere, }` <h1> (<== in other words, only two things, since the format specifier got processed). Does that make sorta make sense? Let me know if I can explain it better sorry!
Bumping this thread. As previously mentioned, the dirxml Console method should take in account format specifiers.

----

Secondary to this issue is the freedom and discretion that https://console.spec.whatwg.org/#ref-for-generic-javascript-object-formatting② allows. Personally, I'd expect:

 - `console.log("%O", document.createElement('h1'));`
 - `console.dirxml("%O", document.createElement('h1'));`

to both log a generic JavaScript representation of the DOM node, while:

 - `console.log(document.createElement('h1'))`
 - `console.dirxml(document.createElement('h1'))`
 - `console.log("%o", document.createElement('h1'))`
 - `console.dirxml("%o", document.createElement('h1'))`

to all log DOM node representations of the object. Firefox, in these cases, logs the same representation of the DOM element every time, which given the spec's flexibility, seems perfectly fine. The issue is that when using `console.dirxml`, a passed in string that contains format specifiers is never used to format later-appearing objects, and is itself printed instead.
Product: Firefox → DevTools
Severity: normal → S3
You need to log in before you can comment on or make changes to this bug.