From 36f066fbc0101f7aa9bcdf4bf77550c8cd3a1397 Mon Sep 17 00:00:00 2001 From: Rene Leonhardt <65483435+reneleonhardt@users.noreply.github.com> Date: Sat, 12 Jul 2025 13:08:40 +0200 Subject: [PATCH] feat: add brave-browser --- index.d.ts | 1 + index.js | 14 ++++++++++++++ readme.md | 3 ++- test-it.js | 4 ++++ test.js | 4 ++++ 5 files changed, 25 insertions(+), 1 deletion(-) create mode 100644 test-it.js diff --git a/index.d.ts b/index.d.ts index e62feaf..b754b2a 100644 --- a/index.d.ts +++ b/index.d.ts @@ -64,6 +64,7 @@ export type OpenAppOptions = { export type AppName = | 'chrome' + | 'brave' | 'firefox' | 'edge' | 'browser' diff --git a/index.js b/index.js index c70295d..b9b251a 100644 --- a/index.js +++ b/index.js @@ -46,6 +46,7 @@ async function getWindowsDefaultBrowserFromWsl() { // Map ProgId to browser IDs const browserMap = { ChromeHTML: 'com.google.chrome', + BraveHTML: 'com.brave.Browser', MSEdgeHTM: 'com.microsoft.edge', FirefoxURL: 'org.mozilla.firefox', }; @@ -101,6 +102,7 @@ const baseOpen = async options => { const ids = { 'com.google.chrome': 'chrome', 'google-chrome.desktop': 'chrome', + 'com.brave.Browser': 'brave', 'org.mozilla.firefox': 'firefox', 'firefox.desktop': 'firefox', 'com.microsoft.msedge': 'edge', @@ -112,6 +114,7 @@ const baseOpen = async options => { // Incognito flags for each browser in `apps`. const flags = { chrome: '--incognito', + brave: '--incognito', firefox: '--private-window', edge: '--inPrivate', }; @@ -328,6 +331,17 @@ defineLazyProperty(apps, 'chrome', () => detectPlatformBinary({ }, })); +defineLazyProperty(apps, 'brave', () => detectPlatformBinary({ + darwin: 'brave browser', + win32: 'brave', + linux: ['brave-browser', 'brave'], +}, { + wsl: { + ia32: '/mnt/c/Program Files (x86)/BraveSoftware/Brave-Browser/Application/brave.exe', + x64: ['/mnt/c/Program Files/BraveSoftware/Brave-Browser/Application/brave.exe', '/mnt/c/Program Files (x86)/BraveSoftware/Brave-Browser/Application/brave.exe'], + }, +})); + defineLazyProperty(apps, 'firefox', () => detectPlatformBinary({ darwin: 'firefox', win32: 'C:\\Program Files\\Mozilla Firefox\\firefox.exe', diff --git a/readme.md b/readme.md index 610e3a4..e3bd313 100644 --- a/readme.md +++ b/readme.md @@ -171,10 +171,11 @@ await open('https://google.com', { - [`chrome`](https://www.google.com/chrome) - Web browser - [`firefox`](https://www.mozilla.org/firefox) - Web browser - [`edge`](https://www.microsoft.com/edge) - Web browser +- [`brave`](https://brave.com/) - Web browser - `browser` - Default web browser - `browserPrivate` - Default web browser in incognito mode -`browser` and `browserPrivate` only supports `chrome`, `firefox`, and `edge`. +`browser` and `browserPrivate` only supports `chrome`, `firefox`, `edge`, and `brave`. ## Related diff --git a/test-it.js b/test-it.js new file mode 100644 index 0000000..22ec673 --- /dev/null +++ b/test-it.js @@ -0,0 +1,4 @@ +import open, {apps, openApp} from 'open'; + +await open('https://brave.com', {app: {name: apps.brave}}); +await openApp(apps.brave, {arguments: ['https://brave.com', '--incognito'], newInstance: true}); diff --git a/test.js b/test.js index bedfa8d..c50325e 100644 --- a/test.js +++ b/test.js @@ -78,6 +78,10 @@ test('open Chrome in incognito mode', async t => { await t.notThrowsAsync(openApp(apps.chrome, {arguments: ['--incognito'], newInstance: true})); }); +test('open Brave in incognito mode', async t => { + await t.notThrowsAsync(openApp(apps.brave, {arguments: ['--incognito'], newInstance: true})); +}); + test('open URL with default browser argument', async t => { await t.notThrowsAsync(open('https://sindresorhus.com', {app: {name: apps.browser}})); });