Skip to content

Commit 02e659a

Browse files
committed
[main] Handle race condition during unload (#2507)
1 parent e147a41 commit 02e659a

File tree

3 files changed

+24
-23
lines changed

3 files changed

+24
-23
lines changed

channels/applicationinsights-channel-js/src/Sender.ts

Lines changed: 22 additions & 8 deletions
Original file line numberDiff line numberDiff line change
@@ -656,7 +656,12 @@ export class Sender extends BaseTelemetryPlugin implements IChannelControls {
656656
endpoint: _endpointUrl,
657657
version: EnvelopeCreator.Version
658658
} as IStatsBeatConfig;
659-
return _self.core.getStatsBeat(statsBeatConfig);
659+
660+
let core = _self.core;
661+
662+
// During page unload the core may have been cleared and some async events may not have been sent yet
663+
// resulting in the core being null. In this case we don't want to create a statsbeat instance
664+
return core ? core.getStatsBeat(statsBeatConfig) : null;
660665
}
661666

662667
function _xdrOnLoad (xdr: IXDomainRequest, payload: IInternalStorageItem[]) {
@@ -1304,12 +1309,21 @@ export class Sender extends BaseTelemetryPlugin implements IChannelControls {
13041309
// Using function lookups for backward compatibility as the getNotifyMgr() did not exist until after v2.5.6
13051310
function _getNotifyMgr() : INotificationManager {
13061311
const func = "getNotifyMgr";
1307-
if (_self.core[func]) {
1308-
return _self.core[func]();
1312+
let result: INotificationManager;
1313+
let core = _self.core;
1314+
if (core) {
1315+
// During page unload the core may have been cleared and some async events may not have been sent yet
1316+
// resulting in the core being null. In this case we don't want to create a statsbeat instance
1317+
1318+
if (core[func]) {
1319+
result = core[func]();
1320+
} else {
1321+
// using _self.core['_notificationManager'] for backward compatibility
1322+
result = (core as any)["_notificationManager"];
1323+
}
13091324
}
13101325

1311-
// using _self.core['_notificationManager'] for backward compatibility
1312-
return _self.core["_notificationManager"];
1326+
return result;
13131327
}
13141328

13151329
function _notifySendRequest(sendRequest: SendRequestReason, isAsync: boolean) {
@@ -1469,7 +1483,7 @@ export class Sender extends BaseTelemetryPlugin implements IChannelControls {
14691483

14701484
/**
14711485
* error handler
1472-
* @Internal
1486+
* @internal
14731487
* since version 3.2.0, if the payload is string[], this function is no-op (string[] is only used for backwards Compatibility)
14741488
*/
14751489
public _onError(payload: string[] | IInternalStorageItem[], message: string, event?: ErrorEvent) {
@@ -1478,7 +1492,7 @@ export class Sender extends BaseTelemetryPlugin implements IChannelControls {
14781492

14791493
/**
14801494
* partial success handler
1481-
* @Internal
1495+
* @internal
14821496
* since version 3.2.0, if the payload is string[], this function is no-op (string[] is only used for backwards Compatibility)
14831497
*/
14841498
public _onPartialSuccess(payload: string[] | IInternalStorageItem[], results: IBackendResponse) {
@@ -1487,7 +1501,7 @@ export class Sender extends BaseTelemetryPlugin implements IChannelControls {
14871501

14881502
/**
14891503
* success handler
1490-
* @Internal
1504+
* @internal
14911505
* since version 3.2.0, if the payload is string[], this function is no-op (string[] is only used for backwards Compatibility)
14921506
*/
14931507
public _onSuccess(payload: string[] | IInternalStorageItem[], countOfItemsInPayload: number) {

common/config/rush/npm-shrinkwrap.json

Lines changed: 0 additions & 13 deletions
Some generated files are not rendered by default. Learn more about customizing how changed files appear on GitHub.

tools/chrome-debug-extension/manifest.json

Lines changed: 2 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -2,8 +2,8 @@
22
"name": "Telemetry Viewer - M3",
33
"short_name": "Telemetry Viewer M3",
44
"description": "A browser extension that provides a real time view of what's happening in Application Insights including what telemetry is being logged by the web application",
5-
"version": "0.7.5",
6-
"version_name": "0.7.5",
5+
"version": "0.8.0",
6+
"version_name": "0.8.0",
77
"manifest_version": 3,
88
"icons": {
99
"16": "images/icon-16.png",

0 commit comments

Comments
 (0)