Skip to content

Track online/offline status change#8410

Merged
tnorling merged 9 commits intov4-ltsfrom
v4-track-online-status-change
Mar 13, 2026
Merged

Track online/offline status change#8410
tnorling merged 9 commits intov4-ltsfrom
v4-track-online-status-change

Conversation

@tnorling
Copy link
Collaborator

This pull request enhances the MSAL browser library's ability to track and measure browser state changes related to both page visibility and online/offline status. It introduces new telemetry fields, refactors event listener management for improved maintainability, and updates tests and API documentation accordingly.

Browser state change tracking and telemetry improvements:

  • Added tracking for online/offline status changes alongside existing visibility change tracking in StandardController, including incrementing a new onlineStatusChangeCount field in performance measurements. [1] [2] [3] [4] [5]
  • Refactored event listener management by introducing addStateChangeListeners and removeStateChangeListeners methods to handle both visibility and online/offline events, improving code maintainability and reducing duplication. [1] [2] [3] [4] [5] [6] [7]

Performance measurement enhancements:

  • Updated BrowserPerformanceClient to capture the browser's online status at the start of a measurement and include it in the telemetry event as startOnlineStatus. [1] [2] [3]

Testing and API documentation:

  • Added a new unit test to verify that online status is correctly captured at the start of a performance measurement.
  • Extended the public API type PerformanceEvent to include the new startOnlineStatus and onlineStatusChangeCount fields. [1] [2]

Minor API cleanup:

  • Updated the signature of generateAppMetadataKey to use a single input parameter for clarity.

@tnorling tnorling requested a review from a team as a code owner March 10, 2026 23:13
Copilot AI review requested due to automatic review settings March 10, 2026 23:13
Copy link
Contributor

Copilot AI left a comment

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Pull request overview

Enhances MSAL browser telemetry to capture and count browser online/offline state changes alongside existing page visibility tracking, and surfaces these fields through performance events.

Changes:

  • Added startOnlineStatus and onlineStatusChangeCount to performance telemetry/types.
  • Refactored StandardController to centrally manage state-change listeners (visibility + online/offline).
  • Added a unit test to validate capturing online status at measurement start and updated API review outputs.

Reviewed changes

Copilot reviewed 7 out of 7 changed files in this pull request and generated 3 comments.

Show a summary per file
File Description
lib/msal-common/src/telemetry/performance/PerformanceEvent.ts Adds new performance telemetry fields for online status and online/offline change counts.
lib/msal-common/apiReview/msal-common.api.md Updates public API surface for new telemetry fields and a signature cleanup.
lib/msal-browser/src/telemetry/BrowserPerformanceClient.ts Captures navigator.onLine at measurement start and emits it in the perf event.
lib/msal-browser/test/telemetry/BrowserPerformanceClient.spec.ts Adds coverage for capturing online status at measurement start.
lib/msal-browser/src/controllers/StandardController.ts Tracks and counts online/offline transitions; refactors state-change event listener management.
change/@azure-msal-common-8fa830b2-239d-4c03-be8c-ec5db6810878.json Adds changelog entry for @azure/msal-common.
change/@azure-msal-browser-7c8cd0ee-be0c-4aa6-92e5-53e967084f87.json Adds changelog entry for @azure/msal-browser.

sameerag
sameerag previously approved these changes Mar 11, 2026
@tnorling
Copy link
Collaborator Author

@copilot Please update the apiExtractor reports

Copy link
Contributor

Copilot AI commented Mar 11, 2026

@tnorling I've opened a new pull request, #8415, to work on those changes. Once the pull request is ready, I'll request review from you.

…es (#8415)

API Extractor reports were out of sync with the source changes
introduced in this PR.

- **`msal-common` API review**: Updated `msal-common.api.md` to reflect
the `generateAppMetadataKey` signature change — destructured parameter
`{ environment, clientId }` instead of `input: AppMetadataEntity`
- **`msal-browser` API review**: Already up to date; no changes needed

The `startOnlineStatus` and `onlineStatusChangeCount` fields added to
`PerformanceEvent` were already correctly reflected in the previous
`apiExtractor` commit.

<!-- START COPILOT CODING AGENT TIPS -->
---

💡 You can make Copilot smarter by setting up custom instructions,
customizing its development environment and configuring Model Context
Protocol (MCP) servers. Learn more [Copilot coding agent
tips](https://gh.io/copilot-coding-agent-tips) in the docs.

---------

Co-authored-by: copilot-swe-agent[bot] <[email protected]>
Co-authored-by: tnorling <[email protected]>
@tnorling tnorling dismissed stale reviews from sameerag and konstantin-msft via 7b99d5e March 11, 2026 19:49
@tnorling tnorling enabled auto-merge (squash) March 11, 2026 20:10
@sameerag
Copy link
Member

@copilot can you rerun the validation checks to merge this PR?

Copy link
Contributor

Copilot AI commented Mar 13, 2026

@sameerag I've opened a new pull request, #8424, to work on those changes. Once the pull request is ready, I'll request review from you.

@tnorling tnorling merged commit eb893e5 into v4-lts Mar 13, 2026
6 of 10 checks passed
@tnorling tnorling deleted the v4-track-online-status-change branch March 13, 2026 02:54
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment

Labels

None yet

Projects

None yet

Development

Successfully merging this pull request may close these issues.

5 participants