GoogleChromeLabs / chromium-bidi

Implementation of WebDriver BiDi for Chromium
https://googlechromelabs.github.io/chromium-bidi/
Apache License 2.0
87 stars 30 forks source link

Using `*` as locator returns no nodes #2539

Open christian-bromann opened 2 weeks ago

christian-bromann commented 2 weeks ago

This behavior is observed in stable and canary (130.0.6682.2)

Expected Behavior

If I call browsingContext.locateNodes with the following parameters:

{
  "locator": {"type":"css","value":"*"},
  "context":"4ab66b36-ae31-4c38-90bb-40d97bd48b36"
}

I would expect that it would fetch the ` tag as it is the first element in the DOM tree.

Actual Behavior

Firefox: ✅ works as expected and returns

{
    "nodes": [
        {
            "type": "node",
            "sharedId": "d2030884-983d-45f9-85fd-10552d1e9f70",
            "value": {
                "nodeType": 1,
                "localName": "head",
                "namespaceURI": "http://www.w3.org/1999/xhtml",
                "childNodeCount": 0,
                "attributes": {},
                "shadowRoot": null
            }
        },
        {
            "type": "node",
            "sharedId": "9d66bb03-20fd-4e5d-bacf-68bbdda1d15d",
            "value": {
                "nodeType": 1,
                "localName": "body",
                "namespaceURI": "http://www.w3.org/1999/xhtml",
                "childNodeCount": 0,
                "attributes": {},
                "shadowRoot": null
            }
        }
    ]
}

Chrome: ❌ fails even though * is a valid selector and returns

{
    "nodes": []
}

Reproducible Example

See https://github.com/christian-bromann/bidi-locateNodes-error, clone the repo, install dependencies, and call npm run wdio

OrKoN commented 2 weeks ago

@sadym-chromium PTAL

sadym-chromium commented 2 weeks ago

e2e repro works: https://github.com/GoogleChromeLabs/chromium-bidi/pull/2543. Looking further

sadym-chromium commented 2 weeks ago

UPD: the issue should be fixed by https://github.com/GoogleChromeLabs/chromium-bidi/pull/2543

sadym-chromium commented 2 weeks ago

The root cause is in the fact Chromium BiDi used document.body instead of document, which excluded head form the selectors.

christian-bromann commented 2 weeks ago

Thanks for fixing this. @sadym-chromium why would it still return no nodes given the selector * then? I would assume it would return the first node in the document.body tree.

sadym-chromium commented 2 weeks ago

Thanks for fixing this. @sadym-chromium why would it still return no nodes given the selector * then? I would assume it would return the first node in the document.body tree.

In your example the page is "about:blank", and there are no elements in the "document.body"