Send WillNavigate earlier during navigation startup (#37778)

The will-navigate message tells the devtools client to expect a
navigation for a browsing context. This makes the network monitor clear
any previous entries and show the requests for the new page that is
loaded. In order to support this correctly, we need to send the
navigation notification from the constellation instead of the script
thread, otherwise we silently ignore navigations triggered by the
browser URL bar.




Testing: Ran servo in devtools mode , now the requests appear for new
loaded page
Fixes: https://github.com/servo/servo/issues/37334

---------

Signed-off-by: Uthman Yahaya Baba <uthmanyahayababa@gmail.com>
This commit is contained in:
Usman Yahaya Baba 2025-07-05 12:35:37 +01:00 committed by GitHub
parent 864c877be5
commit 2ad5b24225
No known key found for this signature in database
GPG key ID: B5690EEEBB952194
13 changed files with 197 additions and 112 deletions

View file

@ -41,6 +41,7 @@ pub struct NetworkEventActor {
pub total_time: Duration,
pub security_state: String,
pub event_timing: Option<Timings>,
pub watcher_name: String,
}
#[derive(Clone, Serialize)]
@ -342,7 +343,7 @@ impl Actor for NetworkEventActor {
}
impl NetworkEventActor {
pub fn new(name: String, resource_id: u64) -> NetworkEventActor {
pub fn new(name: String, resource_id: u64, watcher_name: String) -> NetworkEventActor {
NetworkEventActor {
name,
resource_id,
@ -367,6 +368,7 @@ impl NetworkEventActor {
total_time: Duration::ZERO,
security_state: "insecure".to_owned(),
event_timing: None,
watcher_name,
}
}

View file

@ -14,9 +14,11 @@ use std::collections::HashMap;
use std::net::TcpStream;
use std::time::{SystemTime, UNIX_EPOCH};
use base::id::BrowsingContextId;
use log::warn;
use serde::Serialize;
use serde_json::{Map, Value};
use servo_url::ServoUrl;
use self::network_parent::{NetworkParentActor, NetworkParentActorMsg};
use super::breakpoint::BreakpointListActor;
@ -33,7 +35,7 @@ use crate::actors::watcher::thread_configuration::{
};
use crate::protocol::JsonPacketStream;
use crate::resource::{ResourceArrayType, ResourceAvailable};
use crate::{EmptyReplyMsg, StreamId, WorkerActor};
use crate::{EmptyReplyMsg, IdMap, StreamId, WorkerActor};
pub mod network_parent;
pub mod target_configuration;
@ -79,7 +81,7 @@ impl SessionContext {
("local-storage", false),
("session-storage", false),
("platform-message", false),
("network-event", false),
("network-event", true),
("network-event-stacktrace", false),
("reflow", false),
("stylesheet", false),
@ -192,6 +194,19 @@ pub struct WatcherActor {
session_context: SessionContext,
}
#[derive(Clone, Serialize)]
#[serde(rename_all = "camelCase")]
pub struct WillNavigateMessage {
#[serde(rename = "browsingContextID")]
browsing_context_id: u32,
inner_window_id: u32,
name: String,
time: u128,
is_frame_switching: bool,
#[serde(rename = "newURI")]
new_uri: ServoUrl,
}
impl Actor for WatcherActor {
fn name(&self) -> String {
self.name.clone()
@ -322,6 +337,7 @@ impl Actor for WatcherActor {
}
},
"console-message" | "error-message" => {},
"network-event" => {},
_ => warn!("resource {} not handled yet", resource),
}
@ -385,6 +401,12 @@ impl Actor for WatcherActor {
}
}
impl ResourceAvailable for WatcherActor {
fn actor_name(&self) -> String {
self.name.clone()
}
}
impl WatcherActor {
pub fn new(
actors: &mut ActorRegistry,
@ -422,4 +444,33 @@ impl WatcherActor {
},
}
}
pub fn emit_will_navigate(
&self,
browsing_context_id: BrowsingContextId,
url: ServoUrl,
connections: &mut Vec<TcpStream>,
id_map: &mut IdMap,
) {
let msg = WillNavigateMessage {
browsing_context_id: id_map.browsing_context_id(browsing_context_id).value(),
inner_window_id: 0, // TODO: set this to the correct value
name: "will-navigate".to_string(),
time: SystemTime::now()
.duration_since(UNIX_EPOCH)
.unwrap_or_default()
.as_millis(),
is_frame_switching: false, // TODO: Implement frame switching
new_uri: url,
};
for stream in connections {
self.resource_array(
msg.clone(),
"document-event".to_string(),
ResourceArrayType::Available,
stream,
);
}
}
}