The main reason for this is security and privacy. Web browsers are a very special type of software that has very unique risks that pretty much no other type of application in the world would have.
Whenever your web browser opens a webpage, that webpage may contain a program in it written in the Javascript programming language by the website's owner that will run on your computer. This is pretty much unthinkable.
This application connects to the Internet, downloads a program written by some random guy, and just runs it on your computer? That sounds like a terrible application! Who designed this? Are they insane?
Alas, it's how the web works. In order to do anything, and I mean virtually ANYTHING, including posting comments without reloading the entire webpage, changing the number on a like counter when you click on it without reloading the entire webpage, or even displaying a dropdown menu that is even slightly complex and works on mobile, you're going to need Javascript. Web browsers simply don't provide enough features by default to make most modern websites work, while at the same time they're also bloated with so many features they're practically entire operating systems at this point.
Let me explain. If you want to create a cross-platform application that runs on Windows, macOS, and Linux, the easiest method is to just make it a webpage.
If you were to create a web application from scratch, the instant you needed to load a file you would have all sorts of problems. In order to load a PNG file, you need the library that decodes PNG files into pixel data, but in order to display that pixel data you would need something else, and if you want to scale the image, or rotate it, or even pan it, or display text on top of it, or anything even slightly complex, you would need an immense amount of code.
By contrast, if you choose to make it a webpage, it takes just 2 minutes, at most, because all of the code to load, display, and scale images, to render text, to lay out user interface elements, to handle user input, to display video, to play sounds, to download things from the Internet, etc., is already programmed into the web browser itself.
Consequently, developers are left with the following choice:
- Make your application a web browser app.
- Make no application at all because it's going to take too much effort.
Unfortunately, if you make a web browser app, it's going to suffer from the limitations that web browsers imposes on webpages due to the countless security and privacy concerns that originate from the fact web browsers will literally download programs from the Internet made by random people and run it in your PC.
For instance, an obvious limitation is that webpages don't have direct access to your PC's files and folders.
A web application can read data from a file if you drag and drop it into the web browser. In this case, the browser intercepts the file and passes its data to the webpage's Javascript.
However, the web application can't just open a file by its filepath for example. You can type C:\folder\file in the webpage and have it load the file from your computer, because the web browser won't let it. If it let it, then ANY webpage could read ANY file from your PC, and send it to the Internet, which would be extremely bad.
Note that these security and privacy measures are taken assuming whoever is running the website has criminal intent of some sort. That's because even if the website is run by a decent person, websites can be hacked, and when they are hacked, the hacker can distribute malicious Javascript to anyone who accesses the website.
There is also no way to get rid of these limitations because if you could get rid of it, all the hacker needs to do is tell you to disable some setting in order to make the webpage work and a lot of people would just fall for it.
An additional problem is that because there are multiple web browsers, and multiple versions of the same web browser, a web application that works on one web browser or on one version may not work properly on other web browsers or other versions of the same browser.
To get rid of these problems while keeping the convenience of web browser development, the only choice that developers have is to ship an entire web browser with their webpage. That's Electron.