Skip to content

[🐛 Bug]: DevTools - RemoteObject.Type.OBJECT properties in consoleEvents are not properly mapped and lost (null) on listener call #11377

New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Closed
Wojciech-Kopec opened this issue Dec 7, 2022 · 5 comments · Fixed by #11435
Labels
B-devtools Includes everything BiDi or Chrome DevTools related C-java Java Bindings I-defect Something is not working as intended J-issue-template Applied to issues not following the template, or missing information.

Comments

@Wojciech-Kopec
Copy link

Wojciech-Kopec commented Dec 7, 2022

What happened?

DevTools console entries fetched by Selenium DevTools support have value equals to "null" if are RemoteObject.Type.OBJECT

Through debugging Selenium's code it seems that in this place mapping is incorrectly performed and getValue always defaults to null.

I would like to log DevTools messages as 'they are' for further debugging in case of application defect occurence.

Look at attached images - here is my tested application devtools console tab with Intellij's debug on breakpoint

selenium_devtools_consoleEvent_serialization-highlighted

ModifiedArgs are later forwarded to customListener and original args are no longer available.
selenium_devtools_consoleEvent_serialization-line_later

How can we reproduce the issue?

import io.github.bonigarcia.wdm.WebDriverManager;
import org.openqa.selenium.JavascriptExecutor;
import org.openqa.selenium.WebDriver;
import org.openqa.selenium.chrome.ChromeDriver;
import org.openqa.selenium.devtools.HasDevTools;
import org.openqa.selenium.devtools.v106.log.Log;
import org.openqa.selenium.devtools.v106.network.Network;

import java.util.Optional;

class DevToolsEventsTest {
    public static void main(String[] args) {
        WebDriver driver = null;
        try {
            //Init WebDriver
            WebDriverManager.chromedriver().setup();
            driver = new ChromeDriver();

            //Init DevTools
            ((HasDevTools) driver).maybeGetDevTools().ifPresent(devTools -> {
                devTools.createSessionIfThereIsNotOne();
                devTools.send(Network.enable(Optional.empty(), Optional.empty(), Optional.empty()));
                devTools.send(Log.enable());
                //Add Listeners
                devTools.getDomains().events().addConsoleListener(consoleEvent -> System.out.printf("[consoleEvent] %s%n", consoleEvent));
            });
            //Trigger consoleEvents
            ((JavascriptExecutor) driver).executeScript("console.log(\"simple\", 1, \"test\", true)");
            ((JavascriptExecutor) driver).executeScript("console.log(\"array\", [1, 2, 3])");
            ((JavascriptExecutor) driver).executeScript("console.log(\"object\", { a: 1 })");
            ((JavascriptExecutor) driver).executeScript("console.log(\"nested object\", { a: { b: 1 } })");
            Thread.sleep(5000);
        } catch (InterruptedException e) {
            throw new RuntimeException(e);
        } finally {
            if (driver != null) {
                driver.quit();
            }
        }
    }
}

Relevant log output

