Closed Bug 2005054 Opened 4 months ago Closed 23 days ago

"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)

task
Points:
3

Tracking

(firefox151 fixed)

RESOLVED FIXED
151 Branch
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;
  }

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.

Summary: "text" field of "log.entryAdded" events should return WebIDL interface names (e.g., Window instead of [object Window])” → "text" field of "log.entryAdded" events should return WebIDL interface names (e.g., Window instead of [object Window])” and previews for arrays and generic objects

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.

Flags: needinfo?(hbenl)

(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.

Flags: needinfo?(hbenl)

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.

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.

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.

Summary: "text" field of "log.entryAdded" events should return WebIDL interface names (e.g., Window instead of [object Window])” and previews for arrays and generic objects → "text" field of "log.entryAdded" events should return WebIDL interface names (e.g., Window instead of [object Window])”
Points: --- → 3
Priority: -- → P3
Whiteboard: [webdriver:m19]
Assignee: nobody → aborovova
Status: NEW → ASSIGNED
Blocks: 1917540

For special console APIs use DevTools helper. For console.log stringify serialized arguments.

Attachment #9557911 - Attachment description: Bug 2005054 - [devtools] Extract "transformConsoleAPICallResource" into a shared module to make it easier to reuse in WebDriver BiDi. → Bug 2005054 - [devtools] Extract "transformConsoleMessage" into a shared module to make it easier to reuse in WebDriver BiDi.
Attachment #9557911 - Attachment description: Bug 2005054 - [devtools] Extract "transformConsoleMessage" into a shared module to make it easier to reuse in WebDriver BiDi. → Bug 2005054 - [devtools] Extract "formatMessageParametersAndText" into a shared module to make it easier to reuse in WebDriver BiDi.
Whiteboard: [webdriver:m19] → [webdriver:m19], [wptsync upstream]
Whiteboard: [webdriver:m19], [wptsync upstream] → [webdriver:m20], [wptsync upstream]
Upstream PR merged by moz-wptsync-bot

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.

Regressions: 2028930
Regressions: 2030964
You need to log in before you can comment on or make changes to this bug.

Attachment

General

Created:
Updated:
Size: