Socket
Socket
Sign inDemoInstall

default-browser-id

Package Overview
Dependencies
2
Maintainers
1
Versions
12
Alerts
File Explorer

Advanced tools

Install Socket

Detect and block malicious and high-risk dependencies

Install

Comparing version 2.0.0 to 3.0.0

52

index.js

@@ -1,12 +0,12 @@

'use strict';
const os = require('os');
const bplist = require('bplist-parser');
const untildify = require('untildify');
const pify = require('pify');
const osxVersion = Number(os.release().split('.')[0]);
const file = untildify(osxVersion >= 14 ? '~/Library/Preferences/com.apple.LaunchServices/com.apple.launchservices.secure.plist' : '~/Library/Preferences/com.apple.LaunchServices.plist');
import os from 'os';
import {promises as fs} from 'fs';
import bplist from 'bplist-parser';
import untildify from 'untildify';
module.exports = () => {
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');
export default async function defaultBrowserId() {
if (process.platform !== 'darwin') {
return Promise.reject(new Error('Only OS X is supported'));
throw new Error('macOS only');
}

@@ -16,18 +16,28 @@

return pify(bplist.parseFile)(file).then(data => {
const handlers = data && data[0].LSHandlers;
if (!handlers || handlers.length === 0) {
let buffer;
try {
buffer = await fs.readFile(filePath);
} catch (error) {
if (error.code === 'ENOENT') {
return bundleId;
}
for (const el of handlers) {
if (el.LSHandlerURLScheme === 'http' && el.LSHandlerRoleAll) {
bundleId = el.LSHandlerRoleAll;
break;
}
throw error;
}
const data = bplist.parseBuffer(buffer);
const handlers = data && data[0].LSHandlers;
if (!handlers || handlers.length === 0) {
return bundleId;
}
for (const handler of handlers) {
if (handler.LSHandlerURLScheme === 'http' && handler.LSHandlerRoleAll) {
bundleId = handler.LSHandlerRoleAll;
break;
}
}
return bundleId;
});
};
return bundleId;
}
{
"name": "default-browser-id",
"version": "2.0.0",
"description": "Get the bundle identifier of the default browser (OS X). Example: com.apple.Safari",
"license": "MIT",
"repository": "sindresorhus/default-browser-id",
"author": {
"name": "Sindre Sorhus",
"email": "sindresorhus@gmail.com",
"url": "sindresorhus.com"
},
"engines": {
"node": ">=4"
},
"scripts": {
"test": "xo && ava"
},
"files": [
"index.js"
],
"keywords": [
"osx",
"browser",
"default",
"plist",
"web",
"bundle",
"bundleid",
"id",
"identifier",
"uti"
],
"dependencies": {
"bplist-parser": "^0.1.0",
"pify": "^2.3.0",
"untildify": "^2.0.0"
},
"devDependencies": {
"ava": "*",
"xo": "*"
},
"xo": {
"esnext": true
}
"name": "default-browser-id",
"version": "3.0.0",
"description": "Get the bundle identifier of the default browser (macOS). Example: com.apple.Safari",
"license": "MIT",
"repository": "sindresorhus/default-browser-id",
"funding": "https://github.com/sponsors/sindresorhus",
"author": {
"name": "Sindre Sorhus",
"email": "sindresorhus@gmail.com",
"url": "https://sindresorhus.com"
},
"type": "module",
"exports": "./index.js",
"engines": {
"node": ">=12"
},
"scripts": {
"test": "xo && ava"
},
"files": [
"index.js"
],
"keywords": [
"macos",
"browser",
"default",
"plist",
"web",
"bundle",
"bundleid",
"id",
"identifier",
"uti"
],
"dependencies": {
"bplist-parser": "^0.2.0",
"untildify": "^4.0.0"
},
"devDependencies": {
"ava": "^3.15.0",
"xo": "^0.38.2"
}
}

@@ -1,28 +0,19 @@

# default-browser-id [![Build Status](https://travis-ci.org/sindresorhus/default-browser-id.svg?branch=master)](https://travis-ci.org/sindresorhus/default-browser-id)
# default-browser-id
> Get the [bundle identifier](https://developer.apple.com/library/Mac/documentation/General/Reference/InfoPlistKeyReference/Articles/CoreFoundationKeys.html#//apple_ref/doc/plist/info/CFBundleIdentifier) of the default browser (OS X)<br>
> Get the [bundle identifier](https://developer.apple.com/library/Mac/documentation/General/Reference/InfoPlistKeyReference/Articles/CoreFoundationKeys.html#//apple_ref/doc/plist/info/CFBundleIdentifier) of the default browser *(macOS)*\
> Example: `com.apple.Safari`
## Install
```
$ npm install --save default-browser-id
$ npm install default-browser-id
```
## Usage
```js
const defaultBrowserId = require('default-browser-id');
import defaultBrowserId from 'default-browser-id';
defaultBrowserId().then(browserId => {
console.log(browserId);
//=> 'com.apple.Safari'
});
console.log(await defaultBrowserId());
//=> 'com.apple.Safari'
```
## License
MIT © [Sindre Sorhus](https://sindresorhus.com)

Sorry, the diff of this file is not supported yet

SocketSocket SOC 2 Logo

Product

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

Packages

Stay in touch

Get open source security insights delivered straight into your inbox.


  • Terms
  • Privacy
  • Security

Made with ⚡️ by Socket Inc