Nwjs how to use evalNWBinModule in another created window?

44 views Asked by At

In the main window I write the following code and it works:

nw.Window.get(null).evalNWBinModule(null, "./my.bin", "./my.js");
import("./my.js");

but if I create a new window via nw.Window.open(MyOtherURL); where I then move this code, then after running I get an error:

Uncaught (in promise) TypeError: Failed to resolve module specifier './my.js'

what is the launch difference and what else do i need to configure?

1

There are 1 answers

1
Jaredcheeda On

nw.Window.get() returns a reference to the Window itself, so you can then chain off of it.

nw.Window.open(), does not, but it does have a callback function gives you access to the new window, which you can chain off of.

const url = 'page2.html';
const options = {};
nw.Window.open(url, options, function (win) {
  win.evalNWBinModule(null, './my.bin', './my.js');
});

However I'm not sure that will do what you want. You will likely be better off having the code run in your page2.html file directly.