Skip to content
Merged
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
18 changes: 17 additions & 1 deletion tools/applicationinsights-web-snippet/src/snippet.ts
Original file line number Diff line number Diff line change
Expand Up @@ -35,6 +35,15 @@ import { IConfiguration, Snippet } from "@microsoft/applicationinsights-web";
version: 2.0, // initialization version, if this is not 2.0 the previous scripts fail to initialize
config: aiConfig
};
function isIE() {
let nav = navigator;
if (nav) {
let userAgent = (nav.userAgent || "").toLowerCase();
return (userAgent.indexOf("msie") !== -1 || userAgent.indexOf("trident/") !== -1);
}
return false;
}

function _parseConnectionString() {
let fields:Fields = {};
let connectionString = aiConfig.connectionString;
Expand Down Expand Up @@ -169,8 +178,15 @@ import { IConfiguration, Snippet } from "@microsoft/applicationinsights-web";
}

// Assigning these to local variables allows them to be minified to save space:
let targetSrc = (aiConfig as any)["url"] || snipConfig.src
let targetSrc : string = (aiConfig as any)["url"] || snipConfig.src
if (targetSrc) {
if (isIE() && targetSrc.indexOf("ai.3") !== -1) {
// This regex matches any URL which contains "\ai.3." but not any full versions like "\ai.3.1" etc
targetSrc = targetSrc.replace(/(\/)(ai\.3\.)([^\d]*)$/, function(_all, g1, g2) {
Copy link
Collaborator

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

looks like we need to add the TypeScript definition for these, they are all strings so adding : string as the type should be all that is needed here.

return g1 + "ai.2" + g2;
});
// let message = "Load Version 2 SDK instead to support IE"; // where to report this error?
}
const _handleError = (evt?: any) => {
loadFailed = true;
appInsights.queue = []; // Clear the queue
Expand Down