user9597092
user9597092

Reputation:

Electron - Uncaught Error: document is not defined

I have added an event listener to my electron's main.js:

document.getElementById("btnEd").addEventListener("click", function (e) {
    console.log('button was clicked');
});

The problem is that I keep getting this error:

Uncaught Error: document is not defined

How can I fix this?

Upvotes: 2

Views: 4815

Answers (1)

Hai Pham
Hai Pham

Reputation: 2225

You can not do this on main process

In Electron, the process that runs package.json's main script is called the main process. The script that runs in the main process can display a GUI by creating web pages. An Electron app always has one main process, but never more.

You should take a look at Electron Application Architecture fisrt: https://electronjs.org/docs/tutorial/application-architecture

Upvotes: 4

Related Questions