### Install x-default-browser Globally Source: https://github.com/jakub-g/x-default-browser/blob/main/README.md Install the module globally to use its command-line interface. ```sh $ npm install -g x-default-browser ``` -------------------------------- ### Install x-default-browser Source: https://github.com/jakub-g/x-default-browser/blob/main/README.md Install the module using npm for use in your Node.js project. ```sh $ npm install x-default-browser ``` -------------------------------- ### Get Default Browser Name (CLI) Source: https://github.com/jakub-g/x-default-browser/blob/main/README.md Execute the installed module from the command line to get the common name of the default browser. ```sh $ x-default-browser firefox ``` -------------------------------- ### Use CLI for browser detection Source: https://context7.com/jakub-g/x-default-browser/llms.txt Commands for installing the package globally and using it within shell scripts to identify the default browser. ```bash # Install globally npm install -g x-default-browser # Get default browser name x-default-browser # Output: firefox # Use in shell scripts DEFAULT_BROWSER=$(x-default-browser) echo "Default browser is: $DEFAULT_BROWSER" # Conditional logic based on browser if [ "$(x-default-browser)" = "chrome" ]; then echo "Chrome is the default browser" fi # Handle errors (exits with code 1 on error) x-default-browser || echo "Failed to detect default browser" ``` -------------------------------- ### Get Platform-Specific Browser Identity Source: https://context7.com/jakub-g/x-default-browser/llms.txt Retrieves the platform-specific identity of the default browser. This is useful for advanced OS-level integrations. Examples include registry keys on Windows, .desktop file names on Linux, and bundle identifiers on macOS. ```javascript var defaultBrowser = require("x-default-browser"); defaultBrowser(function (err, res) { if (err) { console.error(err); return; } console.log("Platform-specific identity:", res.identity); // Windows identity examples: // - 'iexplore.exe' (Internet Explorer) // - 'firefox.exe' (Firefox) // - 'google chrome' (Chrome) // - 'chromium.' (Chromium) // - 'operastable' (Opera) // - 'msedgehtm' (Edge on Windows 10/11) // Linux identity examples (Ubuntu): // - 'firefox.desktop' // - 'google-chrome.desktop' // - 'chromium-browser.desktop' // - 'opera.desktop' // macOS identity examples (bundle IDs): // - 'com.apple.Safari' // - 'com.google.chrome' // - 'org.mozilla.firefox' // - 'com.operasoftware.Opera' // Use identity for platform-specific operations var os = require("os"); if (os.platform() === "darwin" && res.identity === "com.google.chrome") { console.log("Can use macOS-specific Chrome automation"); } }); ``` -------------------------------- ### Get Default Browser Info (Node.js) Source: https://github.com/jakub-g/x-default-browser/blob/main/README.md Use the module in your Node.js application to asynchronously retrieve information about the default browser. The callback receives an error object or the browser details. ```js 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' // } }); ``` -------------------------------- ### Get Portable Common Browser Name Source: https://context7.com/jakub-g/x-default-browser/llms.txt Retrieves a standardized, cross-platform name for the default browser. Use this for portable detection logic. The common name is one of: 'edge', 'ie', 'firefox', 'chrome', 'chromium', 'opera', 'safari', 'unknown'. ```javascript var defaultBrowser = require("x-default-browser"); defaultBrowser(function (err, res) { if (err) { console.error(err); return; } // commonName is one of: 'edge', 'ie', 'firefox', 'chrome', 'chromium', 'opera', 'safari', 'unknown' console.log("Common name:", res.commonName); switch (res.commonName) { case "chrome": case "chromium": console.log("Launching with Chrome DevTools Protocol support"); break; case "firefox": console.log("Launching with Firefox Remote Protocol support"); break; case "safari": console.log("Launching with Safari Web Driver support"); break; case "edge": console.log("Launching with Edge DevTools Protocol support"); break; case "ie": console.log("Warning: Internet Explorer has limited modern web support"); break; case "unknown": console.log("Unknown browser - using generic launch method"); break; } }); ``` -------------------------------- ### Implement conditional logic with boolean flags Source: https://context7.com/jakub-g/x-default-browser/llms.txt Demonstrates using individual browser flags and engine-based flags for conditional application logic. ```javascript var defaultBrowser = require("x-default-browser"); defaultBrowser(function (err, res) { if (err) { console.error(err); return; } // Individual browser checks if (res.isChrome) { console.log("Google Chrome detected"); } else if (res.isFirefox) { console.log("Mozilla Firefox detected"); } else if (res.isSafari) { console.log("Apple Safari detected"); } else if (res.isEdge) { console.log("Microsoft Edge detected"); } else if (res.isIE) { console.log("Internet Explorer detected"); } else if (res.isOpera) { console.log("Opera detected"); } else if (res.isChromium) { console.log("Chromium detected"); } // Engine-based feature detection if (res.isBlink) { // Chrome, Chromium, and Opera use Blink engine console.log("Blink engine - supports modern CSS Grid, Web Components"); } if (res.isWebkit) { // Safari, Chrome, Chromium, and Opera are WebKit-based console.log("WebKit-based - -webkit- prefixed CSS may be needed"); } }); ``` -------------------------------- ### Detect default browser with Node.js Source: https://context7.com/jakub-g/x-default-browser/llms.txt Uses the defaultBrowser function to retrieve an object containing browser identity and engine flags. ```javascript var defaultBrowser = require("x-default-browser"); defaultBrowser(function (err, res) { if (err) { console.error("Error detecting browser:", err); return; } console.log("Browser detection result:", res); // => { // isEdge: false, // isIE: false, // isFirefox: true, // isChrome: false, // isChromium: false, // isOpera: false, // isSafari: false, // isBlink: false, // isWebkit: false, // identity: 'firefox.desktop', // commonName: 'firefox' // } // Use commonName for portable browser identification if (res.commonName === "chrome" || res.commonName === "chromium") { console.log("Chrome-based browser detected"); } // Use engine flags for feature detection if (res.isWebkit) { console.log("WebKit-based browser (Chrome, Chromium, Opera, Safari)"); } if (res.isBlink) { console.log("Blink engine browser (Chrome, Chromium, Opera)"); } }); ``` === COMPLETE CONTENT === This response contains all available snippets from this library. No additional content exists. Do not make further requests.