Package com.microsoft.playwright
Interface ConsoleMessage
- All Known Implementing Classes:
ConsoleMessageImpl
public interface ConsoleMessage
ConsoleMessage objects are dispatched by page via the Page.onConsoleMessage()
event. For each console messages logged in the page there will be corresponding event in the Playwright context.
// Listen for all console messages and print them to the standard output.
page.onConsoleMessage(msg -> System.out.println(msg.text()));
// 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 console message
ConsoleMessage msg = page.waitForConsoleMessage(() -> {
// Issue console.log inside the page
page.evaluate("console.log('hello', 42, { foo: 'bar' });");
});
// Deconstruct console.log arguments
msg.args().get(0).jsonValue() // hello
msg.args().get(1).jsonValue() // 42
-
Method Summary
Modifier and TypeMethodDescriptionargs()List of arguments passed to aconsolefunction call.location()URL of the resource followed by 0-based line and column numbers in the resource formatted asURL:line:column.page()The page that produced this console message, if any.text()The text of the console message.type()One of the following values:"log","debug","info","error","warning","dir","dirxml","table","trace","clear","startGroup","startGroupCollapsed","endGroup","assert","profile","profileEnd","count","timeEnd".
-
Method Details
-
args
List of arguments passed to aconsolefunction call. See alsoPage.onConsoleMessage().- Since:
- v1.8
-
location
String location()URL of the resource followed by 0-based line and column numbers in the resource formatted asURL:line:column.- Since:
- v1.8
-
page
Page page()The page that produced this console message, if any.- Since:
- v1.34
-
text
String text()The text of the console message.- Since:
- v1.8
-
type
String type()One of the following values:"log","debug","info","error","warning","dir","dirxml","table","trace","clear","startGroup","startGroupCollapsed","endGroup","assert","profile","profileEnd","count","timeEnd".- Since:
- v1.8
-