Open semmel opened 7 years ago
I can reproduce this issue on Linux/Windows on nwjs-sdk-v0.24.0.
After digging into it I found it should be expected: the 'setTimeout' function is bound to the global window object of the first window (which is under the security origin of chrome-extension://xyz), while the callback is executed in the context of the second window (security origin: www.example.com), which doesn't have the access to the first window and its function.
btw, using 'nwWindow.window.setTimeout' works as expected.
I think the callback should also have the context of the first window (chrome-extension://xyz).
Must be a regression, since it has worked fine until after
NW.js 0.22.3
The behaviour occurs forNW.js 0.23.7
in event handlers likenw.Window.on('close', handler)
.I am running NW.js in Separate Context Mode without
--mixed-context
option.An event handler like
nw.Window.on('close', handler)
has the Browser Context version ofsetTimeout
in the global JS context. The observed behaviour is that it's worker function is never executed.As a workaround one can employ
setTimeout
from the Node.js Context:global.setTimeout
.Here is the demo (Simply run in the Developer Console of the SDK build of
NW.js 0.23.7
)My workaround is to replace the Browser Context version of setTimeout entirely with the Node.js Context version:
To my surprise this seems to work.
Maybe
setInterval
is also affected?