Huge News!Announcing our $40M Series B led by Abstract Ventures.Learn More
Socket
Sign inDemoInstall
Socket

default-browser-id

Package Overview
Dependencies
Maintainers
1
Versions
12
Alerts
File Explorer

Advanced tools

Socket logo

Install Socket

Detect and block malicious and high-risk dependencies

Install

default-browser-id - npm Package Compare versions

Comparing version 4.0.0 to 5.0.0

37

index.js

@@ -0,9 +1,6 @@

import {promisify} from 'node:util';
import process from 'node:process';
import os from 'node:os';
import fs from 'node:fs/promises';
import bplist from 'bplist-parser';
import untildify from 'untildify';
import {execFile} from 'node:child_process';
const macOsVersion = Number(os.release().split('.')[0]);
const filePath = untildify(macOsVersion >= 14 ? '~/Library/Preferences/com.apple.LaunchServices/com.apple.launchservices.secure.plist' : '~/Library/Preferences/com.apple.LaunchServices.plist');
const execFileAsync = promisify(execFile);

@@ -15,28 +12,8 @@ export default async function defaultBrowserId() {

const defaultBundleId = 'com.apple.Safari';
const {stdout} = await execFileAsync('defaults', ['read', 'com.apple.LaunchServices/com.apple.launchservices.secure', 'LSHandlers']);
let buffer;
try {
buffer = await fs.readFile(filePath);
} catch (error) {
if (error.code === 'ENOENT') {
return defaultBundleId;
}
// `(?!-)` is to prevent matching `LSHandlerRoleAll = "-";`.
const match = /LSHandlerRoleAll = "(?!-)(?<id>[^"]+?)";\s+?LSHandlerURLScheme = (?:http|https);/.exec(stdout);
throw error;
}
const handlers = bplist.parseBuffer(buffer)?.[0]?.LSHandlers;
if (!handlers || handlers.length === 0) {
return defaultBundleId;
}
for (const handler of handlers) {
if (handler.LSHandlerURLScheme === 'http' && handler.LSHandlerRoleAll) {
return handler.LSHandlerRoleAll;
}
}
return defaultBundleId;
return match?.groups.id ?? 'com.apple.Safari';
}

9

package.json
{
"name": "default-browser-id",
"version": "4.0.0",
"version": "5.0.0",
"description": "Get the bundle identifier of the default browser (macOS). Example: com.apple.Safari",

@@ -15,2 +15,3 @@ "license": "MIT",

"exports": "./index.js",
"sideEffects": false,
"engines": {

@@ -37,10 +38,6 @@ "node": ">=18"

],
"dependencies": {
"bplist-parser": "^0.3.2",
"untildify": "^5.0.0"
},
"devDependencies": {
"ava": "^5.3.1",
"ava": "^6.0.1",
"xo": "^0.56.0"
}
}
SocketSocket SOC 2 Logo

Product

  • Package Alerts
  • Integrations
  • Docs
  • Pricing
  • FAQ
  • Roadmap
  • Changelog

Packages

npm

Stay in touch

Get open source security insights delivered straight into your inbox.


  • Terms
  • Privacy
  • Security

Made with ⚡️ by Socket Inc