-
-
Notifications
You must be signed in to change notification settings - Fork 239
New issue
Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.
By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.
Already on GitHub? Sign in to your account
Implemented browser and browserPrivate #294
Changes from 1 commit
8b11819
7253ffc
5376f3d
cc68d5a
5828be0
4cf1a6d
5c6582a
53bb565
051edca
13a800c
27e4e3a
51fae87
cbc008b
b3212fb
aa21cad
f7b4c6d
238770d
009b28e
69b4bb5
e368f9b
1af76c2
a4867a4
b185554
6d9d524
File filter
Filter by extension
Conversations
Jump to
Diff view
Diff view
- Loading branch information
There are no files selected for viewing
Original file line number | Diff line number | Diff line change |
---|---|---|
|
@@ -120,20 +120,8 @@ const baseOpen = async options => { | |
})); | ||
} | ||
|
||
if (app === 'browser') { | ||
const browser = await defaultBrowser(); | ||
const browserName = browser.name.toLowerCase(); | ||
return baseOpen({ | ||
...options, | ||
app: { | ||
name: open.apps[browserName], | ||
arguments: appArguments | ||
} | ||
}); | ||
} | ||
|
||
if (app === 'browserPrivate') { | ||
// Incognito or equivalent flags for each of the browser in open.apps | ||
if (app === 'browser' || app === 'browserPrivate') { | ||
// Incognito or equivalent flags for each browser in open.apps | ||
const flags = { | ||
chrome: '--incognito', | ||
firefox: '--private-window', | ||
|
@@ -142,13 +130,25 @@ const baseOpen = async options => { | |
|
||
const browser = await defaultBrowser(); | ||
const browserName = browser.name.toLowerCase(); | ||
return baseOpen({ | ||
...options, | ||
app: { | ||
name: open.apps[browserName], | ||
arguments: [...appArguments, flags[browserName]] | ||
|
||
const supportedBrowsers = Object.keys(flags); | ||
for (const supportedBrowser of supportedBrowsers) { | ||
if (browserName.includes(supportedBrowser)) { | ||
if (app === 'browserPrivate') { | ||
appArguments.push(flags[supportedBrowser]); | ||
} | ||
|
||
return baseOpen({ | ||
...options, | ||
app: { | ||
name: open.apps[supportedBrowser], | ||
arguments: appArguments | ||
} | ||
}); | ||
} | ||
}); | ||
} | ||
|
||
throw new Error(`${browserName} as the default browser is not supported`); | ||
} | ||
|
||
let command; | ||
|
@@ -369,4 +369,5 @@ defineLazyProperty(apps, 'browserPrivate', () => 'browserPrivate'); | |
open.apps = apps; | ||
open.openApp = openApp; | ||
There was a problem hiding this comment. Choose a reason for hiding this commentThe reason will be displayed to describe this comment to others. Learn more. These should be named exports. There was a problem hiding this comment. Choose a reason for hiding this commentThe reason will be displayed to describe this comment to others. Learn more. You mean something like this? export {apps};
export default open; There was a problem hiding this comment. Choose a reason for hiding this commentThe reason will be displayed to describe this comment to others. Learn more. Yes |
||
|
||
export {open}; | ||
export {apps}; | ||
export default open; |
Original file line number | Diff line number | Diff line change |
---|---|---|
|
@@ -26,7 +26,7 @@ npm install open | |
## Usage | ||
|
||
```js | ||
import {open} from 'open'; | ||
import open from 'open'; | ||
|
||
// Opens the image in the default image viewer and waits for the opened app to quit. | ||
await open('unicorn.png', {wait: true}); | ||
|
@@ -124,7 +124,7 @@ We do not recommend setting this option. The convention for success is exit code | |
An object containing auto-detected binary names for common apps. Useful to work around [cross-platform differences](#app). | ||
|
||
```js | ||
import {open} from 'open'; | ||
import open from 'open'; | ||
|
||
await open('https://google.com', { | ||
app: { | ||
|
@@ -142,6 +142,8 @@ await open('https://google.com', { | |
- `browser` - Default web browser | ||
- `browserPrivate` - Default web browser in incognito mode | ||
There was a problem hiding this comment. Choose a reason for hiding this commentThe reason will be displayed to describe this comment to others. Learn more. This needs to document which browsers it supports. |
||
|
||
`browser` and `browserPrivate` currently support `chrome`, `firefox` and `edge`. | ||
|
||
### open.openApp(name, options?) | ||
|
||
Open an app. | ||
|
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
I'm not too sure how to normalise the names, but is this good enough? It just checks if the
browserName
string contains"chrome"
,"firefox"
or"edge"
since these are the only browsers supported right now.There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
That is not going to work. What if the default browser is
Chrome Canary
?There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
Sorry for the lack of replies. I don't know what to do besides converting to lowercase and stripping whitespace. Do you have any advice for normalisation?
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
A list of browsers with their mapping on the different operating systems. We only support 3 browsers for this, so should not be hard to make a list like that.
For example,
.chrome
isGoogle Chrome
on macOS,google-chrome
on Linux.