How to Open Web Page in the Browser from an Electron App

Utkarsha Bakshi
Geek Culture
Published in
3 min readJun 6, 2021

--

Photo by Jason Rosewell on Unsplash

If you are building an electron app for the first time, it might be a bit confusing to comprehend that doing something as simple as opening a web page in the browser from your app isn’t straight forward.

A quick web search, will return lots of results pointing you to a single line of code that can be used for opening a link in the browser. It goes something like this.

require('electron').shell.openExternal("http://google.com");

The above snippet does work but the catch is that it should be called from main process of the Electron app. You might ask, what the heck is the main process?

Put simply, an electron app has 2 processes, ie. the main process and the renderer process. The main process is responsible for creating instances of the browser windows and handling various application events. The renderer process is responsible for running the user-interface of your app. For a deep-dive into electron processes, refer to this article.

--

--