Navigator / Document is null


#1

I’m trying to install Codemirror in Electron. While installing the modules work, the module itself doesn’t work, because Navigator and Document are null, so I guess I do a require of the codemirror module in the wrong place.

Right now, the main.js looks like this:

 'use strict';
  const electron = require('electron');
  const codemirror = require("codemirror"); // <--- the codemirror change
  const app = electron.app;  // Module to control application life.

But the codemirror uses the navigator and the document, for which I get an error: ReferenceError: document is not defined. So, my guess is: I include the codemirror module in the wrong place.

However, what I haven’t figured out yet, is: what is the correct place?

Thanks, Erik


#2

You need to require codemirror from the renderer process (e.g. from index.html or a script included there). The main process does not have access to web APIs.

http://electron.atom.io/docs/latest/tutorial/quick-start/#differences-between-main-process-and-renderer-process


#3

Ah, thanks! I was confused about how to access the different processes. Thanks, that will work!