mirror of
https://github.com/servo/servo.git
synced 2025-08-06 06:00:15 +01:00
DevTools: Display console messages and errors (#32727)
* feat: add streams to browsing context * feat: console now works! * feat: order console messages * feat: add streams to new browsing contexts * fix: apply suggestions Co-authored-by: Martin Robinson <mrobinson@igalia.com> --------- Co-authored-by: Martin Robinson <mrobinson@igalia.com>
This commit is contained in:
parent
34d9be70f9
commit
33f3c34d28
6 changed files with 141 additions and 119 deletions
|
@ -12,7 +12,7 @@ use std::net::TcpStream;
|
|||
|
||||
use base::id::{BrowsingContextId, PipelineId};
|
||||
use devtools_traits::DevtoolScriptControlMsg::{self, WantsLiveNotifications};
|
||||
use devtools_traits::{DevtoolsPageInfo, NavigationState};
|
||||
use devtools_traits::{ConsoleLog, DevtoolsPageInfo, NavigationState, PageError};
|
||||
use ipc_channel::ipc::IpcSender;
|
||||
use serde::Serialize;
|
||||
use serde_json::{Map, Value};
|
||||
|
@ -70,6 +70,36 @@ struct ResourceAvailableMsg {
|
|||
url: Option<String>,
|
||||
}
|
||||
|
||||
#[derive(Serialize)]
|
||||
struct ConsoleMsg {
|
||||
from: String,
|
||||
#[serde(rename = "type")]
|
||||
type_: String,
|
||||
resources: Vec<ConsoleMessageResource>,
|
||||
}
|
||||
|
||||
#[derive(Serialize)]
|
||||
#[serde(rename_all = "camelCase")]
|
||||
struct ConsoleMessageResource {
|
||||
message: ConsoleLog,
|
||||
resource_type: String,
|
||||
}
|
||||
|
||||
#[derive(Serialize)]
|
||||
struct PageErrorMsg {
|
||||
from: String,
|
||||
#[serde(rename = "type")]
|
||||
type_: String,
|
||||
resources: Vec<PageErrorResource>,
|
||||
}
|
||||
|
||||
#[derive(Serialize)]
|
||||
#[serde(rename_all = "camelCase")]
|
||||
struct PageErrorResource {
|
||||
page_error: PageError,
|
||||
resource_type: String,
|
||||
}
|
||||
|
||||
#[derive(Serialize)]
|
||||
struct TabNavigated {
|
||||
from: String,
|
||||
|
@ -347,7 +377,7 @@ impl BrowsingContextActor {
|
|||
from: self.name(),
|
||||
type_: "resource-available-form".into(),
|
||||
resources: vec![ResourceAvailableMsg {
|
||||
has_native_console_api: None,
|
||||
has_native_console_api: Some(true),
|
||||
name: name.into(),
|
||||
new_uri: None,
|
||||
resource_type: "document-event".into(),
|
||||
|
@ -358,4 +388,34 @@ impl BrowsingContextActor {
|
|||
});
|
||||
}
|
||||
}
|
||||
|
||||
pub(crate) fn console_message(&self, message: ConsoleLog) {
|
||||
let msg = ConsoleMsg {
|
||||
from: self.name(),
|
||||
type_: "resource-available-form".into(),
|
||||
resources: vec![ConsoleMessageResource {
|
||||
message,
|
||||
resource_type: "console-message".into(),
|
||||
}],
|
||||
};
|
||||
|
||||
for stream in self.streams.borrow_mut().values_mut() {
|
||||
let _ = stream.write_json_packet(&msg);
|
||||
}
|
||||
}
|
||||
|
||||
pub(crate) fn page_error(&self, page_error: PageError) {
|
||||
let msg = PageErrorMsg {
|
||||
from: self.name(),
|
||||
type_: "resource-available-form".into(),
|
||||
resources: vec![PageErrorResource {
|
||||
page_error,
|
||||
resource_type: "error-message".into(),
|
||||
}],
|
||||
};
|
||||
|
||||
for stream in self.streams.borrow_mut().values_mut() {
|
||||
let _ = stream.write_json_packet(&msg);
|
||||
}
|
||||
}
|
||||
}
|
||||
|
|
Loading…
Add table
Add a link
Reference in a new issue