mirror of
https://github.com/lexmount/moli.git
synced 2026-10-05 00:00:55 +00:00
fix(resource-timing): ignore non-http resources
This commit is contained in:
@@ -278,6 +278,9 @@ pub(crate) fn record_resource_performance_entry(
|
||||
scope: &mut v8::PinScope<'_, '_>,
|
||||
entry: ResourcePerformanceEntry,
|
||||
) {
|
||||
if !url::Url::parse(&entry.name).is_ok_and(|url| matches!(url.scheme(), "http" | "https")) {
|
||||
return;
|
||||
}
|
||||
let Some(performance) = window_performance_value(scope) else {
|
||||
window_state::queue_pending_resource_entry(scope, entry);
|
||||
return;
|
||||
|
||||
@@ -43,6 +43,29 @@ fn record_failed_script_resource(vm: &mut ScriptVm, document_url: &Url, resource
|
||||
vm.record_script_subresource_network_result(document_url.clone(), request_url, &result);
|
||||
}
|
||||
|
||||
#[test]
|
||||
fn resource_timing_ignores_non_http_resources() {
|
||||
let mut vm = new_storage_test_vm("https://resource-scheme.test/");
|
||||
install_test_resource_recorder(&mut vm);
|
||||
|
||||
vm.eval(
|
||||
r#"
|
||||
__recordResourceTiming("data:image/gif;base64,R0lGODlhAQABAIAAAAUEBA==");
|
||||
__recordResourceTiming("blob:https://resource-scheme.test/id");
|
||||
__recordResourceTiming("https://resource-scheme.test/image.png");
|
||||
"#,
|
||||
)
|
||||
.expect("resource timing scheme records should evaluate");
|
||||
|
||||
assert_eq!(
|
||||
vm.eval(
|
||||
r#"JSON.stringify(performance.getEntriesByType("resource").map(entry => entry.name))"#
|
||||
)
|
||||
.expect("resource timing scheme entries should evaluate"),
|
||||
r#"["https://resource-scheme.test/image.png"]"#
|
||||
);
|
||||
}
|
||||
|
||||
#[test]
|
||||
fn resource_timing_default_buffer_is_finite_and_fires_event_handler() {
|
||||
let document_url = Url::parse("https://resource-buffer-default.test/").expect("document URL");
|
||||
|
||||
Reference in New Issue
Block a user