如何通过编程方式获取Chrome的Channel与Version信息
获取Chrome版本与Channel的编程实现方案
嘿,我来给你梳理几种靠谱的编程方式,覆盖不同平台和开发场景,帮你拿到Chrome的版本号和Channel(渠道,比如stable、beta、dev)信息:
一、命令行调用(适用于脚本/后端程序)
这是最通用的方案,不管你用Python、Shell、PowerShell还是其他语言,都可以通过执行系统命令并解析输出来获取信息。
Windows平台
- 获取版本号:直接调用Chrome的可执行文件执行版本查询命令:
输出示例:chrome --versionGoogle Chrome 120.0.6099.109 official,提取数字部分就是版本号。 - 获取Channel:Chrome的渠道信息存在系统注册表中,用PowerShell可以直接读取:
返回结果比如# 读取Channel值 (Get-ItemProperty -Path "HKCU:\Software\Google\Chrome\BLBeacon").channelstable、beta或者dev。
macOS平台
- 获取版本号:调用Chrome应用包内的可执行文件:
/Applications/Google\ Chrome.app/Contents/MacOS/Google\ Chrome --version - 获取Channel:读取应用包的配置信息:
直接返回渠道标识,比如defaults read /Applications/Google\ Chrome.app/Contents/Info.plist KSChannelIDstable。
Linux平台
- 获取版本号:根据你安装的Chrome版本执行对应命令:
# Stable版 google-chrome --version # Beta版 google-chrome-beta --version # Dev版 google-chrome-unstable --version - 获取Channel:可以通过查看已安装的包名来判断:
包名里会包含dpkg -l | grep google-chromestable、beta或unstable字样,直接提取即可。
二、Chrome扩展/浏览器内开发场景
如果你是开发Chrome扩展或者Chrome App,直接用官方提供的API就能拿到准确信息:
// 需要在扩展manifest中声明"runtime"权限 chrome.runtime.getBrowserInfo().then(browserInfo => { console.log("Chrome版本:", browserInfo.version); console.log("Channel:", browserInfo.channel); // 返回stable/beta/dev等 });
注意:这个API只能在Chrome扩展/App环境下使用,普通网页无法调用。
三、Node.js/Electron环境
如果你在开发Electron应用,可以直接通过Electron的内置API获取Chrome版本,Channel则可以通过解析User Agent或者判断Electron构建渠道来获取:
const { app } = require('electron'); // 获取Chrome内核版本 const chromeVersion = app.getChromeVersion(); console.log("Chrome版本:", chromeVersion); // 解析Channel const userAgent = app.userAgent; const channelMatch = userAgent.match(/Chrome\/\d+\.\d+\.\d+\.\d+ (\w+)/); if (channelMatch) { console.log("Channel:", channelMatch[1]); }
内容的提问来源于stack exchange,提问作者IT researcher
相关产品推荐
相关产品推荐

