Increase event timeStamp resolution

Depends on https://github.com/lightpanda-io/libdom/pull/36

The spec says this should be a High Definition timestamp. But browsers avoid
that in order to avoid fingerprinting. By default, FireFox rounds to 2ms (which
is what this PR does).

Previously, the timestamp was seconds, so you'd think: isn't that better? Well,
it's pretty far off the spec and what browsers do, but more importantly, it
crashes our WPT test. If you look at `Event-timestamp-safe-resolution.html`
you'll see that it's trying to find the delta between two timestamps, in an
endless loop (without a loop of many iterations). With second-resolution, it
just takes too long (and crashes..memory).
This commit is contained in:
Karl Seguin
2025-09-11 15:53:34 +08:00
parent b5e2c62fdd
commit 80f758018c
3 changed files with 5 additions and 5 deletions

View File

@@ -113,7 +113,7 @@ pub const Event = struct {
// Even though this is supposed to to provide microsecond resolution, browser
// return coarser values to protect against fingerprinting. libdom returns
// seconds, which is good enough.
pub fn get_timeStamp(self: *parser.Event) !u32 {
pub fn get_timeStamp(self: *parser.Event) !u64 {
return parser.eventTimestamp(self);
}

View File

@@ -505,11 +505,11 @@ pub fn eventIsTrusted(evt: *Event) !bool {
return res;
}
pub fn eventTimestamp(evt: *Event) !u32 {
var ts: c_uint = undefined;
pub fn eventTimestamp(evt: *Event) !u64 {
var ts: u64 = 0;
const err = c._dom_event_get_timestamp(evt, &ts);
try DOMErr(err);
return @as(u32, @intCast(ts));
return ts;
}
pub fn eventStopPropagation(evt: *Event) !void {