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

Edge browser detected as Chrome. #113

Open
johnrizzo4 opened this issue Feb 13, 2023 · 3 comments
Open

Edge browser detected as Chrome. #113

johnrizzo4 opened this issue Feb 13, 2023 · 3 comments

Comments

@johnrizzo4
Copy link

johnrizzo4 commented Feb 13, 2023

In this article from 2019, the Microsoft team explains why they replaced "Edge" by "Edg" in the userAgent string.
https://blogs.windows.com/msedgedev/2019/04/08/microsoft-edge-preview-channel-details/
Look for the subtitle "User Agent String"

getBrowserInfo..js is looking for "Edge" instead of "Edg" at line 3:

var isEdge = navigator.userAgent.indexOf('Edge') !== -1 && (!!navigator.msSaveOrOpenBlob || !!navigator.msSaveBlob);

My suggested replacement:

var isEdge = (navigator.userAgent.indexOf('Edge') !== -1 || navigator.userAgent.indexOf('Edg') !== -1) // Microsoft replaced 'Edge' by 'Edg' a while ago to avoid confusion with a legacy Edge browser.
             && (!!navigator.msSaveOrOpenBlob || !!navigator.msSaveBlob);

This recent article shows similar code with "Edg": https://codepedia.info/detect-browser-in-javascript

I guess that this is why Edge is identified as Chrome by DetectRTC (since Edge also includes "Chrome" their string).
It's easy to see with https://www.webrtc-experiment.com/DetectRTC/ running from Edge as shown in this screenshot.

image

@David-dp-
Copy link

David-dp- commented Feb 15, 2023

I just tested your suggested change in Edge Version 110.0.1587.41 (Official build) (64-bit). The first part of the AND succeeded but the second part was false. I tried each part in the console, too:

navigator.userAgent.indexOf('Edge')
-1
navigator.userAgent.indexOf('Edg')
112
navigator.msSaveOrOpenBlob
undefined
navigator.msSaveBlob
undefined

You should also use this updated line:
var isChrome = !!window.chrome && !isEdge && !isOpera;
And these:

fullVersion = navigator.userAgent.split(/Edge?\//)[1];
// fullVersion = parseInt(navigator.userAgent.match(/Edge?\/(\d+).(\d+)$/)[2], 10).toString();

@johnrizzo4
Copy link
Author

I've updated the PR with your proposed changes, thank you David.

About navigator.msSaveOrOpenBlob and navigator.msSaveBlob, it's just a copy of the existing code. I don't understand the origin of that part which is not commented. I'll remove it from my PR as you suggest.

@junaiddarajat
Copy link

junaiddarajat commented May 4, 2023

@johnrizzo4 I tried your PR, for macOS Monterey and Microsoft Edge Version 112.0.1722.68 (Official build) (x86_64); it's still showing as 'Chrome'. Should this be a proper case or maybe I'm doing something wrong?

EDIT: For using your PR, I've done the following at my React project's package.json dependencies:

        "detectrtc": "https://github.com/johnrizzo4/DetectRTC/#patch-issue-113-Edge-seen-as-Chrome",

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
None yet
Projects
None yet
Development

No branches or pull requests

3 participants