Do you prefer to do all your development work in Chrome but still want to have Safari as your default browser? Sick of having iTerm automatically open all links in Safari instead of Chrome, and then having to copy said link and paste it into Chrome yourself? That takes up so many valuable seconds!
Inspite of all my best research, I wasn’t able to find a way to configure this in iTerm’s preferences. Sure, there’s the Context Menu Items for Smart Selection Rule that’s mentioned in this Stack Overflow answer, but I wasn’t able to get that to do anything. Like, at all. But maybe I’m just stupid.
Lacking an official approach, I did stumble across this hack: Add BROWSER=chrome
to your .env
file. Going forward, whenever you npm start
, it should open with Chrome (even if Safari, or whatever other app, is your default browser).
A few caveats:
- You have to do this individually with every repo going forward. But, on the plus side, once you do it initially with that repo, you should never need to worry about it opening in Chrome.
- React apps come with a lot of Node modules pre-installed. ENV is not one of them. You’ll need to
npm i dotenv
after younpx create-react-app
. Then, of course,touch .env
once you’re in the repo’s main folder, so the file will be created at the top level. Interestingly, after merely creating the file and storing the above string in it, you don’t need to do anything else. As in, you don’t need torequire('dotenv').config()
in yourindex.js
file or anywhere else (which I had to do with my other Node projects). If these additional steps sound unappealing, you could also just run this one, slightly longer line every time you plan to do annpm start
: just typeBROWSER=chrome npm start
, which achieves the same effect as the above configuration. - This approach wouldn’t work with any non-Node projects (React is Node compliant). So this wouldn’t work for any of vanilla JavaScript repos. Or anything in any other programming language. However, there may be some
.env
analog in those situations. Plus, if you’re opening a file from the terminal, you can always typeopen -a chrome index.html
instead ofopen index.html
(or whatever file) in order to make it open in Chrome. Not as simple, but it works. - Every OS handles this a little differently. Windows uses
chrome
, Linux usesgoogle-chrome
, and Mac usesgoogle chrome
. So depending on your computer, you may need to type something different afterBROWSER=
in your.env
file. (I have a Mac, butchrome
works for me; however, I think that’s because I renamed the Chrome app in myApplications
folder fromGoogle Chrome
to justChrome
forever ago. TLDR: Try them out until you get a fit, check what your Chrome app is specifically named in yourApplications
folder if none of those are working, and try wrapping it in quotes if you need to use the two wordsgoogle chrome
.)
h/t to the Stack Overflow answer that finally led me to this approach
Top comments (0)