NWJS window loaded is not available

419 views Asked by At

The NWJS documentation states that after opening a window, you have to wait for the loaded event before you can interact with it:

You should wait for the Window’s loaded event before interacting with any of its components.

So I tried to add a loaded event handler for the win object after opening it.

nw.Window.open('test.html', {}, (win) => { 
    win.showDevTools()
    win.addEventListener("loaded", () => {
        console.log("NW Window loaded not working...")
    })
}

I get the following error:

Uncaught TypeError: win.addEventListener is not a function

How can I listen for NWWindow events in NWJS? Sidenote: I CAN listen for DOM window load events, but that's not the same is it?

nw.Window.open('test.html', options, (win) => { 
    win.showDevTools()
    win.window.addEventListener("load", () => {
        console.log("dom window load IS working...")
    })
}
2

There are 2 answers

0
Kokosnuss On BEST ANSWER

There is an example on how to use the Event Listener on the nw.Window:

nw.Window.open('test.html', {}, win => { 
    win.showDevTools();
    win.on("loaded", () => {
        console.log("NW Window loaded not working...")
    })
}

Example from here, I changed it so that it fits to your problem

  • Edit: I changed the nw.Window.get() to win
1
Chawathe Vipul S On

addEventListener is from DOM. Refer https://nodejs.org/api/events.html#events_emitter_addlistener_eventname_listener & then try again. Also console may work as win.window.console here.