> Task :DevToolsEventsTest.main()
12:39:07 [main] [] DEBUG ResolutionCache - Resolution chrome=108 in cache (valid until 13:07:27 09/12/2022 CET)
12:39:07 [main] [] DEBUG ResolutionCache - Resolution chrome108=108.0.5359.71 in cache (valid until 16:36:58 09/12/2022 CET)
12:39:07 [main] [] INFO  WebDriverManager - Using chromedriver 108.0.5359.71 (resolved driver for Chrome 108)
12:39:07 [main] [] DEBUG WebDriverManager - Driver chromedriver 108.0.5359.71 found in cache
12:39:07 [main] [] INFO  WebDriverManager - Exporting webdriver.chrome.driver as C:\Users\Wojciech\.cache\selenium\chromedriver\win32\108.0.5359.71\chromedriver.exe
Starting ChromeDriver 108.0.5359.71 (1e0e3868ee06e91ad636a874420e3ca3ae3756ac-refs/branch-heads/5359@{#1016}) on port 54167
Only local connections are allowed.
Please see https://chromedriver.chromium.org/security-considerations for suggestions on keeping ChromeDriver safe.
ChromeDriver was started successfully.
Dec 09, 2022 12:39:11 PM org.openqa.selenium.remote.ProtocolHandshake createSession
INFO: Detected upstream dialect: W3C
Dec 09, 2022 12:39:11 PM org.openqa.selenium.devtools.CdpVersionFinder findNearestMatch
WARNING: Unable to find an exact match for CDP version 108, so returning the closest version found: 106
Dec 09, 2022 12:39:11 PM org.openqa.selenium.devtools.CdpVersionFinder findNearestMatch
INFO: Found CDP implementation for version 108 of 106
[consoleEvent] 2022-12-09T11:39:12.035Z [log] [["simple", 1, "test", true]]
[consoleEvent] 2022-12-09T11:39:12.095Z [log] [["object", null]]
[consoleEvent] 2022-12-09T11:39:12.062Z [log] [["array", null]]
[consoleEvent] 2022-12-09T11:39:12.141Z [log] [["nested object", null]]

Operating System

Windows 10

Selenium version

Java 4.5.0

What are the browser(s) and version(s) where you see this issue?

Chrome 108

What are the browser driver(s) and version(s) where you see this issue?

ChromeDriver 108.0.5359.71

Are you using Selenium Grid?

No

@Wojciech-Kopec Wojciech-Kopec added I-defect Something is not working as intended A-needs-triaging A Selenium member will evaluate this soon! labels Dec 7, 2022
@Wojciech-Kopec Wojciech-Kopec changed the title [🐛 Bug]: DevTools - JSON Objects is consoleEvents are not properly mapped and lost (null) on listener call [🐛 Bug]: DevTools - RemoteObject.Type.OBJECT properties in consoleEvents are not properly mapped and lost (null) on listener call Dec 7, 2022
@github-actions
Copy link

github-actions bot commented Dec 7, 2022

@Wojciech-Kopec, thank you for creating this issue. We will troubleshoot it as soon as we can.


Info for maintainers

Triage this issue by using labels.

If information is missing, add a helpful comment and then I-issue-template label.

If the issue is a question, add the I-question label.

If the issue is valid but there is no time to troubleshoot it, consider adding the help wanted label.

If the issue requires changes or fixes from an external project (e.g., ChromeDriver, GeckoDriver, MSEdgeDriver, W3C), add the applicable G-* label, and it will provide the correct link and auto-close the issue.

After troubleshooting the issue, please add the R-awaiting answer label.

Thank you!

@diemol diemol added J-issue-template Applied to issues not following the template, or missing information. and removed A-needs-triaging A Selenium member will evaluate this soon! labels Dec 7, 2022
@github-actions
Copy link

github-actions bot commented Dec 7, 2022

Hi, @Wojciech-Kopec.
Please follow the issue template, we need more information to reproduce the issue.

Either a complete code snippet and URL/HTML (if more than one file is needed, provide a GitHub repo and instructions to run the code), the specific versions used, or a more detailed description to help us understand the issue.

Note: If you cannot share your code and URL/HTML, any complete code snippet and URL/HTML that reproduces the issue is good enough.

Reply to this issue when all information is provided, thank you.

@pujagani pujagani added C-java Java Bindings B-devtools Includes everything BiDi or Chrome DevTools related labels Dec 8, 2022
@Wojciech-Kopec
Copy link
Author

Reproduction added.

((JavascriptExecutor) driver).executeScript("console.log(\"simple\", 1, \"test\", true)");
((JavascriptExecutor) driver).executeScript("console.log(\"array\", [1, 2, 3])");
((JavascriptExecutor) driver).executeScript("console.log(\"object\", { a: 1 })");
((JavascriptExecutor) driver).executeScript("console.log(\"nested object\", { a: { b: 1 } })");

Prints:

[consoleEvent] 2022-12-09T11:39:12.035Z [log] [["simple", 1, "test", true]]
[consoleEvent] 2022-12-09T11:39:12.095Z [log] [["object", null]]
[consoleEvent] 2022-12-09T11:39:12.062Z [log] [["array", null]]
[consoleEvent] 2022-12-09T11:39:12.141Z [log] [["nested object", null]]

@pujagani
Copy link
Contributor

pujagani commented Dec 15, 2022

Thank you for providing the details. After reproducing and triaging it, I agree with the request made in this issue to make the args available as it is.
Meanwhile, till I fix the bug, to unblock things on your end, you can use the following code snippet instead of "addConsoleListener":

devTools.addListener(org.openqa.selenium.devtools.v108.runtime.Runtime.consoleAPICalled(),
                      consoleLog -> {
                          List<RemoteObject> remoteObjectList = consoleLog.getArgs();
                      });
          });

This gives access to the RemoteObject as expected.

@github-actions
Copy link

This issue has been automatically locked since there has not been any recent activity after it was closed. Please open a new issue for related bugs.

@github-actions github-actions bot locked and limited conversation to collaborators Jan 16, 2023
Sign up for free to subscribe to this conversation on GitHub. Already have an account? Sign in.
Labels
B-devtools Includes everything BiDi or Chrome DevTools related C-java Java Bindings I-defect Something is not working as intended J-issue-template Applied to issues not following the template, or missing information.
Projects
None yet
Development

Successfully merging a pull request may close this issue.

3 participants