Files
servo/components/devtools/resource.rs
eri 8cf4955731 devtools: Correctly cache console messages (#41895)
Fix caching before the console is opened and stop sending messages
prematurely.

Fix line numbers not showing in console messages because of a missing
`rename_all`.

Remove `getCachedMessages` in favour of sending a list of messages as a
reply to the `watchResources` for `console-message`/`error-message` in
the watcher.

Remove `startListeners` and `stopListeners`. These are legacy methods of
watching properties before the watcher actor. It is preferred to enable
properties in `supported_resources` in the watcher than to use these
messages.

Remove `clearMessagesCache`, only `clearMessagesCacheAsync` seems to be
used now. Add a reply to `clearMessagesCacheAsync`.

Simplify a bit the structs for console messages and prefer serde's
annotations to manual serialization. Merge `handle_console_message` and
`handle_page_error`, and improve the usability of `ConsoleResource`.

Fix some fields in console messages. We are missing `source_id` for now.
This will be easier to add after better support for source actors. We
are also missing stack traces.

| Before | After |
| --- | --- |
| ![Console message list starting at 5 and counting up, showing the file
location but not the line
number](https://github.com/user-attachments/assets/b21159b4-1a95-46aa-9337-0004a922837c)
| ![Console message list starting at 1, showing both the file location
and line number. It says "Connected here" at message number
4](https://github.com/user-attachments/assets/f8ea1a7c-9262-4fa2-a882-cad35af9c2dc)
|

Testing: Manual testing
Fixes: #26666

---------

Signed-off-by: eri <eri@igalia.com>
Co-authored-by: Martin Robinson <mrobinson@igalia.com>
2026-01-15 21:41:07 +00:00

58 lines
1.5 KiB
Rust

/* This Source Code Form is subject to the terms of the Mozilla Public
* License, v. 2.0. If a copy of the MPL was not distributed with this
* file, You can obtain one at https://mozilla.org/MPL/2.0/. */
use serde::Serialize;
use crate::protocol::JsonPacketStream;
pub enum ResourceArrayType {
Available,
Updated,
}
#[derive(Serialize)]
pub(crate) struct ResourceAvailableReply<T: Serialize> {
from: String,
#[serde(rename = "type")]
type_: String,
array: Vec<(String, Vec<T>)>,
}
pub(crate) trait ResourceAvailable {
fn actor_name(&self) -> String;
fn resource_array<T: Serialize, S: JsonPacketStream>(
&self,
resource: T,
resource_type: String,
array_type: ResourceArrayType,
stream: &mut S,
) {
self.resources_array(vec![resource], resource_type, array_type, stream);
}
fn resources_array<T: Serialize, S: JsonPacketStream>(
&self,
resources: Vec<T>,
resource_type: String,
array_type: ResourceArrayType,
stream: &mut S,
) {
if resources.is_empty() {
return;
}
let msg = ResourceAvailableReply::<T> {
from: self.actor_name(),
type_: match array_type {
ResourceArrayType::Available => "resources-available-array".to_string(),
ResourceArrayType::Updated => "resources-updated-array".to_string(),
},
array: vec![(resource_type, resources)],
};
let _ = stream.write_json_packet(&msg);
}
}