openBrowser always attempts to open Chrome on macOS, even when Firefox is set as the default browser.
It does check the BROWSER env var, but given that this isn't set by default when setting a default browser, it's not authoritative. Instead, openBrowser assumes that if Chrome is open, it's fine to use. For developers who have multiple browsers open, this is not the case, and the behaviour is confusing.
Instead, it would be great if the preferences could be checked first, perhaps using default-browser?
Instead, it would be great if the preferences could be checked first, perhaps using default-browser?
Sounds good, would you like to send a fix? I didn鈥檛 know it was possible when I wrote that code.
If I was to give my 2垄 I would prefer to either control this behaviour or disable it. Seems like a feature that's added because it could be, not because it should be.
@rmccue would you like to send a PR fixing this? 馃槃
Discussed this with @gaearon over twitter recently.
Because Chrome won't reuse the latest window without the included AppleScript perhaps we can check for the default browser and if it is Chrome run the AppleScript as appropriate to prevent Chrome from opening a new window. Otherwise we open the default browser.
Using something like default-browser we could change the code to look a bit like this.
defaultBrowser().then(browser => {
if (browser.id === 'com.google.Chrome') {
shouldTryOpenChromeWithAppleScript...
} else {
opn(url, { app: browser }).catch(() => {});
}
});
would this be a good first task for a newcomer to the project?
I attempted a start in #2869 but I don鈥檛 have the time to finish that up right now. Someone can take that over or start new.
Thanks @clarkbw I'll take over. If anyone else wants to join me on the task. Let me know.
@clarkbw @GregBorrelly
Any progress on the issue.
@sirjmkitavi working on a fix. If you would like to join me on fixing the issue let me know.
@GregBorrelly I wouldn't mind helping out where I can.
Can we just turn off the open-in-browser automatically functionality? It doesn't seem to add much value, and causes these annoyances. In my setup, npm run start opens my app in Firefox, while I actually use Chromium mainly for development. I'd be happy to submit a PR for this.
@nikolas2 You can specify which browser you want to launch by adding this configuration to .env.local file
BROWSER='Firefox'
@nhducit solution just worked for me. Still wish you could turn it off with something like yarn start --nope (don't have time at the moment for a PR, but might be freer in a week or two)
@mjsarfatti You can achieve what you want with a little hack by edit the .env.local file
BROWSER='BlahBlah'
Most helpful comment
Can we just turn off the open-in-browser automatically functionality? It doesn't seem to add much value, and causes these annoyances. In my setup,
npm run startopens my app in Firefox, while I actually use Chromium mainly for development. I'd be happy to submit a PR for this.