webapi: resource-timing

Adds resource timing, e.g. `performance.getEntriesByType("resource")`.

The `resource-timing` WPT category is currently at 4.6%, and this is a first
step at improving it. It also hopefully fixes https://github.com/lightpanda-io/browser/issues/3359

This is more complicated than I thought because there's a "Timing-Allow-Origin"
header that a server can include which hides some of the data if the request
doesn't come from the listed origin. And that, of course, interacts with
redirects.

(The DOMException change is seemingly random, but it came up in one of the WPT
cases I was looking at).
This commit is contained in:
Karl Seguin committed 2026-09-02 20:39:51 +08:00
1 parent 7d39a4fbaf
commit 872fd7d5ff
17 files changed
+1281 -53

No files matched your search

+27
View File
@@ -693,6 +693,33 @@ fn testHTTPHandler(req: *std.http.Server.Request) !void {
});
}
// Scripts, so a cross-origin (localhost) load doesn't depend on CORS.
if (std.mem.eql(u8, path, "/resource-timing/tao")) {
return req.respond("window.__rt_tao = true;", .{
.extra_headers = &.{
.{ .name = "Content-Type", .value = "text/javascript" },
.{ .name = "Timing-Allow-Origin", .value = "https://example.com, *" },
},
});
}
if (std.mem.eql(u8, path, "/resource-timing/plain")) {
return req.respond("window.__rt_plain = true;", .{
.extra_headers = &.{
.{ .name = "Content-Type", .value = "text/javascript" },
},
});
}
if (std.mem.eql(u8, path, "/resource-timing/redirect")) {
return req.respond("", .{
.status = .found,
.extra_headers = &.{
.{ .name = "Location", .value = "/resource-timing/plain" },
},
});
}
if (std.mem.eql(u8, path, "/redirect-no-fragment")) {
return req.respond("", .{
.status = .found,