Uploaded image for project: 'Apache Cordova'
  1. Apache Cordova
  2. CB-12105

window.device.model returns "Chrome" instead of "Edge" when using MS Edge

    Details

    • Type: Bug
    • Status: Closed
    • Priority: Critical
    • Resolution: Fixed
    • Affects Version/s: 6.3.2
    • Fix Version/s: None
    • Component/s: cordova-plugin-device
    • Labels:
      None

      Description

      When building for platform browser the cordova-plugin-device (v1.3.2) returns "Chrome" instead of "Edge" when requesting window.device.model on an Edge browser.

      In the DeviceProxy.js the following code is there: https://github.com/apache/cordova-plugin-device/blob/master/src/browser/DeviceProxy.js#L40

      function getBrowserInfo(getModel) {
          var userAgent = navigator.userAgent;
          var returnVal = '';
          var offset;
      
          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;
      }
      

      The code above returns model Chrome as soon as it is in the userAgent string. MS Edge provides the following userAgent string: Mozilla/5.0 (Windows NT 10.0; Win64; x64) AppleWebKit/537.36 (KHTML, like Gecko) Chrome/51.0.2704.79 Safari/537.36 Edge/14.14393

      So it seems we should be checking first if "Edge" is part of the userAgent. If so the browser would be Edge.

        Issue Links

          Activity

          Hide
          githubbot ASF GitHub Bot added a comment -

          GitHub user alsorokin opened a pull request:

          https://github.com/apache/cordova-plugin-device/pull/61

          CB-12105 (browser) Properly detect Edge

              1. Platforms affected
                Browser
              1. What does this PR do?
                Allows the plugin to properly detect Edge browser.
                https://issues.apache.org/jira/browse/CB-12105
              1. What testing has been done on this change?
                Tested on Edge 38, Chrome 56, Firefox 51
              1. Checklist
          • [x] [Reported an issue](https://issues.apache.org/jira/browse/CB-12105) in the JIRA database
          • [x] Commit message follows the format: "CB-3232: (android) Fix bug with resolving file paths", where CB-xxxx is the JIRA ID & "android" is the platform affected.
          • [ ] Added automated test coverage as appropriate for this change.

          You can merge this pull request into a Git repository by running:

          $ git pull https://github.com/alsorokin/cordova-plugin-device CB-12105

          Alternatively you can review and apply these changes as the patch at:

          https://github.com/apache/cordova-plugin-device/pull/61.patch

          To close this pull request, make a commit to your master/trunk branch
          with (at least) the following in the commit message:

          This closes #61


          commit 4472603a42859084f1a151ebc3676421d33547a7
          Author: Alexander Sorokin <alexander.sorokin@akvelon.com>
          Date: 2017-02-28T08:09:13Z

          CB-12105 (browser) Properly detect Edge


          Show
          githubbot ASF GitHub Bot added a comment - GitHub user alsorokin opened a pull request: https://github.com/apache/cordova-plugin-device/pull/61 CB-12105 (browser) Properly detect Edge Platforms affected Browser What does this PR do? Allows the plugin to properly detect Edge browser. https://issues.apache.org/jira/browse/CB-12105 What testing has been done on this change? Tested on Edge 38, Chrome 56, Firefox 51 Checklist [x] [Reported an issue] ( https://issues.apache.org/jira/browse/CB-12105 ) in the JIRA database [x] Commit message follows the format: " CB-3232 : (android) Fix bug with resolving file paths", where CB-xxxx is the JIRA ID & "android" is the platform affected. [ ] Added automated test coverage as appropriate for this change. You can merge this pull request into a Git repository by running: $ git pull https://github.com/alsorokin/cordova-plugin-device CB-12105 Alternatively you can review and apply these changes as the patch at: https://github.com/apache/cordova-plugin-device/pull/61.patch To close this pull request, make a commit to your master/trunk branch with (at least) the following in the commit message: This closes #61 commit 4472603a42859084f1a151ebc3676421d33547a7 Author: Alexander Sorokin <alexander.sorokin@akvelon.com> Date: 2017-02-28T08:09:13Z CB-12105 (browser) Properly detect Edge
          Hide
          githubbot ASF GitHub Bot added a comment -

          Github user cordova-qa commented on the issue:

          https://github.com/apache/cordova-plugin-device/pull/61

          Cordova CI Build has completed successfully.

          *Commit* - [Link](https://github.com/apache/cordova-plugin-device/pull/61/commits/4472603a42859084f1a151ebc3676421d33547a7)
          *Dashboard* - [Link](http://cordova-ci.cloudapp.net:8080/job/cordova-plugin-device-pr/25/)

          Builder Name Console Output Test Report Device Logs
          :---: :---: :---: :---:
          [Windows 10 Store]( http://cordova-ci.cloudapp.net:8080/job/cordova-plugin-device-pr/25//PLATFORM=windows-10-store/) [Link]( http://cordova-ci.cloudapp.net:8080/job/cordova-plugin-device-pr/25//PLATFORM=windows-10-store/console) [Link]( http://cordova-ci.cloudapp.net:8080/job/cordova-plugin-device-pr/25//PLATFORM=windows-10-store/testReport/) [Link]( http://cordova-ci.cloudapp.net:8080/job/cordova-plugin-device-pr/25//PLATFORM=windows-10-store/artifact/)
          [iOS 9.3]( http://cordova-ci.cloudapp.net:8080/job/cordova-plugin-device-pr/25//PLATFORM=ios-9.3/) [Link]( http://cordova-ci.cloudapp.net:8080/job/cordova-plugin-device-pr/25//PLATFORM=ios-9.3/console) [Link]( http://cordova-ci.cloudapp.net:8080/job/cordova-plugin-device-pr/25//PLATFORM=ios-9.3/testReport/) [Link]( http://cordova-ci.cloudapp.net:8080/job/cordova-plugin-device-pr/25//PLATFORM=ios-9.3/artifact/)
          [iOS 10.0]( http://cordova-ci.cloudapp.net:8080/job/cordova-plugin-device-pr/25//PLATFORM=ios-10.0/) [Link]( http://cordova-ci.cloudapp.net:8080/job/cordova-plugin-device-pr/25//PLATFORM=ios-10.0/console) [Link]( http://cordova-ci.cloudapp.net:8080/job/cordova-plugin-device-pr/25//PLATFORM=ios-10.0/testReport/) [Link]( http://cordova-ci.cloudapp.net:8080/job/cordova-plugin-device-pr/25//PLATFORM=ios-10.0/artifact/)
          [Android 4.4]( http://cordova-ci.cloudapp.net:8080/job/cordova-plugin-device-pr/25//PLATFORM=android-4.4/) [Link]( http://cordova-ci.cloudapp.net:8080/job/cordova-plugin-device-pr/25//PLATFORM=android-4.4/console) [Link]( http://cordova-ci.cloudapp.net:8080/job/cordova-plugin-device-pr/25//PLATFORM=android-4.4/testReport/) [Link]( http://cordova-ci.cloudapp.net:8080/job/cordova-plugin-device-pr/25//PLATFORM=android-4.4/artifact/)
          [Android 5.1]( http://cordova-ci.cloudapp.net:8080/job/cordova-plugin-device-pr/25//PLATFORM=android-5.1/) [Link]( http://cordova-ci.cloudapp.net:8080/job/cordova-plugin-device-pr/25//PLATFORM=android-5.1/console) [Link]( http://cordova-ci.cloudapp.net:8080/job/cordova-plugin-device-pr/25//PLATFORM=android-5.1/testReport/) [Link]( http://cordova-ci.cloudapp.net:8080/job/cordova-plugin-device-pr/25//PLATFORM=android-5.1/artifact/)
          Show
          githubbot ASF GitHub Bot added a comment - Github user cordova-qa commented on the issue: https://github.com/apache/cordova-plugin-device/pull/61 Cordova CI Build has completed successfully. * Commit * - [Link] ( https://github.com/apache/cordova-plugin-device/pull/61/commits/4472603a42859084f1a151ebc3676421d33547a7 ) * Dashboard * - [Link] ( http://cordova-ci.cloudapp.net:8080/job/cordova-plugin-device-pr/25/ ) Builder Name Console Output Test Report Device Logs :---: :---: :---: :---: [Windows 10 Store] ( http://cordova-ci.cloudapp.net:8080/job/cordova-plugin-device-pr/25//PLATFORM=windows-10-store/ ) [Link] ( http://cordova-ci.cloudapp.net:8080/job/cordova-plugin-device-pr/25//PLATFORM=windows-10-store/console ) [Link] ( http://cordova-ci.cloudapp.net:8080/job/cordova-plugin-device-pr/25//PLATFORM=windows-10-store/testReport/ ) [Link] ( http://cordova-ci.cloudapp.net:8080/job/cordova-plugin-device-pr/25//PLATFORM=windows-10-store/artifact/ ) [iOS 9.3] ( http://cordova-ci.cloudapp.net:8080/job/cordova-plugin-device-pr/25//PLATFORM=ios-9.3/ ) [Link] ( http://cordova-ci.cloudapp.net:8080/job/cordova-plugin-device-pr/25//PLATFORM=ios-9.3/console ) [Link] ( http://cordova-ci.cloudapp.net:8080/job/cordova-plugin-device-pr/25//PLATFORM=ios-9.3/testReport/ ) [Link] ( http://cordova-ci.cloudapp.net:8080/job/cordova-plugin-device-pr/25//PLATFORM=ios-9.3/artifact/ ) [iOS 10.0] ( http://cordova-ci.cloudapp.net:8080/job/cordova-plugin-device-pr/25//PLATFORM=ios-10.0/ ) [Link] ( http://cordova-ci.cloudapp.net:8080/job/cordova-plugin-device-pr/25//PLATFORM=ios-10.0/console ) [Link] ( http://cordova-ci.cloudapp.net:8080/job/cordova-plugin-device-pr/25//PLATFORM=ios-10.0/testReport/ ) [Link] ( http://cordova-ci.cloudapp.net:8080/job/cordova-plugin-device-pr/25//PLATFORM=ios-10.0/artifact/ ) [Android 4.4] ( http://cordova-ci.cloudapp.net:8080/job/cordova-plugin-device-pr/25//PLATFORM=android-4.4/ ) [Link] ( http://cordova-ci.cloudapp.net:8080/job/cordova-plugin-device-pr/25//PLATFORM=android-4.4/console ) [Link] ( http://cordova-ci.cloudapp.net:8080/job/cordova-plugin-device-pr/25//PLATFORM=android-4.4/testReport/ ) [Link] ( http://cordova-ci.cloudapp.net:8080/job/cordova-plugin-device-pr/25//PLATFORM=android-4.4/artifact/ ) [Android 5.1] ( http://cordova-ci.cloudapp.net:8080/job/cordova-plugin-device-pr/25//PLATFORM=android-5.1/ ) [Link] ( http://cordova-ci.cloudapp.net:8080/job/cordova-plugin-device-pr/25//PLATFORM=android-5.1/console ) [Link] ( http://cordova-ci.cloudapp.net:8080/job/cordova-plugin-device-pr/25//PLATFORM=android-5.1/testReport/ ) [Link] ( http://cordova-ci.cloudapp.net:8080/job/cordova-plugin-device-pr/25//PLATFORM=android-5.1/artifact/ )
          Hide
          jira-bot ASF subversion and git services added a comment -

          Commit 4472603a42859084f1a151ebc3676421d33547a7 in cordova-plugin-device's branch refs/heads/master from Alexander Sorokin
          [ https://git-wip-us.apache.org/repos/asf?p=cordova-plugin-device.git;h=4472603 ]

          CB-12105 (browser) Properly detect Edge

          Show
          jira-bot ASF subversion and git services added a comment - Commit 4472603a42859084f1a151ebc3676421d33547a7 in cordova-plugin-device's branch refs/heads/master from Alexander Sorokin [ https://git-wip-us.apache.org/repos/asf?p=cordova-plugin-device.git;h=4472603 ] CB-12105 (browser) Properly detect Edge
          Hide
          githubbot ASF GitHub Bot added a comment -

          Github user asfgit closed the pull request at:

          https://github.com/apache/cordova-plugin-device/pull/61

          Show
          githubbot ASF GitHub Bot added a comment - Github user asfgit closed the pull request at: https://github.com/apache/cordova-plugin-device/pull/61
          Hide
          jira-bot ASF subversion and git services added a comment -

          Commit 4472603a42859084f1a151ebc3676421d33547a7 in cordova-plugin-device's branch refs/heads/1.1.x from Alexander Sorokin
          [ https://git-wip-us.apache.org/repos/asf?p=cordova-plugin-device.git;h=4472603 ]

          CB-12105 (browser) Properly detect Edge

          Show
          jira-bot ASF subversion and git services added a comment - Commit 4472603a42859084f1a151ebc3676421d33547a7 in cordova-plugin-device's branch refs/heads/1.1.x from Alexander Sorokin [ https://git-wip-us.apache.org/repos/asf?p=cordova-plugin-device.git;h=4472603 ] CB-12105 (browser) Properly detect Edge

            People

            • Assignee:
              alsorokin Alexander Sorokin
              Reporter:
              markdark81 Mark Veenstra
            • Votes:
              0 Vote for this issue
              Watchers:
              3 Start watching this issue

              Dates

              • Created:
                Updated:
                Resolved:

                Development