Is it possible to launch create-react-app App in a certain browser of my choice? Currently, it always runs in the Chrome while I want it to do that in the Chrome Canary. Does anybody know?
-
What is your system's default browser?jmargolisvt– jmargolisvt2018-08-25 04:51:17 +00:00Commented Aug 25, 2018 at 4:51
-
Chrome, windows 10srgg6701– srgg67012018-08-25 11:41:20 +00:00Commented Aug 25, 2018 at 11:41
4 Answers
You can use BROWSER environment variable to set which browser you wanna open the app in. For example,
BROWSER=firefox yarn start
or
BROWSER=firefox npm start
will open the app in firefox.
So, you can put something like this in your package.json
"scripts": {
"start": "BROWSER=firefox react-scripts start",
"build": "react-scripts build && sw-precache --config=sw-precache-config.js",
"test": "react-scripts test --env=jsdom",
You can read more about it in this pull request thread
6 Comments
/Applications/Firefox.app/Contents/MacOS/firefox-bin -p development."BROWSER='Google Chrome' react-scripts start"With current iterations of create-react-app this can be accomplished by adding a .env file to the project with a "BROWSER" key. It's described in the Advanced Configuration section of the documentation.
If you want to use Google Chrome Canary for your development browser (as I do) then you'll need to create that .env file in the root of the project with the following contents:
# Override default browser for npm start in react-script
BROWSER=Google Chrome Canary
Be sure you don't get overzealous and quote it or add a semi-colon at the end. I did both and scratched my head at first why it didn't work.
Comments
You can use .env file with BROWSER=firefox
Comments
This worked for me:
Set Chrome Canary as default browser in PowerShell (choose the right path first)
$chromePath = "${Env:ProgramFiles(x86)}\Google\Chrome\Application\" $chromeApp = "chrome.exe" $chromeCommandArgs = "--make-default-browser" & "$chromePath$chromeApp" $chromeCommandArgs
(answer from) https://stackoverflow.com/a/17536704/11878186
- Set variable
BROWSER=Chromein.envfile in root directory