microsoft / microsoft/ApplicationInsights-JS
Chrome: Deprecation - Unload event listeners are deprecated and will be removed
Nobody has claimed this yet.
- Dominant language
- TypeScript
- Stars
- 685
- Forks
- 261
- Avg merge
- 21h 33m
- Merged PRs (30d)
- 5
Description
Description/Screenshot
Chrome indicates an issue when using @microsoft/applicationinsights-web version 3.0.6.
"Deprecated feature used"
"Unload event listeners are deprecated and will be removed."
Steps to Reproduce
- OS/Browser:
22.0.6170.5 (Official Build) dev (64-bit) (cohort: Dev)
Windows 11 Version 22H2 (Build 22621.2428) - SDK Version [e.g. 22]:
@microsoft/applicationinsights-web version 3.0.6 - How you initialized the SDK:
import { ApplicationInsights } from "@microsoft/applicationinsights-web";
import { isNullOrWhitespace } from "../data";
let initialized = false;
let appInsights: ApplicationInsights | null;
export function aiInit(
connectionString: string,
appName: string,
userName?: string) {
if (initialized) {
console.log("Telemetry already initialized");
return;
}
appInsights = new ApplicationInsights({
config: {
connectionString: connectionString,
maxBatchInterval: 0,
disableFetchTracking: false
}
});
appInsights.loadAppInsights();
const userNameProvided = !isNullOrWhitespace(userName);
if (userNameProvided) {
appInsights.setAuthenticatedUserContext(userName!, undefined, true);
}
appInsights.addTelemetryInitializer(envelope => {
if (envelope.tags != null) {
envelope.tags["ai.cloud.role"] = appName;
if (userNameProvided) {
envelope.tags["ai.user.id"] = userName!;
}
}
});
appInsights.trackPageView();
initialized = true;
}
export function ai(): ApplicationInsights {
if (!initialized || appInsights == null) {
throw new Error("Telemetry not initialized");
}
return appInsights;
}
Expected behavior
No issue
Contributor guide
First steps
- Read the whole issue, then the project's contributing guide.
- Comment on the issue to say you are picking it up — it saves two people doing the same work.
- Fork the repository and make your change on a branch.
- Open a pull request that references the issue number.
Research direction
Start by reproducing the warning with @microsoft/applicationinsights-web 3.0.6 in the Chrome version and initialization flow shown, especially loadAppInsights(). Trace which SDK path registers the unload listener. Done means the reported deprecation warning no longer appears while the expected telemetry behavior remains intact.
Written by the indexing model from the issue text.
Assessment
- Tech stack
- typescript
- Domain
- observability
- Issue type
- Bug
- Difficulty
- 4/5
- Estimated time
- 3-5 days
- Activity status
- Stale
- Clarity
- Needs clarification
- Newbie friendliness
- 25/100