Ever wanted to check which browser (and browser version) your VSTS/TFS extension is running on? Microsoft Visual Studio Team Services Web Extension SDK has a great set of utility methods. In this blog post we will see couple of such methods which will help us to detect browser type and its version.

Image

Steps

Like in previous post we need to import the module in to our typescript file. The methods we are interested are all in UI module.

import BrowserCheck = require("VSS/Utils/UI");

The imported UI module provides various methods to check the browser and its properties.

Check for Google Chrome

let chrome = BrowserCheck.BrowserCheckUtils.isChrome();

Check for Edge browser

let edge = BrowserCheck.BrowserCheckUtils.isEdge();

Check for Firefox, Safari and IE

Similar to the methods above, you can check other browser types too.

let firefox = BrowserCheck.BrowserCheckUtils.isFirefox();
let safari = BrowserCheck.BrowserCheckUtils.isSafari();
let ie = BrowserCheck.BrowserCheckUtils.isIE();

Check for browser version

You can get the browser version like below.

let version = BrowserCheck.BrowserCheckUtils.getVersion();

Check for specific IE version

If you are looking to check specific version of IE, there is method for it too.

let isIE11 = BrowserCheck.BrowserCheckUtils.isIEVersion(11);

Check if browser version is less than v8 or v9

Now if you would like to check if extension is running on lower version than IE8 or IE9, the SDK has methods to check exactly that.

let lessThanIE8 = BrowserCheck.BrowserCheckUtils.isLessThanOrEqualToIE8();
let lessThanIE9 = BrowserCheck.BrowserCheckUtils.isLessThanOrEqualToIE9();

Can I detect if my extension is running on Windows/Macintosh/iOS?

Yes, you can!

let isWindows = BrowserCheck.BrowserCheckUtils.isWindows();
let isMac = BrowserCheck.BrowserCheckUtils.isMacintosh();
let isiOS = BrowserCheck.BrowserCheckUtils.isIOS();

That’s it for this post. Thanks for reading!


About author
Utkarsh Shigihalli
Utkarsh Shigihalli
Utkarsh is passionate about software development and has experience in the areas of Azure, Azure DevOps, C# and TypeScript. Over the years he has worked as an architect, independent consultant and manager in many countries including India, United States, Netherlands and United Kingdom. He is a Microsoft MVP and has developed numerous extensions for Visual Studio, Visual Studio Code and Azure DevOps.
We Are
  • onlyutkarsh
    Utkarsh Shigihalli
    Microsoft MVP, Technologist & DevOps Coach


  • arora_tarun
    Tarun Arora
    Microsoft MVP, Author & DevOps Coach at Avanade

Do you like our posts? Subscribe to our newsletter!
Our Book