{"version":3,"file":"BrowserPerformanceMeasurement.js","sources":["../../src/telemetry/BrowserPerformanceMeasurement.ts"],"sourcesContent":["/*\r\n * Copyright (c) Microsoft Corporation. All rights reserved.\r\n * Licensed under the MIT License.\r\n */\r\n\r\nimport { IPerformanceMeasurement, SubMeasurement } from \"@azure/msal-common\";\r\n\r\nexport class BrowserPerformanceMeasurement implements IPerformanceMeasurement {\r\n private readonly measureName: string;\r\n private readonly correlationId: string;\r\n private readonly startMark: string;\r\n private readonly endMark: string;\r\n\r\n constructor(name: string, correlationId: string) {\r\n this.correlationId = correlationId;\r\n this.measureName = BrowserPerformanceMeasurement.makeMeasureName(name, correlationId);\r\n this.startMark = BrowserPerformanceMeasurement.makeStartMark(name, correlationId);\r\n this.endMark = BrowserPerformanceMeasurement.makeEndMark(name, correlationId);\r\n }\r\n\r\n private static makeMeasureName(name: string, correlationId: string) {\r\n return `msal.measure.${name}.${correlationId}`;\r\n }\r\n\r\n private static makeStartMark(name: string, correlationId: string) {\r\n return `msal.start.${name}.${correlationId}`;\r\n }\r\n\r\n private static makeEndMark(name: string, correlationId: string) {\r\n return `msal.end.${name}.${correlationId}`;\r\n }\r\n\r\n static supportsBrowserPerformance(): boolean {\r\n return typeof window !== \"undefined\" &&\r\n typeof window.performance !== \"undefined\" &&\r\n typeof window.performance.mark === \"function\" &&\r\n typeof window.performance.measure === \"function\" &&\r\n typeof window.performance.clearMarks === \"function\" &&\r\n typeof window.performance.clearMeasures === \"function\" &&\r\n typeof window.performance.getEntriesByName === \"function\";\r\n }\r\n\r\n /**\r\n * Flush browser marks and measurements.\r\n * @param {string} correlationId\r\n * @param {SubMeasurement} measurements\r\n */\r\n public static flushMeasurements(correlationId: string, measurements: SubMeasurement[]): void {\r\n if (BrowserPerformanceMeasurement.supportsBrowserPerformance()) {\r\n try {\r\n measurements.forEach((measurement) => {\r\n const measureName = BrowserPerformanceMeasurement.makeMeasureName(measurement.name, correlationId);\r\n const entriesForMeasurement = window.performance.getEntriesByName(measureName, \"measure\");\r\n if (entriesForMeasurement.length > 0) {\r\n window.performance.clearMeasures(measureName);\r\n window.performance.clearMarks(BrowserPerformanceMeasurement.makeStartMark(measureName, correlationId));\r\n window.performance.clearMarks(BrowserPerformanceMeasurement.makeEndMark(measureName, correlationId));\r\n }\r\n });\r\n } catch (e) {\r\n // Silently catch and return null\r\n }\r\n }\r\n }\r\n\r\n startMeasurement(): void {\r\n if (BrowserPerformanceMeasurement.supportsBrowserPerformance()) {\r\n try {\r\n window.performance.mark(this.startMark);\r\n } catch (e) {\r\n // Silently catch\r\n }\r\n }\r\n }\r\n\r\n endMeasurement():void {\r\n if (BrowserPerformanceMeasurement.supportsBrowserPerformance()) {\r\n try {\r\n window.performance.mark(this.endMark);\r\n window.performance.measure(this.measureName, this.startMark, this.endMark);\r\n } catch (e) {\r\n // Silently catch\r\n }\r\n }\r\n }\r\n\r\n flushMeasurement(): number | null {\r\n if (BrowserPerformanceMeasurement.supportsBrowserPerformance()) {\r\n try {\r\n const entriesForMeasurement = window.performance.getEntriesByName(this.measureName, \"measure\");\r\n if (entriesForMeasurement.length > 0) {\r\n const durationMs = entriesForMeasurement[0].duration;\r\n window.performance.clearMeasures(this.measureName);\r\n window.performance.clearMarks(this.startMark);\r\n window.performance.clearMarks(this.endMark);\r\n return durationMs;\r\n }\r\n } catch (e) {\r\n // Silently catch and return null\r\n }\r\n }\r\n return null;\r\n }\r\n}\r\n"],"names":[],"mappings":";;AAAA;;;;;IAaI,uCAAY,IAAY,EAAE,aAAqB;QAC3C,IAAI,CAAC,aAAa,GAAG,aAAa,CAAC;QACnC,IAAI,CAAC,WAAW,GAAG,6BAA6B,CAAC,eAAe,CAAC,IAAI,EAAE,aAAa,CAAC,CAAC;QACtF,IAAI,CAAC,SAAS,GAAG,6BAA6B,CAAC,aAAa,CAAC,IAAI,EAAE,aAAa,CAAC,CAAC;QAClF,IAAI,CAAC,OAAO,GAAG,6BAA6B,CAAC,WAAW,CAAC,IAAI,EAAE,aAAa,CAAC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