问题
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