{"version":3,"file":"BrowserPerformanceClient.js","sources":["../../src/telemetry/BrowserPerformanceClient.ts"],"sourcesContent":["/*\n * Copyright (c) Microsoft Corporation. All rights reserved.\n * Licensed under the MIT License.\n */\n\nimport { Logger, PerformanceEvent, PerformanceEvents, IPerformanceClient, PerformanceClient, IPerformanceMeasurement, InProgressPerformanceEvent, ApplicationTelemetry } from \"@azure/msal-common\";\nimport { CryptoOptions } from \"../config/Configuration\";\nimport { BrowserCrypto } from \"../crypto/BrowserCrypto\";\nimport { GuidGenerator } from \"../crypto/GuidGenerator\";\nimport { BrowserPerformanceMeasurement } from \"./BrowserPerformanceMeasurement\";\n\nexport class BrowserPerformanceClient extends PerformanceClient implements IPerformanceClient {\n private browserCrypto: BrowserCrypto;\n private guidGenerator: GuidGenerator;\n \n constructor(clientId: string, authority: string, logger: Logger, libraryName: string, libraryVersion: string, applicationTelemetry: ApplicationTelemetry, cryptoOptions: CryptoOptions) {\n super(clientId, authority, logger, libraryName, libraryVersion, applicationTelemetry);\n this.browserCrypto = new BrowserCrypto(this.logger, cryptoOptions);\n this.guidGenerator = new GuidGenerator(this.browserCrypto);\n }\n \n startPerformanceMeasurement(measureName: string, correlationId: string): IPerformanceMeasurement {\n return new BrowserPerformanceMeasurement(measureName, correlationId);\n }\n\n generateId() : string {\n return this.guidGenerator.generateGuid();\n }\n\n private getPageVisibility(): string | null {\n return document.visibilityState?.toString() || null;\n }\n \n /**\n * Starts measuring performance for a given operation. Returns a function that should be used to end the measurement.\n * Also captures browser page visibilityState.\n *\n * @param {PerformanceEvents} measureName\n * @param {?string} [correlationId]\n * @returns {((event?: Partial) => PerformanceEvent| null)}\n */\n startMeasurement(measureName: PerformanceEvents, correlationId?: string): InProgressPerformanceEvent {\n // Capture page visibilityState and then invoke start/end measurement\n const startPageVisibility = this.getPageVisibility();\n \n const inProgressEvent = super.startMeasurement(measureName, correlationId);\n\n return {\n ...inProgressEvent,\n endMeasurement: (event?: Partial): PerformanceEvent | null => {\n return inProgressEv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