From 1a68c5616fa963fea0aa0833c0662d074d6b4c4b Mon Sep 17 00:00:00 2001
From: "copilot-swe-agent[bot]" <198982749+Copilot@users.noreply.github.com>
Date: Mon, 19 May 2025 18:28:58 +0000
Subject: [PATCH 01/18] Initial plan for issue
From 016492b0d00b0efd26b33a7cc09553d8e45d55c2 Mon Sep 17 00:00:00 2001
From: "copilot-swe-agent[bot]" <198982749+Copilot@users.noreply.github.com>
Date: Mon, 19 May 2025 18:37:40 +0000
Subject: [PATCH 02/18] Add documentation for disablePageUnloadEvents to
address jQuery 3.7.1 deprecation warnings
Co-authored-by: MSNev <54870357+MSNev@users.noreply.github.com>
---
README.md | 21 +++++++++++++++++++++
1 file changed, 21 insertions(+)
diff --git a/README.md b/README.md
index 57cd0ef55..493b4ed7f 100644
--- a/README.md
+++ b/README.md
@@ -371,6 +371,25 @@ The differences between a telemetry initializer and a dependency initializer are
- When a dependency initializer returns `false` to drop the event the event does NOT count against the `maxAjaxCallsPerView` as this blocks the event call from being tracked, and while returning `false` from a [Telemetry Initializer](https://github.com/Microsoft/ApplicationInsights-JS#telemetry-initializers) will also stop the event from being reported because this is further down the processing pipeline the dependency event IS counted against the `maxAjaxCallsPerView` limit.
- It has access to an optional "context" `{ [key: string]: any }` object that is also available to the Dependency Listeners. This allows a listener to add additional details to the context (before the XHR/fetch request is sent), and the initializer will be called after the request has completed.
+#### Example: Disabling jQuery 3.7.1+ Unload Event Deprecation Warnings
+
+If you're using jQuery 3.7.1 or newer and seeing deprecation warnings related to the 'unload' event, you can configure the SDK to not use this deprecated event:
+
+```js
+const appInsights = new ApplicationInsights({
+ config: {
+ connectionString: 'YOUR_CONNECTION_STRING_GOES_HERE',
+ // Disable the deprecated 'unload' event to avoid jQuery deprecation warnings
+ disablePageUnloadEvents: ["unload"],
+ /* ...Other Configuration Options... */
+ }
+});
+appInsights.loadAppInsights();
+appInsights.trackPageView();
+```
+
+This will prevent the SDK from attempting to listen to the deprecated 'unload' event while still maintaining functionality through the other page unload events ('beforeunload', 'pagehide', and 'visibilitychange').
+
### Advanced Setting Using Config/Extensions
- [How to add more details in my Exception Telemetry?](https://microsoft.github.io/ApplicationInsights-JS/exceptionTelemetry)
@@ -450,6 +469,8 @@ Most configuration fields are named such that they can be defaulted to falsey. A
| featureOptIn (#feature)
since 3.0.3 | IFeatureOptIn | undefined | [Optional] Set Feature opt in details. |
| throttleMgrCfg
since 3.0.3 | `{[key: number]: IThrottleMgrConfig}` | undefined | [Optional] Set throttle mgr configuration by key. |
| retryCodes | number[] | undefined | Identifies the status codes that will cause event batches to be resent, when `null` or `undefined` the SDK will use it's defaults `[401, 408, 429, 500, 502, 503, 504]`. `403` was removed in version 3.1.1. |
+| disablePageUnloadEvents | string[] | undefined | [Optional] An array of the page unload events that you would like to be ignored. Note there must be at least one valid unload event hooked - if you list all events or if the runtime environment only supports a listed "disabled" event, it will still be hooked if required by the SDK. Unload events include "beforeunload", "unload", "visibilitychange" (with 'hidden' state) and "pagehide". This can be used to avoid jQuery 3.7.1+ deprecation warnings by configuring as `disablePageUnloadEvents: ["unload"]`. |
+| disablePageShowEvents | string[] | undefined | [Optional] An array of page show events that you would like to be ignored. Note there must be at least one valid show event hooked - if you list all events or if the runtime environment only supports a listed (disabled) event, it will still be hooked if required by the SDK. Page Show events include "pageshow" and "visibilitychange" (with 'visible' state). |
| expCfg
since 3.3.1| [`IExceptionConfig`](https://github.com/microsoft/ApplicationInsights-JS/blob/main/shared/AppInsightsCommon/src/Interfaces/IExceptionTelemetry.ts) | undefined | Set additional configuration for exceptions, such as more scripts to include in the exception telemetry. |
### Feature
From 8e317dfa38958e2037b7a0c981b95a7524b4f910 Mon Sep 17 00:00:00 2001
From: "copilot-swe-agent[bot]" <198982749+Copilot@users.noreply.github.com>
Date: Mon, 19 May 2025 19:43:10 +0000
Subject: [PATCH 03/18] Add detailed documentation for disablePageUnloadEvents
in docs folder
Co-authored-by: MSNev <54870357+MSNev@users.noreply.github.com>
---
README.md | 6 +--
docs/PageUnloadEvents.md | 107 +++++++++++++++++++++++++++++++++++++++
2 files changed, 110 insertions(+), 3 deletions(-)
create mode 100644 docs/PageUnloadEvents.md
diff --git a/README.md b/README.md
index 493b4ed7f..9b43ff15b 100644
--- a/README.md
+++ b/README.md
@@ -388,7 +388,7 @@ appInsights.loadAppInsights();
appInsights.trackPageView();
```
-This will prevent the SDK from attempting to listen to the deprecated 'unload' event while still maintaining functionality through the other page unload events ('beforeunload', 'pagehide', and 'visibilitychange').
+For more detailed information about page unload event handling and browser compatibility, see the [Page Unload Events documentation](./docs/PageUnloadEvents.md).
### Advanced Setting Using Config/Extensions
- [How to add more details in my Exception Telemetry?](https://microsoft.github.io/ApplicationInsights-JS/exceptionTelemetry)
@@ -469,8 +469,8 @@ Most configuration fields are named such that they can be defaulted to falsey. A
| featureOptIn (#feature)
since 3.0.3 | IFeatureOptIn | undefined | [Optional] Set Feature opt in details. |
| throttleMgrCfg
since 3.0.3 | `{[key: number]: IThrottleMgrConfig}` | undefined | [Optional] Set throttle mgr configuration by key. |
| retryCodes | number[] | undefined | Identifies the status codes that will cause event batches to be resent, when `null` or `undefined` the SDK will use it's defaults `[401, 408, 429, 500, 502, 503, 504]`. `403` was removed in version 3.1.1. |
-| disablePageUnloadEvents | string[] | undefined | [Optional] An array of the page unload events that you would like to be ignored. Note there must be at least one valid unload event hooked - if you list all events or if the runtime environment only supports a listed "disabled" event, it will still be hooked if required by the SDK. Unload events include "beforeunload", "unload", "visibilitychange" (with 'hidden' state) and "pagehide". This can be used to avoid jQuery 3.7.1+ deprecation warnings by configuring as `disablePageUnloadEvents: ["unload"]`. |
-| disablePageShowEvents | string[] | undefined | [Optional] An array of page show events that you would like to be ignored. Note there must be at least one valid show event hooked - if you list all events or if the runtime environment only supports a listed (disabled) event, it will still be hooked if required by the SDK. Page Show events include "pageshow" and "visibilitychange" (with 'visible' state). |
+| disablePageUnloadEvents | string[] | undefined | [Optional] An array of the page unload events that you would like to be ignored. [See detailed documentation](./docs/PageUnloadEvents.md). Unload events include "beforeunload", "unload", "visibilitychange" (with 'hidden' state) and "pagehide". This can be used to avoid jQuery 3.7.1+ deprecation warnings by configuring as `disablePageUnloadEvents: ["unload"]`. |
+| disablePageShowEvents | string[] | undefined | [Optional] An array of page show events that you would like to be ignored. [See detailed documentation](./docs/PageUnloadEvents.md). Page Show events include "pageshow" and "visibilitychange" (with 'visible' state). |
| expCfg
since 3.3.1| [`IExceptionConfig`](https://github.com/microsoft/ApplicationInsights-JS/blob/main/shared/AppInsightsCommon/src/Interfaces/IExceptionTelemetry.ts) | undefined | Set additional configuration for exceptions, such as more scripts to include in the exception telemetry. |
### Feature
diff --git a/docs/PageUnloadEvents.md b/docs/PageUnloadEvents.md
new file mode 100644
index 000000000..ab1ab64bf
--- /dev/null
+++ b/docs/PageUnloadEvents.md
@@ -0,0 +1,107 @@
+# Page Unload Event Handling
+
+## Overview
+
+Application Insights Web SDK tracks several page lifecycle events to ensure that telemetry data is sent before a page is unloaded, helping to prevent data loss during page navigation or browser closure. The SDK hooks into different unload and visibility change events depending on the browser environment.
+
+## Unload Events
+
+The SDK listens to the following events to detect when a page is being unloaded:
+
+1. **beforeunload** - Fired when the window, document, and its resources are about to be unloaded
+2. **unload** - Fired when the document or a child resource is being unloaded
+3. **pagehide** - Fired when the browser hides the current page in the process of navigating to another page
+4. **visibilitychange** (with 'hidden' state) - Fired when the content of a tab has become visible or hidden
+
+## Modern Browser Compatibility
+
+Modern browsers and frameworks are deprecating or changing how some page unload events work:
+
+- **jQuery 3.7.1+** has deprecated the use of the `unload` event, showing warning messages when it's used.
+- Some modern browsers are changing the behavior of `beforeunload` event for better performance and reduced tracking potential.
+- The `pagehide` event and `visibilitychange` events are becoming the recommended alternatives.
+
+## Configuration Options
+
+The SDK provides configuration options to control which page unload events are used:
+
+### disablePageUnloadEvents
+
+This configuration option allows you to specify which page unload events should not be used by the SDK.
+
+```javascript
+const appInsights = new ApplicationInsights({
+ config: {
+ connectionString: 'YOUR_CONNECTION_STRING_GOES_HERE',
+ disablePageUnloadEvents: ["unload"],
+ /* ...Other Configuration Options... */
+ }
+});
+```
+
+**Important notes**:
+
+- The SDK requires at least one functioning page unload event to ensure telemetry is sent when the page is closed.
+- If all events are listed in `disablePageUnloadEvents` or if the only working events in the current browser environment are the ones you've disabled, the SDK will still use one of them to ensure functionality.
+- This option is especially useful for avoiding jQuery 3.7.1+ deprecation warnings by excluding the "unload" event.
+
+### disablePageShowEvents
+
+Similarly, this configuration option controls which page show events are not used by the SDK. Page show events include:
+
+1. **pageshow** - Fired when a page is shown, or when navigating to a page using browser's back/forward functionality
+2. **visibilitychange** (with 'visible' state) - Fired when a tab becomes visible
+
+```javascript
+const appInsights = new ApplicationInsights({
+ config: {
+ connectionString: 'YOUR_CONNECTION_STRING_GOES_HERE',
+ disablePageShowEvents: ["pageshow"],
+ /* ...Other Configuration Options... */
+ }
+});
+```
+
+## Fallback Mechanism
+
+The SDK implements a robust fallback mechanism to ensure that telemetry can be sent before the page unloads:
+
+1. The SDK first tries to use all available unload events except those listed in `disablePageUnloadEvents`.
+2. If no events can be registered (either because all are disabled or not supported), the SDK will ignore the `disablePageUnloadEvents` setting and force registration of at least one event.
+3. This ensures that critical telemetry data is always sent, even in constrained environments.
+
+## Use Cases
+
+### Avoiding jQuery 3.7.1+ Deprecation Warnings
+
+If you're using jQuery 3.7.1 or newer, you'll encounter deprecation warnings when the 'unload' event is used. Configure the SDK to not use this deprecated event:
+
+```javascript
+const appInsights = new ApplicationInsights({
+ config: {
+ connectionString: 'YOUR_CONNECTION_STRING_GOES_HERE',
+ // Disable the deprecated 'unload' event to avoid jQuery deprecation warnings
+ disablePageUnloadEvents: ["unload"],
+ }
+});
+```
+
+### Optimizing for Modern Browsers
+
+For the best experience in modern browsers, you might want to prioritize newer events:
+
+```javascript
+const appInsights = new ApplicationInsights({
+ config: {
+ connectionString: 'YOUR_CONNECTION_STRING_GOES_HERE',
+ // Use only modern events
+ disablePageUnloadEvents: ["unload", "beforeunload"],
+ }
+});
+```
+
+Note that the SDK will still use an older event if none of the modern events are supported in the browser environment.
+
+### Progressive Enhancement
+
+The SDK's approach to page unload events reflects a progressive enhancement strategy, ensuring that telemetry works across diverse browser environments while offering configuration options for optimal behavior in modern contexts.
\ No newline at end of file
From c4d3fe25c89f12b5154e39b1d38fb571b2b856e4 Mon Sep 17 00:00:00 2001
From: "copilot-swe-agent[bot]" <198982749+Copilot@users.noreply.github.com>
Date: Mon, 19 May 2025 20:35:16 +0000
Subject: [PATCH 04/18] Update documentation URLs and add TypeScript examples
for page events config
Co-authored-by: MSNev <54870357+MSNev@users.noreply.github.com>
---
README.md | 6 +--
docs/PageUnloadEvents.md | 92 +++++++++++++++++++++++++++++++++++++++-
2 files changed, 93 insertions(+), 5 deletions(-)
diff --git a/README.md b/README.md
index 9b43ff15b..770757e25 100644
--- a/README.md
+++ b/README.md
@@ -388,7 +388,7 @@ appInsights.loadAppInsights();
appInsights.trackPageView();
```
-For more detailed information about page unload event handling and browser compatibility, see the [Page Unload Events documentation](./docs/PageUnloadEvents.md).
+For more detailed information about page unload event handling and browser compatibility, see the [Page Unload Events documentation](https://microsoft.github.io/ApplicationInsights-JS/docs/PageUnloadEvents.html).
### Advanced Setting Using Config/Extensions
- [How to add more details in my Exception Telemetry?](https://microsoft.github.io/ApplicationInsights-JS/exceptionTelemetry)
@@ -469,8 +469,8 @@ Most configuration fields are named such that they can be defaulted to falsey. A
| featureOptIn (#feature)
since 3.0.3 | IFeatureOptIn | undefined | [Optional] Set Feature opt in details. |
| throttleMgrCfg
since 3.0.3 | `{[key: number]: IThrottleMgrConfig}` | undefined | [Optional] Set throttle mgr configuration by key. |
| retryCodes | number[] | undefined | Identifies the status codes that will cause event batches to be resent, when `null` or `undefined` the SDK will use it's defaults `[401, 408, 429, 500, 502, 503, 504]`. `403` was removed in version 3.1.1. |
-| disablePageUnloadEvents | string[] | undefined | [Optional] An array of the page unload events that you would like to be ignored. [See detailed documentation](./docs/PageUnloadEvents.md). Unload events include "beforeunload", "unload", "visibilitychange" (with 'hidden' state) and "pagehide". This can be used to avoid jQuery 3.7.1+ deprecation warnings by configuring as `disablePageUnloadEvents: ["unload"]`. |
-| disablePageShowEvents | string[] | undefined | [Optional] An array of page show events that you would like to be ignored. [See detailed documentation](./docs/PageUnloadEvents.md). Page Show events include "pageshow" and "visibilitychange" (with 'visible' state). |
+| disablePageUnloadEvents | string[] | undefined | [Optional] An array of the page unload events that you would like to be ignored. [See detailed documentation](https://microsoft.github.io/ApplicationInsights-JS/docs/PageUnloadEvents.html). Unload events include "beforeunload", "unload", "visibilitychange" (with 'hidden' state) and "pagehide". This can be used to avoid jQuery 3.7.1+ deprecation warnings by configuring as `disablePageUnloadEvents: ["unload"]`. |
+| disablePageShowEvents | string[] | undefined | [Optional] An array of page show events that you would like to be ignored. [See detailed documentation](https://microsoft.github.io/ApplicationInsights-JS/docs/PageUnloadEvents.html). Page Show events include "pageshow" and "visibilitychange" (with 'visible' state). |
| expCfg
since 3.3.1| [`IExceptionConfig`](https://github.com/microsoft/ApplicationInsights-JS/blob/main/shared/AppInsightsCommon/src/Interfaces/IExceptionTelemetry.ts) | undefined | Set additional configuration for exceptions, such as more scripts to include in the exception telemetry. |
### Feature
diff --git a/docs/PageUnloadEvents.md b/docs/PageUnloadEvents.md
index ab1ab64bf..bdfd9f1df 100644
--- a/docs/PageUnloadEvents.md
+++ b/docs/PageUnloadEvents.md
@@ -23,12 +23,13 @@ Modern browsers and frameworks are deprecating or changing how some page unload
## Configuration Options
-The SDK provides configuration options to control which page unload events are used:
+The SDK provides configuration options to control which page lifecycle events are used:
### disablePageUnloadEvents
This configuration option allows you to specify which page unload events should not be used by the SDK.
+**JavaScript Example:**
```javascript
const appInsights = new ApplicationInsights({
config: {
@@ -39,6 +40,19 @@ const appInsights = new ApplicationInsights({
});
```
+**TypeScript Example:**
+```typescript
+import { ApplicationInsights } from '@microsoft/applicationinsights-web';
+
+const appInsights = new ApplicationInsights({
+ config: {
+ connectionString: 'YOUR_CONNECTION_STRING_GOES_HERE',
+ disablePageUnloadEvents: ["unload"],
+ /* ...Other Configuration Options... */
+ }
+});
+```
+
**Important notes**:
- The SDK requires at least one functioning page unload event to ensure telemetry is sent when the page is closed.
@@ -52,6 +66,7 @@ Similarly, this configuration option controls which page show events are not use
1. **pageshow** - Fired when a page is shown, or when navigating to a page using browser's back/forward functionality
2. **visibilitychange** (with 'visible' state) - Fired when a tab becomes visible
+**JavaScript Example:**
```javascript
const appInsights = new ApplicationInsights({
config: {
@@ -62,6 +77,19 @@ const appInsights = new ApplicationInsights({
});
```
+**TypeScript Example:**
+```typescript
+import { ApplicationInsights } from '@microsoft/applicationinsights-web';
+
+const appInsights = new ApplicationInsights({
+ config: {
+ connectionString: 'YOUR_CONNECTION_STRING_GOES_HERE',
+ disablePageShowEvents: ["pageshow"],
+ /* ...Other Configuration Options... */
+ }
+});
+```
+
## Fallback Mechanism
The SDK implements a robust fallback mechanism to ensure that telemetry can be sent before the page unloads:
@@ -76,6 +104,7 @@ The SDK implements a robust fallback mechanism to ensure that telemetry can be s
If you're using jQuery 3.7.1 or newer, you'll encounter deprecation warnings when the 'unload' event is used. Configure the SDK to not use this deprecated event:
+**JavaScript Example:**
```javascript
const appInsights = new ApplicationInsights({
config: {
@@ -86,10 +115,24 @@ const appInsights = new ApplicationInsights({
});
```
+**TypeScript Example:**
+```typescript
+import { ApplicationInsights } from '@microsoft/applicationinsights-web';
+
+const appInsights = new ApplicationInsights({
+ config: {
+ connectionString: 'YOUR_CONNECTION_STRING_GOES_HERE',
+ // Disable the deprecated 'unload' event to avoid jQuery deprecation warnings
+ disablePageUnloadEvents: ["unload"],
+ }
+});
+```
+
### Optimizing for Modern Browsers
For the best experience in modern browsers, you might want to prioritize newer events:
+**JavaScript Example:**
```javascript
const appInsights = new ApplicationInsights({
config: {
@@ -100,8 +143,53 @@ const appInsights = new ApplicationInsights({
});
```
+**TypeScript Example:**
+```typescript
+import { ApplicationInsights } from '@microsoft/applicationinsights-web';
+
+const appInsights = new ApplicationInsights({
+ config: {
+ connectionString: 'YOUR_CONNECTION_STRING_GOES_HERE',
+ // Use only modern events
+ disablePageUnloadEvents: ["unload", "beforeunload"],
+ }
+});
+```
+
Note that the SDK will still use an older event if none of the modern events are supported in the browser environment.
+### Using Both Configuration Options Together
+
+You can configure both unload and show events simultaneously for fine-grained control:
+
+**JavaScript Example:**
+```javascript
+const appInsights = new ApplicationInsights({
+ config: {
+ connectionString: 'YOUR_CONNECTION_STRING_GOES_HERE',
+ // Disable specific unload events
+ disablePageUnloadEvents: ["unload"],
+ // Disable specific show events
+ disablePageShowEvents: ["pageshow"],
+ }
+});
+```
+
+**TypeScript Example:**
+```typescript
+import { ApplicationInsights } from '@microsoft/applicationinsights-web';
+
+const appInsights = new ApplicationInsights({
+ config: {
+ connectionString: 'YOUR_CONNECTION_STRING_GOES_HERE',
+ // Disable specific unload events
+ disablePageUnloadEvents: ["unload"],
+ // Disable specific show events
+ disablePageShowEvents: ["pageshow"],
+ }
+});
+```
+
### Progressive Enhancement
-The SDK's approach to page unload events reflects a progressive enhancement strategy, ensuring that telemetry works across diverse browser environments while offering configuration options for optimal behavior in modern contexts.
\ No newline at end of file
+The SDK's approach to page lifecycle events reflects a progressive enhancement strategy, ensuring that telemetry works across diverse browser environments while offering configuration options for optimal behavior in modern contexts.
\ No newline at end of file
From e3583487f6b04128fd824356a6700f1151a5731a Mon Sep 17 00:00:00 2001
From: "copilot-swe-agent[bot]" <198982749+Copilot@users.noreply.github.com>
Date: Mon, 19 May 2025 21:29:51 +0000
Subject: [PATCH 05/18] Update documentation for disablePageUnloadEvents and
disablePageShowEvents
Co-authored-by: MSNev <54870357+MSNev@users.noreply.github.com>
---
README.md | 37 ++++++++++---------
shared/1ds-core-js/README.md | 4 +-
.../IConfiguration.ts | 22 ++++++++++-
3 files changed, 42 insertions(+), 21 deletions(-)
diff --git a/README.md b/README.md
index 770757e25..64fe1aef9 100644
--- a/README.md
+++ b/README.md
@@ -371,24 +371,7 @@ The differences between a telemetry initializer and a dependency initializer are
- When a dependency initializer returns `false` to drop the event the event does NOT count against the `maxAjaxCallsPerView` as this blocks the event call from being tracked, and while returning `false` from a [Telemetry Initializer](https://github.com/Microsoft/ApplicationInsights-JS#telemetry-initializers) will also stop the event from being reported because this is further down the processing pipeline the dependency event IS counted against the `maxAjaxCallsPerView` limit.
- It has access to an optional "context" `{ [key: string]: any }` object that is also available to the Dependency Listeners. This allows a listener to add additional details to the context (before the XHR/fetch request is sent), and the initializer will be called after the request has completed.
-#### Example: Disabling jQuery 3.7.1+ Unload Event Deprecation Warnings
-If you're using jQuery 3.7.1 or newer and seeing deprecation warnings related to the 'unload' event, you can configure the SDK to not use this deprecated event:
-
-```js
-const appInsights = new ApplicationInsights({
- config: {
- connectionString: 'YOUR_CONNECTION_STRING_GOES_HERE',
- // Disable the deprecated 'unload' event to avoid jQuery deprecation warnings
- disablePageUnloadEvents: ["unload"],
- /* ...Other Configuration Options... */
- }
-});
-appInsights.loadAppInsights();
-appInsights.trackPageView();
-```
-
-For more detailed information about page unload event handling and browser compatibility, see the [Page Unload Events documentation](https://microsoft.github.io/ApplicationInsights-JS/docs/PageUnloadEvents.html).
### Advanced Setting Using Config/Extensions
- [How to add more details in my Exception Telemetry?](https://microsoft.github.io/ApplicationInsights-JS/exceptionTelemetry)
@@ -473,6 +456,26 @@ Most configuration fields are named such that they can be defaulted to falsey. A
| disablePageShowEvents | string[] | undefined | [Optional] An array of page show events that you would like to be ignored. [See detailed documentation](https://microsoft.github.io/ApplicationInsights-JS/docs/PageUnloadEvents.html). Page Show events include "pageshow" and "visibilitychange" (with 'visible' state). |
| expCfg
since 3.3.1| [`IExceptionConfig`](https://github.com/microsoft/ApplicationInsights-JS/blob/main/shared/AppInsightsCommon/src/Interfaces/IExceptionTelemetry.ts) | undefined | Set additional configuration for exceptions, such as more scripts to include in the exception telemetry. |
+### Page Unload and Visibility Event Handling
+
+Application Insights SDK tracks various page lifecycle events to ensure telemetry data is sent before a page unloads or changes visibility state. Modern browsers and frameworks like jQuery 3.7.1+ are changing or deprecating some of these events.
+
+```js
+const appInsights = new ApplicationInsights({
+ config: {
+ connectionString: 'YOUR_CONNECTION_STRING_GOES_HERE',
+ // Disable the deprecated 'unload' event to avoid jQuery 3.7.1+ deprecation warnings
+ // This also prevents Chrome's warnings about the unload event
+ disablePageUnloadEvents: ["unload"],
+ /* ...Other Configuration Options... */
+ }
+});
+appInsights.loadAppInsights();
+appInsights.trackPageView();
+```
+
+For more detailed information about browser compatibility and configuration options, see the [Page Unload Events documentation](https://microsoft.github.io/ApplicationInsights-JS/docs/PageUnloadEvents.html).
+
### Feature
You can use the `featureOptIn` configuration to enable or customize specific SDK features.
diff --git a/shared/1ds-core-js/README.md b/shared/1ds-core-js/README.md
index 94876f33d..69f029102 100644
--- a/shared/1ds-core-js/README.md
+++ b/shared/1ds-core-js/README.md
@@ -52,8 +52,8 @@ appInsightsCore.initialize(coreConfig, []);
| idLength | [Optional] Identifies the default length used to generate new random session and user id's. Defaults to 22, previous default value was 5 (v2.4.2 or less), if you need to keep the previous maximum length you should set this value to 5. | number
Default: 22
| disableEventTimings | [Optional] Disables additional internal event timings that are added during processing of events, the timings are not sent as part telemetry items to the server. | boolean
Default: false
| enableCompoundKey | [Optional] Enables support for objects with compound keys which indirectly represent an object where the "key" of the object contains a "." as part of it's name.
Example: event: { "somedata.embeddedvalue": 123 } | boolean
Default: false
-| disablePageUnloadEvents | [Optional] An array of the page unload events that you would like to be ignored, special note there must be at least one valid unload event hooked, if you list all or the runtime environment only supports a listed "disabled" event it will still be hooked, if required by the SDK.
Unload events include "beforeunload", "unload", "visibilitychange" (with 'hidden' state) and "pagehide"| string[]
Default: not specified
-| disablePageShowEvents | [Optional] An array of page show events that you would like to be ignored, special note there must be at lease one valid show event hooked, if you list all or the runtime environment only supports a listed (disabled) event it will STILL be hooked, if required by the SDK.
Page Show events include "pageshow" and "visibilitychange" (with 'visible' state)| string[]
Default: not specified
+| disablePageUnloadEvents | [Optional] An array of the page unload events that you would like to be ignored, special note there must be at least one valid unload event hooked, if you list all or the runtime environment only supports a listed "disabled" event it will still be hooked, if required by the SDK.
Unload events include "beforeunload", "unload", "visibilitychange" (with 'hidden' state) and "pagehide". See [Page Unload Events documentation](https://microsoft.github.io/ApplicationInsights-JS/docs/PageUnloadEvents.html) for details.| string[]
Default: not specified
+| disablePageShowEvents | [Optional] An array of page show events that you would like to be ignored, special note there must be at lease one valid show event hooked, if you list all or the runtime environment only supports a listed (disabled) event it will STILL be hooked, if required by the SDK.
Page Show events include "pageshow" and "visibilitychange" (with 'visible' state). See [Page Unload Events documentation](https://microsoft.github.io/ApplicationInsights-JS/docs/PageUnloadEvents.html) for details.| string[]
Default: not specified
### [IPropertyStorageOverride](https://microsoft.github.io/ApplicationInsights-JS/webSdk/1ds-core-js/interfaces/IPropertyStorageOverride.html)
diff --git a/shared/AppInsightsCore/src/JavaScriptSDK.Interfaces/IConfiguration.ts b/shared/AppInsightsCore/src/JavaScriptSDK.Interfaces/IConfiguration.ts
index 57bc44758..585cd19f6 100644
--- a/shared/AppInsightsCore/src/JavaScriptSDK.Interfaces/IConfiguration.ts
+++ b/shared/AppInsightsCore/src/JavaScriptSDK.Interfaces/IConfiguration.ts
@@ -156,14 +156,32 @@ export interface IConfiguration {
/**
* [Optional] An array of the page unload events that you would like to be ignored, special note there must be at least one valid unload
* event hooked, if you list all or the runtime environment only supports a listed "disabled" event it will still be hooked, if required by the SDK.
- * Unload events include "beforeunload", "unload", "visibilitychange" (with 'hidden' state) and "pagehide"
+ * Unload events include "beforeunload", "unload", "visibilitychange" (with 'hidden' state) and "pagehide".
+ *
+ * This can be used to avoid jQuery 3.7.1+ deprecation warnings and Chrome warnings about the unload event:
+ * ```javascript
+ * {
+ * disablePageUnloadEvents: ["unload"]
+ * }
+ * ```
+ *
+ * For more details, see the [Page Unload Events documentation](https://microsoft.github.io/ApplicationInsights-JS/docs/PageUnloadEvents.html).
*/
disablePageUnloadEvents?: string[];
/**
* [Optional] An array of page show events that you would like to be ignored, special note there must be at lease one valid show event
* hooked, if you list all or the runtime environment only supports a listed (disabled) event it will STILL be hooked, if required by the SDK.
- * Page Show events include "pageshow" and "visibilitychange" (with 'visible' state)
+ * Page Show events include "pageshow" and "visibilitychange" (with 'visible' state).
+ *
+ * Example usage:
+ * ```javascript
+ * {
+ * disablePageShowEvents: ["pageshow"]
+ * }
+ * ```
+ *
+ * For more details, see the [Page Unload Events documentation](https://microsoft.github.io/ApplicationInsights-JS/docs/PageUnloadEvents.html).
*/
disablePageShowEvents?: string[];
From 8784a578e7131fc1ad16f82896a94ff7ef5a1e36 Mon Sep 17 00:00:00 2001
From: "copilot-swe-agent[bot]" <198982749+Copilot@users.noreply.github.com>
Date: Mon, 19 May 2025 22:00:43 +0000
Subject: [PATCH 06/18] Add @example tag to TypeDoc for disablePageUnloadEvents
and disablePageShowEvents
Co-authored-by: MSNev <54870357+MSNev@users.noreply.github.com>
---
.../src/JavaScriptSDK.Interfaces/IConfiguration.ts | 2 ++
1 file changed, 2 insertions(+)
diff --git a/shared/AppInsightsCore/src/JavaScriptSDK.Interfaces/IConfiguration.ts b/shared/AppInsightsCore/src/JavaScriptSDK.Interfaces/IConfiguration.ts
index 585cd19f6..dc57768cf 100644
--- a/shared/AppInsightsCore/src/JavaScriptSDK.Interfaces/IConfiguration.ts
+++ b/shared/AppInsightsCore/src/JavaScriptSDK.Interfaces/IConfiguration.ts
@@ -159,6 +159,7 @@ export interface IConfiguration {
* Unload events include "beforeunload", "unload", "visibilitychange" (with 'hidden' state) and "pagehide".
*
* This can be used to avoid jQuery 3.7.1+ deprecation warnings and Chrome warnings about the unload event:
+ * @example
* ```javascript
* {
* disablePageUnloadEvents: ["unload"]
@@ -175,6 +176,7 @@ export interface IConfiguration {
* Page Show events include "pageshow" and "visibilitychange" (with 'visible' state).
*
* Example usage:
+ * @example
* ```javascript
* {
* disablePageShowEvents: ["pageshow"]
From e34465684eeb16f240956c9c2542d31f72470b4f Mon Sep 17 00:00:00 2001
From: "copilot-swe-agent[bot]" <198982749+Copilot@users.noreply.github.com>
Date: Mon, 19 May 2025 22:03:08 +0000
Subject: [PATCH 07/18] Add PageUnloadEvents.html link to docs/README.md FAQ
section
Co-authored-by: MSNev <54870357+MSNev@users.noreply.github.com>
---
docs/README.md | 1 +
1 file changed, 1 insertion(+)
diff --git a/docs/README.md b/docs/README.md
index 5c9837144..62263f6dc 100644
--- a/docs/README.md
+++ b/docs/README.md
@@ -49,6 +49,7 @@ ES3 support has been removed from the latest version (v3.x), if required [see fo
- [Create an Issue](https://github.com/microsoft/ApplicationInsights-JS/issues/new/choose)
- [ES3 Support](./es3_Support.md)
+- [Page Unload Event Handling](https://microsoft.github.io/ApplicationInsights-JS/docs/PageUnloadEvents.html)
- [V2 Upgrade Guide](./upgrade/v2_UpgradeGuide.md)
- [V3 Breaking Changes](./upgrade/v3_BreakingChanges.md)
From 499ca51afc9c32e8530b3be5f5ae78342a9b1bea Mon Sep 17 00:00:00 2001
From: "copilot-swe-agent[bot]" <198982749+Copilot@users.noreply.github.com>
Date: Mon, 19 May 2025 22:06:55 +0000
Subject: [PATCH 08/18] Update disablePageUnloadEvents and
disablePageShowEvents links to use TypeDoc URL
Co-authored-by: MSNev <54870357+MSNev@users.noreply.github.com>
---
shared/1ds-core-js/README.md | 4 ++--
1 file changed, 2 insertions(+), 2 deletions(-)
diff --git a/shared/1ds-core-js/README.md b/shared/1ds-core-js/README.md
index 69f029102..7f6a7e077 100644
--- a/shared/1ds-core-js/README.md
+++ b/shared/1ds-core-js/README.md
@@ -52,8 +52,8 @@ appInsightsCore.initialize(coreConfig, []);
| idLength | [Optional] Identifies the default length used to generate new random session and user id's. Defaults to 22, previous default value was 5 (v2.4.2 or less), if you need to keep the previous maximum length you should set this value to 5. | number
Default: 22
| disableEventTimings | [Optional] Disables additional internal event timings that are added during processing of events, the timings are not sent as part telemetry items to the server. | boolean
Default: false
| enableCompoundKey | [Optional] Enables support for objects with compound keys which indirectly represent an object where the "key" of the object contains a "." as part of it's name.
Example: event: { "somedata.embeddedvalue": 123 } | boolean
Default: false
-| disablePageUnloadEvents | [Optional] An array of the page unload events that you would like to be ignored, special note there must be at least one valid unload event hooked, if you list all or the runtime environment only supports a listed "disabled" event it will still be hooked, if required by the SDK.
Unload events include "beforeunload", "unload", "visibilitychange" (with 'hidden' state) and "pagehide". See [Page Unload Events documentation](https://microsoft.github.io/ApplicationInsights-JS/docs/PageUnloadEvents.html) for details.| string[]
Default: not specified
-| disablePageShowEvents | [Optional] An array of page show events that you would like to be ignored, special note there must be at lease one valid show event hooked, if you list all or the runtime environment only supports a listed (disabled) event it will STILL be hooked, if required by the SDK.
Page Show events include "pageshow" and "visibilitychange" (with 'visible' state). See [Page Unload Events documentation](https://microsoft.github.io/ApplicationInsights-JS/docs/PageUnloadEvents.html) for details.| string[]
Default: not specified
+| [disablePageUnloadEvents](https://microsoft.github.io/ApplicationInsights-JS/webSdk/applicationinsights-core-js/interfaces/IConfiguration.html#disablePageUnloadEvents) | [Optional] An array of the page unload events that you would like to be ignored, special note there must be at least one valid unload event hooked, if you list all or the runtime environment only supports a listed "disabled" event it will still be hooked, if required by the SDK.
Unload events include "beforeunload", "unload", "visibilitychange" (with 'hidden' state) and "pagehide". See [Page Unload Events documentation](https://microsoft.github.io/ApplicationInsights-JS/docs/PageUnloadEvents.html) for details.| string[]
Default: not specified
+| [disablePageShowEvents](https://microsoft.github.io/ApplicationInsights-JS/webSdk/applicationinsights-core-js/interfaces/IConfiguration.html#disablePageShowEvents) | [Optional] An array of page show events that you would like to be ignored, special note there must be at lease one valid show event hooked, if you list all or the runtime environment only supports a listed (disabled) event it will STILL be hooked, if required by the SDK.
Page Show events include "pageshow" and "visibilitychange" (with 'visible' state). See [Page Unload Events documentation](https://microsoft.github.io/ApplicationInsights-JS/docs/PageUnloadEvents.html) for details.| string[]
Default: not specified
### [IPropertyStorageOverride](https://microsoft.github.io/ApplicationInsights-JS/webSdk/1ds-core-js/interfaces/IPropertyStorageOverride.html)
From 49cf4ee25e32b9ede29b23545fc5ff4398c7aec1 Mon Sep 17 00:00:00 2001
From: "copilot-swe-agent[bot]" <198982749+Copilot@users.noreply.github.com>
Date: Mon, 19 May 2025 22:10:05 +0000
Subject: [PATCH 09/18] Remove unnecessary lines and "Example usage:" heading
Co-authored-by: MSNev <54870357+MSNev@users.noreply.github.com>
---
README.md | 2 --
.../src/JavaScriptSDK.Interfaces/IConfiguration.ts | 1 -
2 files changed, 3 deletions(-)
diff --git a/README.md b/README.md
index 64fe1aef9..32c05971b 100644
--- a/README.md
+++ b/README.md
@@ -371,8 +371,6 @@ The differences between a telemetry initializer and a dependency initializer are
- When a dependency initializer returns `false` to drop the event the event does NOT count against the `maxAjaxCallsPerView` as this blocks the event call from being tracked, and while returning `false` from a [Telemetry Initializer](https://github.com/Microsoft/ApplicationInsights-JS#telemetry-initializers) will also stop the event from being reported because this is further down the processing pipeline the dependency event IS counted against the `maxAjaxCallsPerView` limit.
- It has access to an optional "context" `{ [key: string]: any }` object that is also available to the Dependency Listeners. This allows a listener to add additional details to the context (before the XHR/fetch request is sent), and the initializer will be called after the request has completed.
-
-
### Advanced Setting Using Config/Extensions
- [How to add more details in my Exception Telemetry?](https://microsoft.github.io/ApplicationInsights-JS/exceptionTelemetry)
diff --git a/shared/AppInsightsCore/src/JavaScriptSDK.Interfaces/IConfiguration.ts b/shared/AppInsightsCore/src/JavaScriptSDK.Interfaces/IConfiguration.ts
index dc57768cf..9e7b606e9 100644
--- a/shared/AppInsightsCore/src/JavaScriptSDK.Interfaces/IConfiguration.ts
+++ b/shared/AppInsightsCore/src/JavaScriptSDK.Interfaces/IConfiguration.ts
@@ -175,7 +175,6 @@ export interface IConfiguration {
* hooked, if you list all or the runtime environment only supports a listed (disabled) event it will STILL be hooked, if required by the SDK.
* Page Show events include "pageshow" and "visibilitychange" (with 'visible' state).
*
- * Example usage:
* @example
* ```javascript
* {
From 0e3b1298423dd2e2e5fb27572bc9929bd66a4b1d Mon Sep 17 00:00:00 2001
From: "copilot-swe-agent[bot]" <198982749+Copilot@users.noreply.github.com>
Date: Mon, 19 May 2025 22:12:33 +0000
Subject: [PATCH 10/18] Update PageUnloadEvents link to use relative markdown
path
Co-authored-by: MSNev <54870357+MSNev@users.noreply.github.com>
---
docs/README.md | 2 +-
1 file changed, 1 insertion(+), 1 deletion(-)
diff --git a/docs/README.md b/docs/README.md
index 62263f6dc..617b23566 100644
--- a/docs/README.md
+++ b/docs/README.md
@@ -49,7 +49,7 @@ ES3 support has been removed from the latest version (v3.x), if required [see fo
- [Create an Issue](https://github.com/microsoft/ApplicationInsights-JS/issues/new/choose)
- [ES3 Support](./es3_Support.md)
-- [Page Unload Event Handling](https://microsoft.github.io/ApplicationInsights-JS/docs/PageUnloadEvents.html)
+- [Page Unload Event Handling](./PageUnloadEvents.md)
- [V2 Upgrade Guide](./upgrade/v2_UpgradeGuide.md)
- [V3 Breaking Changes](./upgrade/v3_BreakingChanges.md)
From 5ec545b4b7b89ba3ed603882a70268717bf2fe63 Mon Sep 17 00:00:00 2001
From: "copilot-swe-agent[bot]" <198982749+Copilot@users.noreply.github.com>
Date: Mon, 19 May 2025 22:20:42 +0000
Subject: [PATCH 11/18] Add details about handling missing events in
PageUnloadEvents.md
Co-authored-by: MSNev <54870357+MSNev@users.noreply.github.com>
---
docs/PageUnloadEvents.md | 5 ++++-
1 file changed, 4 insertions(+), 1 deletion(-)
diff --git a/docs/PageUnloadEvents.md b/docs/PageUnloadEvents.md
index bdfd9f1df..384e1c0f0 100644
--- a/docs/PageUnloadEvents.md
+++ b/docs/PageUnloadEvents.md
@@ -20,6 +20,7 @@ Modern browsers and frameworks are deprecating or changing how some page unload
- **jQuery 3.7.1+** has deprecated the use of the `unload` event, showing warning messages when it's used.
- Some modern browsers are changing the behavior of `beforeunload` event for better performance and reduced tracking potential.
- The `pagehide` event and `visibilitychange` events are becoming the recommended alternatives.
+- The SDK is designed to handle cases where certain events are unavailable or behave differently across browsers, gracefully adapting to the environment to ensure telemetry is sent.
## Configuration Options
@@ -96,7 +97,9 @@ The SDK implements a robust fallback mechanism to ensure that telemetry can be s
1. The SDK first tries to use all available unload events except those listed in `disablePageUnloadEvents`.
2. If no events can be registered (either because all are disabled or not supported), the SDK will ignore the `disablePageUnloadEvents` setting and force registration of at least one event.
-3. This ensures that critical telemetry data is always sent, even in constrained environments.
+3. Even when the SDK attempts to hook events that may be missing in certain browsers, it's designed to gracefully handle these cases without errors.
+4. The SDK includes internal logic to detect when hooked events aren't firing as expected and will utilize alternative approaches to send telemetry.
+5. This ensures that critical telemetry data is always sent, even in constrained environments or when browser implementations change.
## Use Cases
From 7a1ac2756b7168fb0429a83d4d95059cd9f6a356 Mon Sep 17 00:00:00 2001
From: "copilot-swe-agent[bot]" <198982749+Copilot@users.noreply.github.com>
Date: Mon, 19 May 2025 22:23:34 +0000
Subject: [PATCH 12/18] Update disablePageUnloadEvents and
disablePageShowEvents with TypeDoc links in README.md
Co-authored-by: MSNev <54870357+MSNev@users.noreply.github.com>
---
README.md | 4 ++--
1 file changed, 2 insertions(+), 2 deletions(-)
diff --git a/README.md b/README.md
index 32c05971b..10bea9cc5 100644
--- a/README.md
+++ b/README.md
@@ -450,8 +450,8 @@ Most configuration fields are named such that they can be defaulted to falsey. A
| featureOptIn (#feature)
since 3.0.3 | IFeatureOptIn | undefined | [Optional] Set Feature opt in details. |
| throttleMgrCfg
since 3.0.3 | `{[key: number]: IThrottleMgrConfig}` | undefined | [Optional] Set throttle mgr configuration by key. |
| retryCodes | number[] | undefined | Identifies the status codes that will cause event batches to be resent, when `null` or `undefined` the SDK will use it's defaults `[401, 408, 429, 500, 502, 503, 504]`. `403` was removed in version 3.1.1. |
-| disablePageUnloadEvents | string[] | undefined | [Optional] An array of the page unload events that you would like to be ignored. [See detailed documentation](https://microsoft.github.io/ApplicationInsights-JS/docs/PageUnloadEvents.html). Unload events include "beforeunload", "unload", "visibilitychange" (with 'hidden' state) and "pagehide". This can be used to avoid jQuery 3.7.1+ deprecation warnings by configuring as `disablePageUnloadEvents: ["unload"]`. |
-| disablePageShowEvents | string[] | undefined | [Optional] An array of page show events that you would like to be ignored. [See detailed documentation](https://microsoft.github.io/ApplicationInsights-JS/docs/PageUnloadEvents.html). Page Show events include "pageshow" and "visibilitychange" (with 'visible' state). |
+| [disablePageUnloadEvents](https://microsoft.github.io/ApplicationInsights-JS/webSdk/applicationinsights-core-js/interfaces/IConfiguration.html#disablePageUnloadEvents) | string[] | undefined | [Optional] An array of the page unload events that you would like to be ignored. [See detailed documentation](https://microsoft.github.io/ApplicationInsights-JS/docs/PageUnloadEvents.html). Unload events include "beforeunload", "unload", "visibilitychange" (with 'hidden' state) and "pagehide". This can be used to avoid jQuery 3.7.1+ deprecation warnings by configuring as `disablePageUnloadEvents: ["unload"]`. |
+| [disablePageShowEvents](https://microsoft.github.io/ApplicationInsights-JS/webSdk/applicationinsights-core-js/interfaces/IConfiguration.html#disablePageShowEvents) | string[] | undefined | [Optional] An array of page show events that you would like to be ignored. [See detailed documentation](https://microsoft.github.io/ApplicationInsights-JS/docs/PageUnloadEvents.html). Page Show events include "pageshow" and "visibilitychange" (with 'visible' state). |
| expCfg
since 3.3.1| [`IExceptionConfig`](https://github.com/microsoft/ApplicationInsights-JS/blob/main/shared/AppInsightsCommon/src/Interfaces/IExceptionTelemetry.ts) | undefined | Set additional configuration for exceptions, such as more scripts to include in the exception telemetry. |
### Page Unload and Visibility Event Handling
From a9c0fef8690703442a0b935792955c7dc844f604 Mon Sep 17 00:00:00 2001
From: "copilot-swe-agent[bot]" <198982749+Copilot@users.noreply.github.com>
Date: Mon, 19 May 2025 22:29:29 +0000
Subject: [PATCH 13/18] Update disablePageUnloadEvents and
disablePageShowEvents links to 1ds-core-js specific TypeDoc URLs
Co-authored-by: MSNev <54870357+MSNev@users.noreply.github.com>
---
shared/1ds-core-js/README.md | 4 ++--
1 file changed, 2 insertions(+), 2 deletions(-)
diff --git a/shared/1ds-core-js/README.md b/shared/1ds-core-js/README.md
index 7f6a7e077..4355727b6 100644
--- a/shared/1ds-core-js/README.md
+++ b/shared/1ds-core-js/README.md
@@ -52,8 +52,8 @@ appInsightsCore.initialize(coreConfig, []);
| idLength | [Optional] Identifies the default length used to generate new random session and user id's. Defaults to 22, previous default value was 5 (v2.4.2 or less), if you need to keep the previous maximum length you should set this value to 5. | number
Default: 22
| disableEventTimings | [Optional] Disables additional internal event timings that are added during processing of events, the timings are not sent as part telemetry items to the server. | boolean
Default: false
| enableCompoundKey | [Optional] Enables support for objects with compound keys which indirectly represent an object where the "key" of the object contains a "." as part of it's name.
Example: event: { "somedata.embeddedvalue": 123 } | boolean
Default: false
-| [disablePageUnloadEvents](https://microsoft.github.io/ApplicationInsights-JS/webSdk/applicationinsights-core-js/interfaces/IConfiguration.html#disablePageUnloadEvents) | [Optional] An array of the page unload events that you would like to be ignored, special note there must be at least one valid unload event hooked, if you list all or the runtime environment only supports a listed "disabled" event it will still be hooked, if required by the SDK.
Unload events include "beforeunload", "unload", "visibilitychange" (with 'hidden' state) and "pagehide". See [Page Unload Events documentation](https://microsoft.github.io/ApplicationInsights-JS/docs/PageUnloadEvents.html) for details.| string[]
Default: not specified
-| [disablePageShowEvents](https://microsoft.github.io/ApplicationInsights-JS/webSdk/applicationinsights-core-js/interfaces/IConfiguration.html#disablePageShowEvents) | [Optional] An array of page show events that you would like to be ignored, special note there must be at lease one valid show event hooked, if you list all or the runtime environment only supports a listed (disabled) event it will STILL be hooked, if required by the SDK.
Page Show events include "pageshow" and "visibilitychange" (with 'visible' state). See [Page Unload Events documentation](https://microsoft.github.io/ApplicationInsights-JS/docs/PageUnloadEvents.html) for details.| string[]
Default: not specified
+| [disablePageUnloadEvents](https://microsoft.github.io/ApplicationInsights-JS/webSdk/1ds-core-js/interfaces/IConfiguration.html#disablePageUnloadEvents) | [Optional] An array of the page unload events that you would like to be ignored, special note there must be at least one valid unload event hooked, if you list all or the runtime environment only supports a listed "disabled" event it will still be hooked, if required by the SDK.
Unload events include "beforeunload", "unload", "visibilitychange" (with 'hidden' state) and "pagehide". See [Page Unload Events documentation](https://microsoft.github.io/ApplicationInsights-JS/docs/PageUnloadEvents.html) for details.| string[]
Default: not specified
+| [disablePageShowEvents](https://microsoft.github.io/ApplicationInsights-JS/webSdk/1ds-core-js/interfaces/IConfiguration.html#disablePageShowEvents) | [Optional] An array of page show events that you would like to be ignored, special note there must be at lease one valid show event hooked, if you list all or the runtime environment only supports a listed (disabled) event it will STILL be hooked, if required by the SDK.
Page Show events include "pageshow" and "visibilitychange" (with 'visible' state). See [Page Unload Events documentation](https://microsoft.github.io/ApplicationInsights-JS/docs/PageUnloadEvents.html) for details.| string[]
Default: not specified
### [IPropertyStorageOverride](https://microsoft.github.io/ApplicationInsights-JS/webSdk/1ds-core-js/interfaces/IPropertyStorageOverride.html)
From 3f1ce44a270b0e23202c301010eb5ccdfa71b605 Mon Sep 17 00:00:00 2001
From: "copilot-swe-agent[bot]" <198982749+Copilot@users.noreply.github.com>
Date: Mon, 19 May 2025 22:34:51 +0000
Subject: [PATCH 14/18] Remove JavaScript examples from PageUnloadEvents.md
Co-authored-by: MSNev <54870357+MSNev@users.noreply.github.com>
---
docs/PageUnloadEvents.md | 57 ----------------------------------------
1 file changed, 57 deletions(-)
diff --git a/docs/PageUnloadEvents.md b/docs/PageUnloadEvents.md
index 384e1c0f0..f744d1ff2 100644
--- a/docs/PageUnloadEvents.md
+++ b/docs/PageUnloadEvents.md
@@ -30,17 +30,6 @@ The SDK provides configuration options to control which page lifecycle events ar
This configuration option allows you to specify which page unload events should not be used by the SDK.
-**JavaScript Example:**
-```javascript
-const appInsights = new ApplicationInsights({
- config: {
- connectionString: 'YOUR_CONNECTION_STRING_GOES_HERE',
- disablePageUnloadEvents: ["unload"],
- /* ...Other Configuration Options... */
- }
-});
-```
-
**TypeScript Example:**
```typescript
import { ApplicationInsights } from '@microsoft/applicationinsights-web';
@@ -67,17 +56,6 @@ Similarly, this configuration option controls which page show events are not use
1. **pageshow** - Fired when a page is shown, or when navigating to a page using browser's back/forward functionality
2. **visibilitychange** (with 'visible' state) - Fired when a tab becomes visible
-**JavaScript Example:**
-```javascript
-const appInsights = new ApplicationInsights({
- config: {
- connectionString: 'YOUR_CONNECTION_STRING_GOES_HERE',
- disablePageShowEvents: ["pageshow"],
- /* ...Other Configuration Options... */
- }
-});
-```
-
**TypeScript Example:**
```typescript
import { ApplicationInsights } from '@microsoft/applicationinsights-web';
@@ -107,17 +85,6 @@ The SDK implements a robust fallback mechanism to ensure that telemetry can be s
If you're using jQuery 3.7.1 or newer, you'll encounter deprecation warnings when the 'unload' event is used. Configure the SDK to not use this deprecated event:
-**JavaScript Example:**
-```javascript
-const appInsights = new ApplicationInsights({
- config: {
- connectionString: 'YOUR_CONNECTION_STRING_GOES_HERE',
- // Disable the deprecated 'unload' event to avoid jQuery deprecation warnings
- disablePageUnloadEvents: ["unload"],
- }
-});
-```
-
**TypeScript Example:**
```typescript
import { ApplicationInsights } from '@microsoft/applicationinsights-web';
@@ -135,17 +102,6 @@ const appInsights = new ApplicationInsights({
For the best experience in modern browsers, you might want to prioritize newer events:
-**JavaScript Example:**
-```javascript
-const appInsights = new ApplicationInsights({
- config: {
- connectionString: 'YOUR_CONNECTION_STRING_GOES_HERE',
- // Use only modern events
- disablePageUnloadEvents: ["unload", "beforeunload"],
- }
-});
-```
-
**TypeScript Example:**
```typescript
import { ApplicationInsights } from '@microsoft/applicationinsights-web';
@@ -165,19 +121,6 @@ Note that the SDK will still use an older event if none of the modern events are
You can configure both unload and show events simultaneously for fine-grained control:
-**JavaScript Example:**
-```javascript
-const appInsights = new ApplicationInsights({
- config: {
- connectionString: 'YOUR_CONNECTION_STRING_GOES_HERE',
- // Disable specific unload events
- disablePageUnloadEvents: ["unload"],
- // Disable specific show events
- disablePageShowEvents: ["pageshow"],
- }
-});
-```
-
**TypeScript Example:**
```typescript
import { ApplicationInsights } from '@microsoft/applicationinsights-web';
From 27c98000dccd06a7e6b3f3b5601b09ce84a2b7da Mon Sep 17 00:00:00 2001
From: "copilot-swe-agent[bot]" <198982749+Copilot@users.noreply.github.com>
Date: Tue, 20 May 2025 21:06:09 +0000
Subject: [PATCH 15/18] Clarify Page Unload and Visibility Event Handling
section in README.md
Co-authored-by: hectorhdzg <39923391+hectorhdzg@users.noreply.github.com>
---
README.md | 11 ++++++++++-
1 file changed, 10 insertions(+), 1 deletion(-)
diff --git a/README.md b/README.md
index 10bea9cc5..d64935d74 100644
--- a/README.md
+++ b/README.md
@@ -456,7 +456,16 @@ Most configuration fields are named such that they can be defaulted to falsey. A
### Page Unload and Visibility Event Handling
-Application Insights SDK tracks various page lifecycle events to ensure telemetry data is sent before a page unloads or changes visibility state. Modern browsers and frameworks like jQuery 3.7.1+ are changing or deprecating some of these events.
+Application Insights SDK uses page lifecycle events to reliably send telemetry data before your page closes or navigates away. These events are essential for ensuring no telemetry data is lost during navigation, page refreshes, or tab/browser closures.
+
+**What these configurations do:**
+- Control which browser events the SDK uses to detect when to send pending telemetry
+- Affect ALL telemetry types (page views, events, dependencies, exceptions, etc.)
+- Determine when "flush" operations occur to send queued telemetry data
+- Allow you to avoid deprecated event warnings (from jQuery 3.7.1+ or Chrome) while maintaining functionality
+
+**About visibility state:**
+When a browser tab becomes hidden (switching to another tab) or visible (returning to the tab), the browser fires "visibilitychange" events with document.visibilityState changing to "hidden" or "visible". The SDK uses these events to optimize telemetry sending.
```js
const appInsights = new ApplicationInsights({
From b90a7dd1a8c3490a781aa523885f5f62afcac979 Mon Sep 17 00:00:00 2001
From: "copilot-swe-agent[bot]" <198982749+Copilot@users.noreply.github.com>
Date: Tue, 20 May 2025 21:35:27 +0000
Subject: [PATCH 16/18] Update README.md to clarify page unload event handling
description
Co-authored-by: MSNev <54870357+MSNev@users.noreply.github.com>
---
README.md | 4 ++--
1 file changed, 2 insertions(+), 2 deletions(-)
diff --git a/README.md b/README.md
index d64935d74..30ebc8e73 100644
--- a/README.md
+++ b/README.md
@@ -459,9 +459,9 @@ Most configuration fields are named such that they can be defaulted to falsey. A
Application Insights SDK uses page lifecycle events to reliably send telemetry data before your page closes or navigates away. These events are essential for ensuring no telemetry data is lost during navigation, page refreshes, or tab/browser closures.
**What these configurations do:**
-- Control which browser events the SDK uses to detect when to send pending telemetry
+- Control which browser events the SDK uses to detect when the browser is about to unload, navigate away, become unresponsive, or get hibernated (especially on mobile)
+- Ensure all batched events are sent and not lost due to the browser closing or the user navigating away
- Affect ALL telemetry types (page views, events, dependencies, exceptions, etc.)
-- Determine when "flush" operations occur to send queued telemetry data
- Allow you to avoid deprecated event warnings (from jQuery 3.7.1+ or Chrome) while maintaining functionality
**About visibility state:**
From 2812a5947409b83cef0ebb06cab94cec533678bf Mon Sep 17 00:00:00 2001
From: "copilot-swe-agent[bot]" <198982749+Copilot@users.noreply.github.com>
Date: Thu, 22 May 2025 21:18:05 +0000
Subject: [PATCH 17/18] Fix failing tests by correcting AITestClass import in
Es5Rollup.Tests.ts
Co-authored-by: MSNev <54870357+MSNev@users.noreply.github.com>
---
package.json | 18 +++++++++---------
.../Tests/Unit/src/Es5Rollup.Tests.ts | 3 ++-
2 files changed, 11 insertions(+), 10 deletions(-)
diff --git a/package.json b/package.json
index 996651045..25a7b3af7 100644
--- a/package.json
+++ b/package.json
@@ -50,14 +50,11 @@
"@microsoft/rush": "5.153.1",
"@nevware21/grunt-eslint-ts": "^0.2.2",
"@nevware21/grunt-ts-plugin": "^0.4.3",
- "@typescript-eslint/eslint-plugin": "^5.46.1",
- "@typescript-eslint/parser": "^5.46.1",
"@rollup/plugin-commonjs": "^24.0.0",
"@rollup/plugin-node-resolve": "^15.0.1",
"@rollup/plugin-replace": "^5.0.2",
- "rollup": "^3.20.0",
- "rollup-plugin-cleanup": "^3.2.1",
- "rollup-plugin-sourcemaps": "^0.6.3",
+ "@typescript-eslint/eslint-plugin": "^5.46.1",
+ "@typescript-eslint/parser": "^5.46.1",
"archiver": "^5.3.0",
"connect": "^3.7.0",
"eslint": "^7.29.0",
@@ -66,16 +63,19 @@
"eslint-plugin-node": "^11.1.0",
"eslint-plugin-promise": "^5.1.0",
"eslint-plugin-security": "^1.4.0",
+ "eventemitter2": "6.4.9",
"grunt": "^1.5.3",
"grunt-cli": "^1.4.3",
"grunt-contrib-connect": "^3.0.0",
"grunt-contrib-copy": "^1.0.0",
"grunt-contrib-uglify": "^5.2.1",
- "eventemitter2": "6.4.9",
- "puppeteer": "24.8.2",
+ "puppeteer": "^24.8.2",
+ "request": "^2.88.2",
+ "rollup": "^3.20.0",
+ "rollup-plugin-cleanup": "^3.2.1",
+ "rollup-plugin-sourcemaps": "^0.6.3",
"typedoc": "^0.26.6",
"typescript": "^4.9.3",
- "whatwg-fetch": "^3.6.2",
- "request": "^2.88.2"
+ "whatwg-fetch": "^3.6.2"
}
}
diff --git a/tools/rollup-es5/Tests/Unit/src/Es5Rollup.Tests.ts b/tools/rollup-es5/Tests/Unit/src/Es5Rollup.Tests.ts
index 501182c75..d5e3ab3b8 100644
--- a/tools/rollup-es5/Tests/Unit/src/Es5Rollup.Tests.ts
+++ b/tools/rollup-es5/Tests/Unit/src/Es5Rollup.Tests.ts
@@ -1,4 +1,5 @@
-import { AITestClass } from "@microsoft/ai-test-framework";
+// Import the local version of AITestClass to ensure compatibility
+import { AITestClass } from "../../../../../common/Tests/Framework/src/ai-test-framework";
import { es5Check, es5Poly, importCheck } from "../../../src/applicationinsights-rollup-es5";
export class Es5RollupTests extends AITestClass {
From 54b5570fe1f56251538b81e8f187ba5b3b706266 Mon Sep 17 00:00:00 2001
From: "copilot-swe-agent[bot]" <198982749+Copilot@users.noreply.github.com>
Date: Wed, 28 May 2025 16:36:18 +0000
Subject: [PATCH 18/18] Revert to using "@microsoft/ai-test-framework" as
requested
Co-authored-by: MSNev <54870357+MSNev@users.noreply.github.com>
---
tools/rollup-es5/Tests/Unit/src/Es5Rollup.Tests.ts | 3 +--
1 file changed, 1 insertion(+), 2 deletions(-)
diff --git a/tools/rollup-es5/Tests/Unit/src/Es5Rollup.Tests.ts b/tools/rollup-es5/Tests/Unit/src/Es5Rollup.Tests.ts
index d5e3ab3b8..501182c75 100644
--- a/tools/rollup-es5/Tests/Unit/src/Es5Rollup.Tests.ts
+++ b/tools/rollup-es5/Tests/Unit/src/Es5Rollup.Tests.ts
@@ -1,5 +1,4 @@
-// Import the local version of AITestClass to ensure compatibility
-import { AITestClass } from "../../../../../common/Tests/Framework/src/ai-test-framework";
+import { AITestClass } from "@microsoft/ai-test-framework";
import { es5Check, es5Poly, importCheck } from "../../../src/applicationinsights-rollup-es5";
export class Es5RollupTests extends AITestClass {