"text" field of "log.entryAdded" events should return WebIDL interface names (e.g., Window instead of [object Window])”
Categories
(Remote Protocol :: WebDriver BiDi, task, P3)
Tracking
(firefox151 fixed)
| Tracking | Status | |
|---|---|---|
| firefox151 | --- | fixed |
People
(Reporter: whimboo, Assigned: Sasha)
References
(Blocks 2 open bugs, Regressed 1 open bug)
Details
(Whiteboard: [webdriver:m20], [wptsync upstream])
Attachments
(4 files)
In the log.entryAdded event code we are serializing all the arguments by mapping it to String:
text += args.map(String).join(" ");
This produces text like [object Window] for window objects. Instead we need to return WebIDL interface names.
We could use ChromeUtils.getClassName() similar to our usage in RemoteValue.sys.mjs or Symbol.toStringTag like the following:
#getTypeName(value) {
if (value === null || value === undefined) {
return String(object);
}
const tag = value[Symbol.toStringTag];
if (typeof tag === "string") {
return tag;
}
return value.constructor && value.constructor.name
? value.constructor.name
: typeof value;
}
| Reporter | ||
Comment 1•4 months ago
|
||
Note that the above is just an example but not some code that we can directly use. Playwright has the test should use object previews for arrays and objects in page-event-console.spec.ts which expects the following for other browsers than Firefox:
Expected: "[1, 2, 3] {a: 1} Window"
Received: "1,2,3 [object Object] [object Window]"
So arguments which are an Array or a generic object have to be printed as previews. This is definitely better than the currently expected value for Firefox via Juggler: Array JSHandle@object JSHandle@object.
| Reporter | ||
Updated•4 months ago
|
| Reporter | ||
Comment 2•4 months ago
|
||
I wasn't aware that there is as well a Playwright issue: https://github.com/microsoft/playwright/issues/38304
Holger how much should actually be done in Playwright itself?
In the WebDriver BiDi spec we have:
If arg is a primitive ECMAScript value, append ToString(arg) to text. Otherwise append an implementation-defined string to text.
So we should still do better on our side given that above mentioned types are not primitive ECMAScript values.
Comment 3•4 months ago
|
||
(In reply to Henrik Skupin [:whimboo][⌚️UTC+1] from comment #2)
I wasn't aware that there is as well a Playwright issue: https://github.com/microsoft/playwright/issues/38304
Well, that Playwright issue is about correctly handling the values in args whereas this issue is about improving the value in text.
Holger how much should actually be done in Playwright itself?
In the WebDriver BiDi spec we have:
If arg is a primitive ECMAScript value, append ToString(arg) to text. Otherwise append an implementation-defined string to text.
So we should still do better on our side given that above mentioned types are not primitive ECMAScript values.
I agree: Playwright could ignore what we send in text and build a better alternative from the values in args but I think we should improve text rather than expecting BiDi clients to use args instead.
| Reporter | ||
Comment 4•4 months ago
|
||
I checked which differences exist between Firefox and Chrome when logging the following code through the console:
const array = [1, 2, 3];
const obj = {"a": 4};
console.log([1, 2, 3], obj, window);
Firefox:
0:08.56 pid:41854 1765473016170 RemoteAgent DEBUG WebDriverBiDiConnection f02cadab-1dea-49c7-b00f-aa9277227a42 <- {"type":"event","method":"log.entryAdded","params":{"type":"console","method":"log","source":{"realm":"5e21ee82-77ca-4efd-9ce3-91133be92519","context":"d46a3eea-746b-4428-9c81-261ace6acc1a"},"args":[{"type":"array","value":[{"type":"number","value":1},{"type":"number","value":2},{"type":"number","value":3}]},{"type":"object","value":[["a",{"type":"number","value":4}]]},{"type":"window","value":{"context":"4","isTopBrowsingContext":true}}],"level":"info","text":"1,2,3 [object Object] [object Window]","timestamp":1765473016167}}
0:08.57 pid:41854 1765473016170 RemoteAgent DEBUG WebDriverBiDiConnection f02cadab-1dea-49c7-b00f-aa9277227a42 <- {"type":"success","id":4,"result":{"realm":"5e21ee82-77ca-4efd-9ce3-91133be92519","type":"success","result":{"type":"undefined"}}}
Chrome:
event_data = {'args': [{'type': 'array',
'value': [{'type': 'number', 'value': 1},
{'type': 'number', 'value': 2},
{'type': 'number', 'value': 3}]},
{'type': 'object', 'value': [['a', {'type': 'number', 'value': 4}]]},
{'type': 'window',
'value': {'context': 'B3274E3D5AA7DD688B6FE4FB9A312B53'}}],
'level': 'info',
'method': 'log',
'source': {'context': 'B3274E3D5AA7DD688B6FE4FB9A312B53',
'realm': '-7906776153176179583.-2042879900037113502'},
'stackTrace': {'callFrames': [{'columnNumber': 16,
'functionName': '',
'lineNumber': 4,
'url': ''}]},
'text': 'Array(3) Object(1) window',
'timestamp': 1765473157754,
'type': 'console'}
Holger, it looks like that for the preview of arrays and objects Playwright still seems to pre-process maybe the args? The above output is retrieved via a wdspec test.
Comment 5•4 months ago
|
||
Playwright uses the browser-supplied preview by default but it can also create a preview from the supplied args (it does the latter for CDP which doesn't supply a preview string - note the lack of a text argument here).
For BiDi it uses the browser-supplied preview and fails the preview tests for both Firefox and Chrome (for example in this test Chrome/BiDi's preview is hello 5 Object(1)).
We could change Playwright to ignore text and always create a preview from args and improve renderPreview() to work more like the implementation for CDP. In this case I think we should still improve the preview that the browser supplies for BiDi clients other than Playwright but the priority would be lower.
| Reporter | ||
Comment 6•4 months ago
|
||
Thanks Holger! Ok, so lets limit this bug for now to create proper WebIDL names when generating the text. Maybe we can think of adding as well the length of the array or the number of own enumerable properties within brackets as suffix similar to what Chrome is doing.
| Reporter | ||
Updated•4 months ago
|
| Assignee | ||
Updated•1 month ago
|
| Assignee | ||
Comment 7•1 month ago
|
||
| Assignee | ||
Comment 8•1 month ago
|
||
| Assignee | ||
Comment 9•1 month ago
|
||
| Assignee | ||
Comment 10•1 month ago
|
||
For special console APIs use DevTools helper. For console.log stringify serialized arguments.
Updated•28 days ago
|
Updated•27 days ago
|
Comment 11•24 days ago
|
||
| Reporter | ||
Updated•24 days ago
|
Comment 13•23 days ago
|
||
| bugherder | ||
https://hg.mozilla.org/mozilla-central/rev/0b71a3cb8de1
https://hg.mozilla.org/mozilla-central/rev/972846f49a7a
https://hg.mozilla.org/mozilla-central/rev/1a8d195fd579
https://hg.mozilla.org/mozilla-central/rev/4b901cda34db
Comment 14•23 days ago
|
||
| bugherder | ||
https://hg.mozilla.org/mozilla-central/rev/0b71a3cb8de1
https://hg.mozilla.org/mozilla-central/rev/972846f49a7a
https://hg.mozilla.org/mozilla-central/rev/1a8d195fd579
https://hg.mozilla.org/mozilla-central/rev/4b901cda34db
Comment 16•23 days ago
|
||
For the future, please don't move around localizable files without consulting with localization.
This results in 145 strings showing up as untranslated, and duplicated in the repository (because we need to support the old location in ESR builds). I wonder if that move was strictly necessary.
Description
•