pub struct ConsoleMessage { /* private fields */ }Expand description
Represents a console message emitted by a page.
ConsoleMessage objects are dispatched by the "console" event on both
Page (via on_console) and
BrowserContext (via on_console).
Implementations§
Source§impl ConsoleMessage
impl ConsoleMessage
Sourcepub fn type_(&self) -> &str
pub fn type_(&self) -> &str
Returns the console message type.
Possible values: "log", "debug", "info", "error", "warning",
"dir", "dirxml", "table", "trace", "clear", "startGroup",
"startGroupCollapsed", "endGroup", "assert", "profile",
"profileEnd", "count", "timeEnd".
See: https://playwright.dev/docs/api/class-consolemessage#console-message-type
Sourcepub fn text(&self) -> &str
pub fn text(&self) -> &str
Returns the text representation of the console message arguments.
See: https://playwright.dev/docs/api/class-consolemessage#console-message-text
Sourcepub fn location(&self) -> &ConsoleMessageLocation
pub fn location(&self) -> &ConsoleMessageLocation
Returns the source location of the console message.
See: https://playwright.dev/docs/api/class-consolemessage#console-message-location
Sourcepub fn page(&self) -> Option<&Page>
pub fn page(&self) -> Option<&Page>
Returns the page that produced the console message, if available.
May be None if the page has already been closed or if the message
originated in a context where the page cannot be resolved.
See: https://playwright.dev/docs/api/class-consolemessage#console-message-page
Sourcepub fn timestamp(&self) -> f64
pub fn timestamp(&self) -> f64
Returns the timestamp when this console message was emitted.
The value is the number of milliseconds since the Unix epoch (January 1, 1970 UTC),
as a floating-point number. This matches the value sent by the Playwright server
in the "console" event payload.
See: https://playwright.dev/docs/api/class-consolemessage#console-message-timestamp
Sourcepub fn args(&self) -> &[Arc<JSHandle>]
pub fn args(&self) -> &[Arc<JSHandle>]
Returns the list of arguments passed to the console method.
Each argument is a JSHandle that can be
inspected via json_value(), get_property(), etc.
§Example
let playwright = Playwright::launch().await?;
let browser = playwright.chromium().launch().await?;
let page = browser.new_page().await?;
let captured = Arc::new(Mutex::new(None));
let cap = captured.clone();
page.on_console(move |msg| {
let cap = cap.clone();
async move {
*cap.lock().unwrap() = Some(msg.args().to_vec());
Ok(())
}
}).await?;
page.evaluate_expression("console.log('hello', 42)").await?;
tokio::time::sleep(Duration::from_millis(200)).await;
let args = captured.lock().unwrap().take().unwrap();
assert_eq!(args.len(), 2);
let first = args[0].json_value().await?;
assert_eq!(first, serde_json::json!("hello"));See: https://playwright.dev/docs/api/class-consolemessage#console-message-args
Trait Implementations§
Source§impl Clone for ConsoleMessage
impl Clone for ConsoleMessage
Source§fn clone(&self) -> ConsoleMessage
fn clone(&self) -> ConsoleMessage
1.0.0 · Source§fn clone_from(&mut self, source: &Self)
fn clone_from(&mut self, source: &Self)
source. Read more