简体   繁体   English

可以在 Chrome 中的 JavaScript 中获取 V8 JavaScript 引擎版本号

[英]Possible to get the V8 JavaScript engine version number in JavaScript in Chrome

I see that the most stable release for V8 is 3.26.9 I'm wondering if it is possible to get this version number in JavaScript directly, or even find the version number that Chrome is using somehow.我看到 V8 最稳定的版本是 3.26.9 我想知道是否可以直接在 JavaScript 中获取此版本号,或者甚至可以找到 Chrome 以某种方式使用的版本号。 Any way to do this?有没有办法做到这一点?

Not directly via Javascript no, but you could map each Chrome version to the V8 engine.不直接通过 Javascript 不,但您可以将每个 Chrome 版本映射到 V8 引擎。

To find the v8 version that Chrome is using, simply look it up using the URI: chrome://version/要查找 Chrome 使用的 v8 版本,只需使用 URI 查找: chrome://version/

You can parse Chrome version from User Agent string您可以从用户代理字符串解析 Chrome 版本

console.log(window.navigator.userAgent);

    "Mozilla/5.0 (Windows NT 6.1; Win64; x64) AppleWebKit/537.36 (KHTML, like Gecko) Chrome/71.0.3578.98 Safari/537.36"

console.log(window.navigator.userAgent.match(/Chrome\/(\d+).\d+.\d+.\d+/)[1]);

    "71"

This means, your v8 version is 7.1, because it always corresponds to a Chrome release number.这意味着,您的 v8 版本是 7.1,因为它始终对应于 Chrome 版本号。

This is not too reliable as one can change its User Agent string either manually or automatically (eg via Chrome extension), but still usable in simple cases.这不太可靠,因为您可以手动或自动(例如通过 Chrome 扩展程序)更改其用户代理字符串,但在简单情况下仍然可用。

This is not possible in Chrome.这在 Chrome 中是不可能的。 For interest though, in the Node.js runtime, you can get this in Javascript under process.versions.v8 - for example, console.log(process.versions.v8 )不过,出于兴趣,在Node.js运行时,您可以在process.versions.v8下的 Javascript 中获取它 - 例如, console.log(process.versions.v8 )

声明:本站的技术帖子网页,遵循CC BY-SA 4.0协议,如果您需要转载,请注明本站网址或者原文地址。任何问题请咨询:yoyou2525@163.com.

 
粤ICP备18138465号  © 2020-2024 STACKOOM.COM