playwright/imp/
console_message.rs1use crate::imp::{core::*, js_handle::JsHandle, prelude::*, utils::SourceLocation};
2
3#[derive(Debug)]
4pub(crate) struct ConsoleMessage {
5 channel: ChannelOwner,
6 location: SourceLocation,
7 args: Vec<Weak<JsHandle>>
8}
9
10impl ConsoleMessage {
11 pub(crate) fn try_new(ctx: &Context, channel: ChannelOwner) -> Result<Self, Error> {
12 #[derive(Deserialize)]
13 struct De {
14 location: SourceLocation,
15 args: Vec<OnlyGuid>
16 }
17 let De { location, args } = serde_json::from_value(channel.initializer.clone())?;
18 let args = args
19 .iter()
20 .map(|OnlyGuid { guid }| get_object!(ctx, guid, JsHandle))
21 .collect::<Result<Vec<_>, _>>()?;
22 Ok(Self {
23 channel,
24 location,
25 args
26 })
27 }
28
29 pub(crate) fn r#type(&self) -> &str {
30 self.channel()
31 .initializer
32 .get("type")
33 .and_then(|v| v.as_str())
34 .unwrap_or_default()
35 }
36
37 pub(crate) fn text(&self) -> &str {
38 self.channel()
39 .initializer
40 .get("text")
41 .and_then(|v| v.as_str())
42 .unwrap_or_default()
43 }
44
45 pub(crate) fn location(&self) -> &SourceLocation { &self.location }
46
47 pub(crate) fn args(&self) -> &[Weak<JsHandle>] { &self.args }
48}
49
50impl RemoteObject for ConsoleMessage {
51 fn channel(&self) -> &ChannelOwner { &self.channel }
52 fn channel_mut(&mut self) -> &mut ChannelOwner { &mut self.channel }
53}