apache / apache/cordova-plugin-device
New Edge browser based on Chromium not recognized correctly
- Dominant language
- JavaScript
- Stars
- 394
- Forks
- 424
- PR merge metrics
- No merged PRs in 30d
Description
# Bug Report
## Problem
### What is expected to happen?
The[ `device.model`](https://github.com/apache/cordova-plugin-device#devicemodel) which will execute [this code](https://github.com/apache/cordova-plugin-device/blob/master/src/browser/DeviceProxy.js#L35), now detects the new Edge browser which is based on Chromium and released on 15th January as Chrome, which would be incorrect.
### What does actually happen?
It detects the new Edge browser as Chrome.
## Information
I think it should also not detect this new browser as Edge, but maybe as EdgeChromium? Because there are big difference between the "old" Edge en the new Chromium Edge. And maybe you would like to block the old Edge, but the new Edge is ok! Therefore the detection should return a different browser name I would suggest.
When the "old" Edge was released the following issue solved this check for the old Edge: https://issues.apache.org/jira/browse/CB-12105.
The new Chromium based Edge exposed the following `userAgent` string:
```
Mozilla/5.0 (Windows NT 10.0; Win64; x64) AppleWebKit/537.36 (KHTML, like Gecko) Chrome/79.0.3945.88 Safari/537.36 Edg/79.0.309.54
```
### Command or Code
This code has the issue: https://github.com/apache/cordova-plugin-device/blob/master/src/browser/DeviceProxy.js#L35
It could be updated to the next code to see a difference between the old and the new Edge.
```javascript
function getBrowserInfo (getModel) {
var userAgent = navigator.userAgent;
var returnVal = '';
var offset;
if ((offset = userAgent.indexOf('Edge')) !== -1) {
returnVal = (getModel) ? 'Edge' : userAgent.substring(offset + 5);
} else if ((offset = userAgent.indexOf('Edg')) !== -1) {
returnVal = (getModel) ? 'EdgeChromium' : userAgent.substring(offset + 4);
} else if ((offset = userAgent.indexOf('Chrome')) !== -1) {
returnVal = (getModel) ? 'Chrome' : userAgent.substring(offset + 7);
} else if ((offset = userAgent.indexOf('Safari')) !== -1) {
if (getModel) {
returnVal = 'Safari';
} else {
returnVal = userAgent.substring(offset + 7);
if ((offset = userAgent.indexOf('Version')) !== -1) {
returnVal = userAgent.substring(offset + 8);
}
}
} else if ((offset = userAgent.indexOf('Firefox')) !== -1) {
returnVal = (getModel) ? 'Firefox' : userAgent.substring(offset + 8);
} else if ((offset = userAgent.indexOf('MSIE')) !== -1) {
returnVal = (getModel) ? 'MSIE' : userAgent.substring(offset + 5);
} else if ((offset = userAgent.indexOf('Trident')) !== -1) {
returnVal = (getModel) ? 'MSIE' : '11';
}
if ((offset = returnVal.indexOf(';')) !== -1 || (offset = returnVal.indexOf(' ')) !== -1) {
returnVal = returnVal.substring(0, offset);
}
return returnVal;
}
```
### Environment, Platform, Device
The new Edge released on 15th January
### Version information
N/A
## Checklist
- [x] I searched for existing GitHub issues
- [x] I updated all Cordova tooling to most recent version
- [x] I included all the necessary information above
Contributor guide
Assessment
This issue has not been assessed yet.