srgg6701
srgg6701

Reputation: 2048

Run create-react-app in a certain browser

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?

Upvotes: 11

Views: 12403

Answers (4)

You can use .env file with BROWSER=firefox

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

Upvotes: 5

Pietro DT
Pietro DT

Reputation: 1

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

Upvotes: 0

Mark Edington
Mark Edington

Reputation: 6732

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.

Upvotes: 8

sudo bangbang
sudo bangbang

Reputation: 28199

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

Upvotes: 18

Related Questions