@aw-web-design/x-default-browser

中文文档
1.4.126发布于 2022/08/08MITCommonJS近 30 天下载 293.1万

Detect default web browser of the current user, cross-platform (Win/Lin/Mac)

原始使用文档
文档目录6 节
  1. How it works
  2. Usage as a nodejs module
  3. Usage from command line
  4. Linux support
  5. License
  6. Related projects

x-default-browser

Build Status

Get it on npm

This cross-platform module finds out the default browser for current user.

Tested on Windows 10 64-bit, Windows 7 64-bit, Windows XP 32-bit, Ubuntu 14.04 64-bit (en-US locale), Mac OS X.

It requires nodejs and npm. If you don't have node, grab it at nodejs.org. Node installer bundles npm (node package manager)

How it works

  • Windows:
    • checks registry value HKCU\Software\Clients\StartMenuInternet
  • Linuxes:
    • reads the output of xdg-mime query default x-scheme-handler/http
  • OS X:

Usage as a nodejs module

$ npm install x-default-browser
var defaultBrowser = require('x-default-browser');

defaultBrowser(function (err, res) {

    // in case of error, `err` will be a string with error message; otherwise it's `null`.

    console.dir(res);
    // => {
    //  isIE: false,
    //  isFirefox: true,
    //  isChrome: false,
    //  isChromium: false,
    //  isOpera: false,
    //  isWebkit: false,
    //  identity: 'firefox.exe',
    //  commonName: 'firefox'
    // }
});
  • commonName is portable, it will be ie, safari, firefox, chrome, chromium, opera or unknown
  • isBlink is true for Chrome, Chromium, Opera
  • isWebkit is true for Chrome, Chromium, Opera, Safari
  • identity key is platform-specific.
    • On Windows, it's the prefix you can use for querying HKLM\Software\Clients\StartMenuInternet\<prefix> keys to find out details of the browser. It'll be one of iexplore.exe, firefox.exe, google chrome, chromium.<somerandomkeyhere>, operastable.
    • On Ubuntu, it will be firefox.desktop, google-chrome.desktop, chromium-browser.desktop or opera.desktop
    • On Mac OS X, it will be the bundle ID: com.apple.Safari, com.google.chrome, com.operasoftware.Opera, org.mozilla.firefox etc

Usage from command line

$ npm install -g x-default-browser
$ x-default-browser
firefox

Command line version outputs the commonName key, i.e. ie, safari, firefox, chrome, chromium, opera or unknown.

Linux support

This module was only tested on Ubuntu. Compatibility reports and fixes for other distros are more than welcome! Use GitHub issues or email: (jakub.g.opensource) (gmail)

License

MIT © Jakub Gieryluk

版本与发布记录

@aw-web-design/x-default-browser 共发布 127 个版本,首次发布于 2022/05/06;过去 12 个月发布了 0 个版本。

版本发布日期距今
1.4.126latest2022/08/084 年前
1.4.1252022/08/074 年前
1.4.1242022/08/074 年前
1.4.1232022/08/054 年前
1.4.1222022/08/024 年前
1.4.1212022/08/024 年前

关于 @aw-web-design/x-default-browser 的常见问题

@aw-web-design/x-default-browser 是什么?

Detect default web browser of the current user, cross-platform (Win/Lin/Mac)

如何安装 @aw-web-design/x-default-browser?

在项目目录运行 npm install @aw-web-design/x-default-browser,或使用 pnpm add / yarn add / bun add。它还提供命令行工具 x-default-browser,可以用 npx x-default-browser 直接运行。

@aw-web-design/x-default-browser 支持 TypeScript 吗?

该包的 package.json 没有声明类型入口。需要类型提示时,可以在 npm 上查找社区维护的 @types/aw-web-design__x-default-browser 是否存在。

@aw-web-design/x-default-browser 支持 ESM 还是 CommonJS?

以 CommonJS 形式发布,可以直接 require();在 ES Module 项目中也可以用 import 引入(Node.js 会把 module.exports 作为默认导出)。

@aw-web-design/x-default-browser 可以商用吗?

@aw-web-design/x-default-browser 使用 MIT 许可。宽松许可:允许商业使用、修改和再分发,通常只需在分发时保留原版权与许可声明。以上为概括,不构成法律意见,请以许可原文为准。

@aw-web-design/x-default-browser 的下载量有多少?

根据 npm 官方下载统计,@aw-web-design/x-default-browser 在 2026/10/07 – 2026/11/05 这 30 天内被下载 2,930,807 次,日均约 97,694 次。下载量会把 CI 构建、镜像同步和作为其他包依赖的安装一并计入,适合横向比较热度,不能直接等同于使用人数。

@aw-web-design/x-default-browser 还在维护吗?

最新版本 1.4.126 发布于 2022/08/08(4 年前);至今共发布 127 个版本,其中过去 12 个月发布了 0 个;首次发布于 2022/05/06。发布频率只是参考信号:功能稳定的工具可能很少需要更新,建议结合源码仓库的 issue 和提交记录判断。