How to get the current version of Chrome from an extension?

China☆狼群 提交于 2020-01-23 17:13:31

问题


I'm making a user-agent switcher for Chrome using the experimental API WebRequest, and I'd like to display the current user-agent used.

For that, I have to get the current version of Chrome, but I don't find anything about that in the doc and I can't access to the "chrome://version" page due to security considerations.

Do you have an idea to help me?


回答1:


How about

window.navigator.userAgent

on your backgroundpage?




回答2:


You can always use the good old navigator object (navigator.userAgent is the exact property, but it contains many other informations), it's available to extensions.




回答3:


try

function getChromeVersion(){
  var match = window.navigator.userAgent.match(/Chrom(?:e|ium)\/([0-9\.]+)/);
  return match ? match[1] : null;
}

or use https://github.com/DamonOehlman/detect-browser for Multi-Browser Support.



来源:https://stackoverflow.com/questions/8275200/how-to-get-the-current-version-of-chrome-from-an-extension

易学教程内所有资源均来自网络或用户发布的内容,如有违反法律规定的内容欢迎反馈
该文章没有解决你所遇到的问题?点击提问,说说你的问题,让更多的人一起探讨吧!