11

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?

2
  • What is your system's default browser? Commented Aug 25, 2018 at 4:51
  • Chrome, windows 10 Commented Aug 25, 2018 at 11:41

4 Answers 4

18

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

Sign up to request clarification or add additional context in comments.

6 Comments

Is it possible to open Firefox in a given profile? Looking for an equivalent to /Applications/Firefox.app/Contents/MacOS/firefox-bin -p development.
Found a way using the script option. See github.com/facebook/create-react-app/issues/1533
But what about exactly Chrome Canary? Did anybody try?
For Google Chrome, use "BROWSER='Google Chrome' react-scripts start"
With react-scripts 5.x this no longer seems to work.
|
8

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

5

You can use .env file with BROWSER=firefox

https://create-react-app.dev/docs/advanced-configuration/

Comments

0

This worked for me:

  1. 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

  1. Set variable BROWSER=Chrome in .env file in root directory

Comments

Your Answer

By clicking “Post Your Answer”, you agree to our terms of service and acknowledge you have read our privacy policy.

Start asking to get answers

Find the answer to your question by asking.

Ask question

Explore related questions

See similar questions with these tags.