docs: fix java console message snippet (#20171)

Fixes https://github.com/microsoft/playwright-java/issues/1168
This commit is contained in:
Yury Semikhatsky 2023-01-17 11:04:43 -08:00 committed by GitHub
parent 0656ab4811
commit c36827433d
No known key found for this signature in database
GPG Key ID: 4AEE18F83AFDEB23

View File

@ -28,16 +28,16 @@ await msg.args[1].jsonValue() // 42
```
```java
// Listen for all System.out.printlns
// Listen for all console messages and print them to the standard output.
page.onConsoleMessage(msg -> System.out.println(msg.text()));
// Listen for all console events and handle errors
// Listen for all console messages and print errors to the standard output.
page.onConsoleMessage(msg -> {
if ("error".equals(msg.type()))
System.out.println("Error text: " + msg.text());
});
// Get the next System.out.println
// Get the next console message
ConsoleMessage msg = page.waitForConsoleMessage(() -> {
// Issue console.log inside the page
page.evaluate("console.log('hello', 42, { foo: 'bar' });");