How to detect the installed Chrome version?

前端 未结 2 808
礼貌的吻别
礼貌的吻别 2020-12-01 05:19

I\'m developing a Chrome extension and I\'m wondering is there a way that I can detect which version of Chrome the user is using?

2条回答
  •  [愿得一人]
    2020-12-01 05:44

    Here is a version, based on the answer from @serg, that extracts all of the elements of the version number:

    function getChromeVersion () {
        var pieces = navigator.userAgent.match(/Chrom(?:e|ium)\/([0-9]+)\.([0-9]+)\.([0-9]+)\.([0-9]+)/);
        if (pieces == null || pieces.length != 5) {
            return undefined;
        }
        pieces = pieces.map(piece => parseInt(piece, 10));
        return {
            major: pieces[1],
            minor: pieces[2],
            build: pieces[3],
            patch: pieces[4]
        };
    }
    

    The naming of the elements in the object that is returned is based on this convention, though you can of course adapt it to be based on this instead.

提交回复
热议问题