Skip to content

Commit

Permalink
[BUG] v2.8.1 with a Hosted IE environment fails to initialize for a h…
Browse files Browse the repository at this point in the history
…osted instance of IE #1822

[BUG] IE8 Support was broken by several components #1823
  • Loading branch information
MSNev committed Apr 29, 2022
1 parent 4e88f21 commit 45b2c3b
Show file tree
Hide file tree
Showing 30 changed files with 279 additions and 237 deletions.
1 change: 1 addition & 0 deletions .gitignore
Original file line number Diff line number Diff line change
Expand Up @@ -261,3 +261,4 @@ aicore.tests.js*
aicore.tests.d.ts
ai.tests.d.ts
/.vs
/index.html
76 changes: 47 additions & 29 deletions AISKU/Tests/Perf/src/AISKUPerf.Tests.ts
Original file line number Diff line number Diff line change
Expand Up @@ -123,7 +123,6 @@ function addSnippetLoadingTimeEvent(AISKUPerfTest: any, endtime: number): void {
createPerfEvent(AISKUPerfTest, "SDKInit", duration, true, `AppInsightsInit-Init: Script LoadingTime: ${duration} ms added`);
}


export class AISKUPerf extends AITestClass {
public AISKUPerfTest: AppInsightsInitPerfTestClass;
public perfMgr: any;
Expand All @@ -137,7 +136,6 @@ export class AISKUPerf extends AITestClass {
public testInitialize() {
try {
this.AISKUPerfTest = new AppInsightsInitPerfTestClass();
this.AISKUPerfTest.loadScriptOnInit = () => {return this._loadScriptOnInit();}
Assert.ok(window["oneDS"], "oneDS exists");
Assert.ok(window["Microsoft"]?.ApplicationInsights?.PerfMarkMeasureManager, "perfMgr exists");
Assert.ok(window["Microsoft"]?.ApplicationInsights?.doPerf, "doPerf exists");
Expand Down Expand Up @@ -167,6 +165,7 @@ export class AISKUPerf extends AITestClass {
this.testCaseAsync({
name: "AppInsights AISKU perf Test",
stepDelay: 10000,
assertNoHooks: false,
steps: [() => {
Assert.ok(window["appInsightsInitPerftest"], "global appInsightsInitPerftest exists");
Assert.ok(window["oneDS"], "oneDS exists");
Expand Down Expand Up @@ -199,16 +198,27 @@ export class AISKUPerf extends AITestClass {
});
}

protected _loadScriptOnInit(): void {
protected _loadScriptOnInit(theModule: any): void {
var snippetLoadingEndTime = performance.now();
this._addMemoryPerfEvent(this.initialMemoryUsage);
Assert.ok(true,"AppInsights script loaded");

addSnippetLoadingTimeEvent(this.AISKUPerfTest,snippetLoadingEndTime);
addSnippetLoadingTimeEvent(this.AISKUPerfTest, snippetLoadingEndTime);

let appInsights = window["appInsights"];
this.appInsights = appInsights;

this.onDone(() => {
if (appInsights && appInsights.unload && appInsights.core && appInsights.core.isInitialized()) {
Assert.ok(true, "Unloading...");
appInsights.unload(false);
} else {
Assert.ok(true, "Unload not supported...");
}

appInsights = null;
this.appInsights = null;
});
try {
let notificationManager = this.appInsights.core["_notificationManager"] ||this.appInsights.core?.getNotifyMgr();
if (notificationManager) {
Expand All @@ -230,29 +240,31 @@ export class AISKUPerf extends AITestClass {
}

protected _loadSnippet():void {
this.initialMemoryUsage = performance["memory"]?.usedJSHeapSize;
var tag = document.createElement("script");
tag.innerText = this.getSnippet();
this.AISKUPerfTest.snippetStartTime = performance.now();
document.getElementsByTagName("head")[0].appendChild(tag);
}

public getSnippet(): string {
return `
loadSdkUsingRequire({
src: "https://js.monitor.azure.com/scripts/b/ai.${this.AISKUPerfTest.version}.min.js?${this.AISKUPerfTest.testPostfix}",
onInit: function (appInsights) {
console.log("snippet loaded");
appInsightsInitPerftest.loadScriptOnInit();
},
cfg: {
instrumentationKey: "key",
enablePerfMgr: true,
maxBatchSizeInBytes: 1000000,
maxBatchInterval: 30000000,
extensionConfig: {}
}
});`;
let self = this;
self.initialMemoryUsage = performance["memory"]?.usedJSHeapSize;
window["loadSdkUsingRequire"]({
src: self.getScriptSrc(),
onInit: function (theInstance) {
console.log("snippet loaded");
self._loadScriptOnInit(theInstance);

self.onDone(() => {
if (theInstance && theInstance.unload && theInstance.core && theInstance.core.isInitialized()) {
Assert.ok(true, "Unloading from onInit...");
theInstance.unload(false);
} else {
Assert.ok(true, "Unload not supported in onInit...");
}
});
},
cfg: {
instrumentationKey: "key",
enablePerfMgr: true,
maxBatchSizeInBytes: 1000000,
maxBatchInterval: 30000000,
extensionConfig: {}
}
});
}

public addPerfEvents() {
Expand All @@ -277,8 +289,14 @@ export class AISKUPerf extends AITestClass {
}

public getScriptSrc(): string {
return `https://js.monitor.azure.com/scripts/b/ai.${this.AISKUPerfTest.version}.min.js?${this.AISKUPerfTest.testPostfix}`;
}
let baseUrl = "https://js.monitor.azure.com/scripts/b/ai.";

if (this.AISKUPerfTest.version.indexOf("nightly") !== -1) {
baseUrl = "https://js.monitor.azure.com/nightly/ai.";
}

return baseUrl + `${this.AISKUPerfTest.version}.min.js?${this.AISKUPerfTest.testPostfix}`;
}

private _addMemoryPerfEvent(initialMemoryUsage: number, metric?: string): void {
let curMemory = performance["memory"]?.usedJSHeapSize;
Expand Down
4 changes: 3 additions & 1 deletion AISKU/Tests/PerfTests.html
Original file line number Diff line number Diff line change
Expand Up @@ -55,7 +55,9 @@
};

if (snippetCfg.onInit) {
appInsights.queue.push(snippetCfg.onInit);
appInsights.queue.push(function() {
snippetCfg.onInit(appInsights);
});
}

window["appInsights"] = appInsights;
Expand Down
2 changes: 1 addition & 1 deletion AISKU/package.json
Original file line number Diff line number Diff line change
Expand Up @@ -64,7 +64,7 @@
"tslib": "*"
},
"dependencies": {
"@microsoft/dynamicproto-js": "^1.1.4",
"@microsoft/dynamicproto-js": "^1.1.5",
"@microsoft/applicationinsights-shims": "2.0.1",
"@microsoft/applicationinsights-analytics-js": "2.8.1",
"@microsoft/applicationinsights-channel-js": "2.8.1",
Expand Down
4 changes: 2 additions & 2 deletions AISKU/src/ApplicationInsightsDeprecated.ts
Original file line number Diff line number Diff line change
Expand Up @@ -5,7 +5,7 @@ import {
IEventTelemetry, IEnvelope, ProcessLegacy
} from "@microsoft/applicationinsights-common";
import { Snippet, Initialization as ApplicationInsights } from "./Initialization";
import { ITelemetryItem, IDiagnosticLogger, IConfiguration, proxyAssign, throwError, ICookieMgr } from "@microsoft/applicationinsights-core-js";
import { ITelemetryItem, IDiagnosticLogger, IConfiguration, proxyAssign, throwError, ICookieMgr, arrIndexOf } from "@microsoft/applicationinsights-core-js";

// This is an exclude list of properties that should not be updated during initialization
// They include a combination of private and internal property names
Expand Down Expand Up @@ -187,7 +187,7 @@ export class AppInsightsDeprecated implements IAppInsightsDeprecated {
// Note: This must be called before loadAppInsights is called
proxyAssign(snippet, this, (name: string) => {
// Not excluding names prefixed with "_" as we need to proxy some functions like _onError
return name && _ignoreUpdateSnippetProperties.indexOf(name) === -1;
return name && arrIndexOf(_ignoreUpdateSnippetProperties, name) === -1;
});
}

Expand Down
6 changes: 3 additions & 3 deletions AISKU/src/Initialization.ts
Original file line number Diff line number Diff line change
Expand Up @@ -7,7 +7,7 @@ import {
IChannelControls, hasWindow, hasDocument, isReactNative, doPerf, IDiagnosticLogger, INotificationManager, objForEachKey, proxyAssign, proxyFunctions,
arrForEach, isString, isFunction, isNullOrUndefined, isArray, throwError, ICookieMgr, addPageUnloadEventListener, addPageHideEventListener,
createUniqueNamespace, ITelemetryPlugin, IPlugin, ILoadedPlugin, UnloadHandler, removePageUnloadEventListener, removePageHideEventListener,
ITelemetryInitializerHandler, ITelemetryUnloadState, mergeEvtNamespace, _throwInternal
ITelemetryInitializerHandler, ITelemetryUnloadState, mergeEvtNamespace, _throwInternal, arrIndexOf
} from "@microsoft/applicationinsights-core-js";
import { AnalyticsPlugin, ApplicationInsights } from "@microsoft/applicationinsights-analytics-js";
import { Sender } from "@microsoft/applicationinsights-channel-js";
Expand Down Expand Up @@ -235,7 +235,7 @@ export class Initialization implements IApplicationInsights {
if (isString(field) &&
!isFunction(value) &&
field && field[0] !== "_" && // Don't copy "internal" values
_ignoreUpdateSnippetProperties.indexOf(field) === -1) {
arrIndexOf(_ignoreUpdateSnippetProperties, field) === -1) {
snippet[field as string] = value;
}
});
Expand Down Expand Up @@ -277,7 +277,7 @@ export class Initialization implements IApplicationInsights {
// Note: This must be called before loadAppInsights is called
proxyAssign(snippet, _self, (name: string) => {
// Not excluding names prefixed with "_" as we need to proxy some functions like _onError
return name && _ignoreUpdateSnippetProperties.indexOf(name) === -1;
return name && arrIndexOf(_ignoreUpdateSnippetProperties, name) === -1;
});
};

Expand Down
2 changes: 1 addition & 1 deletion AISKULight/package.json
Original file line number Diff line number Diff line change
Expand Up @@ -49,7 +49,7 @@
"tslib": "*"
},
"dependencies": {
"@microsoft/dynamicproto-js": "^1.1.4",
"@microsoft/dynamicproto-js": "^1.1.5",
"@microsoft/applicationinsights-shims": "2.0.1",
"@microsoft/applicationinsights-common": "2.8.1",
"@microsoft/applicationinsights-channel-js": "2.8.1",
Expand Down
2 changes: 1 addition & 1 deletion channels/applicationinsights-channel-js/package.json
Original file line number Diff line number Diff line change
Expand Up @@ -45,7 +45,7 @@
"tslib": "*"
},
"dependencies": {
"@microsoft/dynamicproto-js": "^1.1.4",
"@microsoft/dynamicproto-js": "^1.1.5",
"@microsoft/applicationinsights-shims": "2.0.1",
"@microsoft/applicationinsights-core-js": "2.8.1",
"@microsoft/applicationinsights-common": "2.8.1"
Expand Down
2 changes: 1 addition & 1 deletion common/Tests/Framework/package.json
Original file line number Diff line number Diff line change
Expand Up @@ -49,6 +49,6 @@
"tslib": "*"
},
"dependencies": {
"@microsoft/dynamicproto-js": "^1.1.4"
"@microsoft/dynamicproto-js": "^1.1.5"
}
}

0 comments on commit 45b2c3b

Please sign in to comment.