Currently I am generating metrics on my web application by raising an event with a name and an associated absolute timestamp. These events are aggregated in a central repository of events that looks something like:
const metricEvents = [
{ name: appStart, time: window.performance.timing.responseStart }
]
metricEvents.push({ name: 'interactive', time: new Date().getTime() })
I can then subtract the end time from the start time and obtain a duration for that task.
My web application makes use of Web Workers and cross origin iframes, all of which contribute metric events of their own.
Currently it's pretty simple for me to send absolute timestamps from the workers/frames and still calculate the durations of events from points (e.g. A -> C or B -> E).
I see that PerformanceTiming is deprecated in favour of PerformanceNavigationTiming. The issue is that PerformanceNavigationTiming gives back relative times relavent to the current entity (frame, worker, host). This means I am no longer able to use my existing approach to calculate the task times.
Instinctively I look to obtain an absolute timestamps from the new PerformanceNavigationTiming API, is that possible or is there a better way to approach this objective with the new API?
The Performance object has a timeOrigin property. You can use it to get absolute timings accross several contexts.
You can see this example from the specs which illustrate exactly your case.