JavaScript Snippet – Get Chrome’s Version Using JavaScript

(function(match){                         /* just as string. ie. "57.0.2947.0"*/
  match = null === match ? "" : match[1];
  return match;
}(
  (self.navigator.appVersion + self.navigator.userAgent).match(/Chrome\/([\d\.]+)\ /i)
));

A trick: Since the version exist both in navigator.appVersion and navigator.userAgent, combining them to one string, and applying a little regular-expression match, using regex-backtrack, has a better chance of “finding something” :]


This one also breaks the Semantic Versioning and convert each value to a number, which may come-in handy for any type of numeric-comparison.

(function(match){                         /* as array of numbers (by the order of reading, left to right). ie. [57, 0, 2947, 0]*/
  match = null === match ? "0.0.0.0" : match[1];
  match = match.split(".").reduce(function(carry_result, item){ return [].concat(carry_result,Number(item)); }, []);
  return match;
}(
  (self.navigator.appVersion + self.navigator.userAgent).match(/Chrome\/([\d\.]+)\ /i)
));