Sunday, July 30, 2017

Electron - Passing Data On Window Creation

Passing data from Main to another window can be achieved by using ipcRenderer. That feature is surely good if we need 2-way communication between Main and its rendered window.

But, what if we only to do it on its initiation? Isn't there any simpler way to do it? 

Yes, there it is. 

I can't find it in its documentation, but I found it accidentally. 

Actually, we can pass any data on BrowserWindow creation process. 

In my case, I need to pass an URL to be loaded on the webview. So, here's mine :



And here's how I got that URL on the page.html I loaded


My conclusion, even ipcRenderer is good for communication between Main and Rendered process, but if it's only on window initiation, we can do pass it on BrowserWindow creation. It'll be simpler and more effective in my opinion.


If you have a more effective way, comment this post.

Nothing is perfect, right?