0

On a specific website I am unable to detect if the browser is edge (chromium) because on that website I am getting following user agent on edge browser

"Mozilla/5.0 (Windows NT 10.0; Win64; x64) AppleWebKit/537.36 (KHTML, like Gecko) Chrome/91.0.4472.101 Safari/537.36"

There is no "edge" or "edg" keyword to detect if it's edge is there any work around for this issue.

I need to just differentiate between these two browsers only, here is my code for detection.

public isChrome(): boolean {
    return /Chrome/.test(navigator.userAgent) && /Google Inc/.test(navigator.vendor);
}

public isEdge(): boolean {
    return /edg|edge/.test(navigator.userAgent.toLowerCase()) && /Google Inc/.test(navigator.vendor);
}

thanks

Guest360
  • 1
  • 1

1 Answers1

0

I think the userAgent you provided is from Chrome instead of MS Edge. The userAgent of MS Edge should have edg/version at the end. For example:

mozilla/5.0 (windows nt 10.0; win64; x64) applewebkit/537.36 (khtml, like gecko) chrome/91.0.4472.101 safari/537.36 edg/91.0.864.48

For details, you could also refer to this document:How to detect Microsoft Edge in your website. If you want to determine the browser used by the user, you can refer to this case:How to detect Microsoft Chromium Edge (chredge , edgium) in Javascript

Xudong Peng
  • 1,463
  • 1
  • 4
  • 9