Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

NW2: with nwfaketop get chrome.windows undefined #7498

Closed
srguiwiz opened this issue Jun 7, 2020 · 3 comments
Closed

NW2: with nwfaketop get chrome.windows undefined #7498

srguiwiz opened this issue Jun 7, 2020 · 3 comments
Labels

Comments

@srguiwiz
Copy link

srguiwiz commented Jun 7, 2020

NWJS Version : 0.46.2
Operating System : CentOS 7.8

Expected behavior

A call

nw.Window.get(iframe.contentWindow)

should work even if that iframe is an nwfaketop. It worked before NW2 when in NW1.

Actual behavior

There is an error with a surprisingly short stack trace

extensions::nw.Window:107 Uncaught TypeError: Cannot read property 'onWindowChanged' of undefined
    at new NWWindow (extensions::nw.Window:107)
    at extensions::nw.Window:723

and our code doesn't run after that.

At a breakpoint at that line extensions::nw.Window:107 inside function NWWindow(cWindow) in the code

  chrome.windows.onWindowChanged.addListener(updateWindowAttributes);

the chrome.windows is undefined.

That is called from line 723 inside apiBridge.registerCustomHook(function(bindingsAPI) code

currentNWWindow = new NWWindow;

We have narrowed it down it occurs with an iframe that has nwfaketop.

Per developer tools call stack it is caused by our application calling

nw.Window.get(iframe.contentWindow)

Not knowing when code would get to line 107, I guess maybe a new optional chaining operator would be a reasonable single character fix:

chrome.windows?.onWindowChanged.addListener(updateWindowAttributes);

How to reproduce

Simplest NW.js app with index.html

<html>
<head>
</head>
<body>
  <iframe
    src="http://www.wikipedia.org/"
    nwfaketop
    width="100%" height="80%"></iframe>
  <script>
    function loadListener(event) {
      let iframe = event.target;
      console.log(`iframe ${iframe.src} has loaded ${iframe.contentWindow.location.href}`);
      let nwWindow = nw.Window.get(iframe.contentWindow);
    }
    document.querySelector("iframe").addEventListener("load", loadListener);
    nw.Window.get().showDevTools();
  </script>
</body>
</html>

No rush. For now we can run with NW2 disabled.

@srguiwiz
Copy link
Author

srguiwiz commented Jun 7, 2020

Updated description with a short index.html that causes the error.

@srguiwiz srguiwiz changed the title in NW2 with nwfaketop get chrome.windows undefined NW2: with nwfaketop get chrome.windows undefined Jun 8, 2020
@srguiwiz
Copy link
Author

srguiwiz commented Jun 20, 2020

We found out for our need we are fine with

let nwWindow = nw.Window.get(window);

instead of passing the iframe's contentWindow. Hence, we finally are able to use NW2.

Therefore, this no longer is an issue for us.

It probably is okay to close this issue.

@rogerwang
Copy link
Member

cc #7230

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
Projects
None yet
Development

No branches or pull requests

3 participants