Logo Questions Linux Laravel Mysql Ubuntu Git Menu
 

How to set the default browser for a Angular 2 application

I am trying to build an Angular 2 application using VSCode editor. On my machine the default browser is IE. When I run npm start it launches the application in IE. But I want to launch my application in Chrome.

How can I change this behaviour to launch Chrome instead of IE with npm start?

like image 763
Atul Sureka Avatar asked Mar 02 '26 23:03

Atul Sureka


2 Answers

You could try it using package.json, as a workaround for default browser. Look into the "scripts" and find "start". Use this code snippet:

"start": "start {browser} http://{projectsite} && ng serve"

With {browser} as your preferred browser (in this case, use chrome), and {projectsite} as the site where the application is started (if you haven't changed any of the setting for the test, still use localhost:4200).

If you want to test it, use npm start to run these commands. It should start the browser first before compiling the angular project so you would see a "page not found" before switching to your app.

like image 71
Glenn Parale Avatar answered Mar 04 '26 16:03

Glenn Parale


If you're using VS_Code as your IDE then go to .vs > vscode > launch.json in that check for the below.

{
  "type": "chrome",
  "request": "launch",
  "name": "Launch Chrome against localhost",
  "url": "http://localhost:PortNo",
  "webRoot": "${workspaceFolder}",

} 
like image 30
Gnani S Avatar answered Mar 04 '26 15:03

Gnani S



Donate For Us

If you love us? You can donate to us via Paypal or buy me a coffee so we can maintain and grow! Thank you!