question-mark
Stuck on an issue?

Lightrun Answers was designed to reduce the constant googling that comes with debugging 3rd party libraries. It collects links to all the places you might be looking at while hunting down a tough bug.

And, if you’re still stuck at the end, we’re happy to hop on a call to see how we can help out.

Reference to a window after reloading is broken

See original GitHub issue

In my test app i open a window on app start nw.Window.open(nw.App.manifest.onlineURL, windowProperties, function (win) { win.on('close', function (shouldQuit) { if (shouldQuit) { nw.App.quit(); } else { win.hide() }; }); nw.App.on('reopen', function () { win.show(); }); tray.on('click', function () { win.show(); }); win.window.onload = function (){ setTimeout(function(){ win.window.location.href = nw.App.manifest.onlineURL; }, 5000); } }); And i have a Tray click handler. After reloading the window tray.on('click) does not work. The window is hidden and i do not have any reference to it.

NW 0.14.2 Windows 10 x64. My test app: test_app.zip

Issue Analytics

  • State:closed
  • Created 7 years ago
  • Comments:13 (4 by maintainers)

github_iconTop GitHub Comments

1reaction
davidcamposcommented, Aug 30, 2016

@franchuk Have you managed to fix this? I create the window in the init script (main: index.js on package.json) and keep the reference to it. After navigating to another page, the window reference is broken and the close event is cleared. I have tray with menu on the background page. I’m using the latest stable version of nw.js.

@ghostoy and @rogerwang Any recommendations?

Thanks for your help.

1reaction
RohitSharma27commented, Jun 11, 2016

Can you please provide more information like when does the file that contains the above code is executed? When do you inject the file that contains your tray’s code? I did face the same issue and the reason is when you reload or navigate, your functions and variables are likely to get GCed. So you are gonna have to write your tray related code in background context, which stays there for your app’s lifetime. See manifest format and use bgscript in your package.json to include your tray file. I hope it helps. Cheers. 😃

Read more comments on GitHub >

github_iconTop Results From Across the Web

Retrieve child window reference after refresh - Stack Overflow
You can obtain the reference of child window simply by following trick. newWin = window.open("", "child_window_name", "width=.
Read more >
Child window lost reference to it's parent window on reloading ...
When the parent window is reloaded the JavaScript lexical environment is wiped clean - the reference is gone. Don't reload the parent window!...
Read more >
location.reload() - Web APIs | MDN
The location.reload() method reloads the current URL, like the Refresh button.
Read more >
Location reload() Method - W3Schools
Window location.reload()​​ The reload() method reloads the current document. The reload() method does the same as the reload button in your browser.
Read more >
Trying to reload parent page after opening new window from ...
Hi, I have a strange setup that requires an iframe which then has a link to open a new tab/window. When someone clicks...
Read more >

github_iconTop Related Medium Post

No results found

github_iconTop Related StackOverflow Question

No results found

github_iconTroubleshoot Live Code

Lightrun enables developers to add logs, metrics and snapshots to live code - no restarts or redeploys required.
Start Free

github_iconTop Related Reddit Thread

No results found

github_iconTop Related Hackernoon Post

No results found

github_iconTop Related Tweet

No results found

github_iconTop Related Dev.to Post

No results found

github_iconTop Related Hashnode Post

No results found