Skip to content

Commit d2cd2da

Browse files
committed
set window.__nwWindowId when installing Node symbols
Fix nwjs#1519 in a better way. See 0b0dfe625 in Chrome repo
1 parent bb3bd09 commit d2cd2da

File tree

1 file changed

+7
-1
lines changed

1 file changed

+7
-1
lines changed

src/renderer/shell_content_renderer_client.cc

Lines changed: 7 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -303,7 +303,13 @@ void ShellContentRendererClient::InstallNodeSymbols(
303303

304304
if (use_node) {
305305
RenderViewImpl* rv = RenderViewImpl::FromWebView(frame->view());
306+
307+
std::string js_set_id;
308+
int nw_win_id = rv->GetNwWinID();
309+
if (nw_win_id > 0)
310+
js_set_id = "window.__nwWindowId = " + base::IntToString(nw_win_id) + ";";
306311
std::string root_path = rv->renderer_preferences_.nw_app_root_path.AsUTF8Unsafe();
312+
307313
#if defined(OS_WIN)
308314
ReplaceChars(root_path, "\\", "\\\\", &root_path);
309315
#endif
@@ -320,7 +326,7 @@ void ShellContentRendererClient::InstallNodeSymbols(
320326
"if (window.location.href.indexOf('app://') === 0) {process.mainModule.filename = root + '/' + process.mainModule.filename}"
321327
"process.mainModule.paths = global.require('module')._nodeModulePaths(process.cwd());"
322328
"process.mainModule.loaded = true;"
323-
"}").c_str()
329+
"}" + js_set_id ).c_str()
324330
));
325331
CHECK(*script);
326332
script->Run();

0 commit comments

Comments
 (0)