简体   繁体   中英

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. Any way to do this?

Not directly via Javascript no, but you could map each Chrome version to the V8 engine.

To find the v8 version that Chrome is using, simply look it up using the URI: chrome://version/

You can parse Chrome version from User Agent string

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.

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.

This is not possible in 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 )

The technical post webpages of this site follow the CC BY-SA 4.0 protocol. If you need to reprint, please indicate the site URL or the original address.Any question please contact:yoyou2525@163.com.

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