Javascript performance API PerformanceResourceTiming returns 0 for most of properties

473 Views Asked by At

Currently I'm working on Angular application that let's user measure loading time of specific page. I'm loading that page from my app as an iframe in the background and want to measure specific timestamps of loading that iframe using javascript performance API. PerformanceResourceTiming interface is ideal for me because I can get specific times like DNS or TCP connection time (described here: https://developer.mozilla.org/en-US/docs/Web/Performance/Navigation_and_resource_timings). My problem is, that when I get my PerformanceResourceTiming object, most of the properties return values of 0 (although in DevTools -> Network they're not equal to 0). What am I doing wrong? Thank you in advance for your help.

enter image description here

1

There are 1 best solutions below

0
On

You may be using a CORS request. This requires the server providing the Timing-Allow-Origin HTTP header.

From MDM:

When CORS is in effect, many of the timing properties' values are returned as zero unless the server's access policy permits these values to be shared. This requires the server providing the resource to send the Timing-Allow-Origin HTTP response header with a value specifying the origin or origins which are allowed to get the restricted timestamp values.

e.g.: Timing-Allow-Origin: *