Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

In getting IE version, prefer Trident version over MSIE version. #1726

Merged
merged 6 commits into from
Dec 10, 2021
Merged
Show file tree
Hide file tree
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
13 changes: 11 additions & 2 deletions shared/AppInsightsCommon/Tests/Unit/src/Util.tests.ts
Original file line number Diff line number Diff line change
Expand Up @@ -531,8 +531,8 @@ export class UtilTests extends AITestClass {
}

Assert.equal(7, Util.getIEVersion("Mozilla/4.0 (compatible; MSIE 7.0b; Windows NT 6.0)"));
Assert.equal(7, Util.getIEVersion("Mozilla/4.0 (compatible; MSIE 7.0; Windows NT 6.0; WOW64; Trident/4.0;)"));
Assert.equal(7, Util.getIEVersion("Mozilla/5.0 (compatible; MSIE 7.0; Windows NT 6.0; en-US)"));
Assert.equal(7, Util.getIEVersion("Mozilla/4.0 (compatible; MSIE 7.0; Windows NT 6.0; WOW64; Trident/4.0;)"));
Assert.equal(8, Util.getIEVersion("Mozilla/4.0 (compatible; MSIE 8.0; Windows NT 5.1; Trident/4.0)"));
Assert.equal(8, Util.getIEVersion("Mozilla/4.0 (compatible; MSIE 8.0; Windows NT 6.1; Trident/4.0)"));
Assert.equal(8, Util.getIEVersion("Mozilla/5.0 (compatible; MSIE 8.0; Windows NT 6.0; Trident/4.0; WOW64; Trident/4.0; SLCC2; .NET CLR 2.0.50727; .NET CLR 3.5.30729; .NET CLR 3.0.30729; .NET CLR 1.0.3705; .NET CLR 1.1.4322)"));
Expand All @@ -546,7 +546,16 @@ export class UtilTests extends AITestClass {
Assert.equal(11, Util.getIEVersion("Mozilla/5.0 (Windows NT 6.3; Trident/7.0; rv:11.0) like Gecko"));
Assert.equal(11, Util.getIEVersion("Mozilla/5.0 (Windows NT 10.0; Trident/7.0; rv:11.0) like Gecko"));
Assert.equal(11, Util.getIEVersion("Mozilla/5.0 (Windows NT 6.1; WOW64; Trident/7.0; AS; rv:11.0) like Gecko"));

const origDocMode = document['documentMode'];
document['documentMode'] = 11;

Assert.equal(11, Util.getIEVersion("Mozilla/4.0 (Compatible; MSIE 8.0; Windows NT 5.2; Trident/6.0)"));
Assert.equal(11, Util.getIEVersion("Mozilla/4.0 (compatible; MSIE 7.0; Windows NT 6.2; Win64; x64; Trident/7.0; .NET4.0C; .NET4.0E)"));

// restore documentMode
document['documentMode'] = origDocMode;
}
});
}
}
}
5 changes: 4 additions & 1 deletion shared/AppInsightsCore/src/JavaScriptSDK/EnvUtils.ts
Original file line number Diff line number Diff line change
Expand Up @@ -19,6 +19,7 @@ declare var XDomainRequest: any;

const strWindow = "window";
const strDocument = "document";
const strDocumentMode = "documentMode";
const strNavigator = "navigator";
const strHistory = "history";
const strLocation = "location";
Expand Down Expand Up @@ -311,8 +312,10 @@ export function getIEVersion(userAgentStr: string = null): number {
}

var ua = (userAgentStr || "").toLowerCase();
// Also check for documentMode in case X-UA-Compatible meta tag was included in HTML.
if (strContains(ua, strMsie)) {
return parseInt(ua.split(strMsie)[1]);
let doc = getDocument() || {} as Document;
Copy link
Collaborator

Choose a reason for hiding this comment

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

👍

return Math.max(parseInt(ua.split(strMsie)[1]), (doc[strDocumentMode] || 0));
} else if (strContains(ua, strTrident)) {
let tridentVer = parseInt(ua.split(strTrident)[1]);
if (tridentVer) {
Expand Down