How to change the default browser opened for localhost?

Viewed 1063

I have been working with React.js for a couple months now, developing using VS Code, Chromium-based browsers (ditched Chrome, switched to Brave as default browser) and a Windows machine (Windows 10).

Recently, my friend have recommended that I switch to using Firefox for development, and as lazy as developers can go, I wanna ask how to configure such that when I do npm start, localhost:3000 will appear in Firefox instead of my original default browser. I do not want to change my default browser.

Update

From recommendations I have found this other post:
create-react-app: How do I "npm start" with a specific browser?

Further comments are still welcome XD

3 Answers

On Linux(Ubuntu 20.04). Edit Your package.json like that:

"scripts": {
    "start": "BROWSER=firefox react-scripts start",
    "build": "react-scripts build",
    "test": "react-scripts test",
    "eject": "react-scripts eject"
  },

Type npm start and Voila :-P

On Win 10. Create an .env file in the root directory with line like this BROWSER=firefox Run npm start and You are done:-) Best Regards ;-)

I would set the BROWSER environment variable in your linux environment instead of the project-specific package.json file (or inside of a .env file) if you are using the Windows Subsystem for Linux (WSL) on your Windows 10 machine and always want to connect to the React development server from your Firefox browser.

Assuming you are using WSL2: open a WSL2 shell and enter the following command:

sudo nano ~/.bashrc

Add export BROWSER='firefox' at the end of the file, exit the nano editor (CTRL+X) and save (Y) when prompted. Enter the following command in the linux bash shell:

exit

Now, relaunch the WSL2 linux shell and start the React development server again. Firefox should start automatically, pointing to your development server on localhost.

You don't need to run any command in cmd or make changes to any scripts. Just make default the browser, you want for HTTP file extension. I have Edge as default for everything, just changed HTTP to Chrome and Yes! React app opens now in Chrome.

enter image description here

Related