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