@@ -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 ) {
0 commit comments