playwright/api/
console_message.rs

1use crate::{
2    api::JsHandle,
3    imp::{console_message::ConsoleMessage as Impl, core::*, prelude::*, utils::SourceLocation}
4};
5
6/// `ConsoleMessage` objects are dispatched by page via the [page::Event::Console](crate::api::page::Event::Console) event.
7#[derive(Clone)]
8pub struct ConsoleMessage {
9    inner: Weak<Impl>
10}
11
12impl ConsoleMessage {
13    pub(crate) fn new(inner: Weak<Impl>) -> Self { Self { inner } }
14
15    /// One of the following values: `'log'`, `'debug'`, `'info'`, `'error'`, `'warning'`, `'dir'`, `'dirxml'`, `'table'`,
16    /// `'trace'`, `'clear'`, `'startGroup'`, `'startGroupCollapsed'`, `'endGroup'`, `'assert'`, `'profile'`, `'profileEnd'`,
17    /// `'count'`, `'timeEnd'`.
18    pub fn r#type(&self) -> Result<String, Error> { Ok(upgrade(&self.inner)?.r#type().into()) }
19
20    /// The text of the console message.
21    pub fn text(&self) -> Result<String, Error> { Ok(upgrade(&self.inner)?.text().into()) }
22
23    /// URL of the resource followed by 0-based line and column numbers in the resource formatted as `URL:line:column`.
24    pub fn location(&self) -> Result<SourceLocation, Error> {
25        Ok(upgrade(&self.inner)?.location().to_owned())
26    }
27
28    /// List of arguments passed to a `console` function call.
29    pub fn args(&self) -> Result<Vec<JsHandle>, Error> {
30        Ok(upgrade(&self.inner)?
31            .args()
32            .iter()
33            .map(|x| JsHandle::new(x.clone()))
34            .collect())
35    }
36}