browser.ts 1.2 KB

12345678910111213141516171819202122232425262728293031323334
  1. /**
  2. * Check to see if browser is not supported by Grafana
  3. * This function is copied to index-template.html but is here so we can write tests
  4. * */
  5. export function checkBrowserCompatibility() {
  6. const isIE = navigator.userAgent.indexOf('MSIE') > -1;
  7. const isEdge = navigator.userAgent.indexOf('Edge/') > -1 || navigator.userAgent.indexOf('Edg/') > -1;
  8. const isFirefox = navigator.userAgent.toLowerCase().indexOf('firefox') > -1;
  9. const isChrome = /Chrome/.test(navigator.userAgent) && /Google Inc/.test(navigator.vendor);
  10. /* Check for
  11. <= IE11 (Trident 7)
  12. Edge <= 16
  13. Firefox <= 64
  14. Chrome <= 54
  15. */
  16. const isEdgeVersion = /Edge\/([0-9.]+)/.exec(navigator.userAgent);
  17. if (isIE && parseFloat(/Trident\/([0-9.]+)/.exec(navigator.userAgent)![1]) <= 7) {
  18. return false;
  19. } else if (
  20. isEdge &&
  21. ((isEdgeVersion && parseFloat(isEdgeVersion[1]) <= 16) ||
  22. parseFloat(/Edg\/([0-9.]+)/.exec(navigator.userAgent)![1]) <= 16)
  23. ) {
  24. return false;
  25. } else if (isFirefox && parseFloat(/Firefox\/([0-9.]+)/.exec(navigator.userAgent)![1]) <= 64) {
  26. return false;
  27. } else if (isChrome && parseFloat(/Chrome\/([0-9.]+)/.exec(navigator.userAgent)![1]) <= 54) {
  28. return false;
  29. }
  30. return true;
  31. }