Skip to content

Commit e0c9a02

Browse files
committed
always redirect global.console to webkit
There are cases that the new Frame doesn't have Node enabled on navigation, and then the 'console' set previously won't work since the rv has been swapped out. Fix nwjs#350
1 parent 8ce2355 commit e0c9a02

1 file changed

Lines changed: 6 additions & 5 deletions

File tree

src/renderer/shell_content_renderer_client.cc

Lines changed: 6 additions & 5 deletions
Original file line numberDiff line numberDiff line change
@@ -166,6 +166,12 @@ void ShellContentRendererClient::InstallNodeSymbols(
166166
static bool installed_once = false;
167167

168168
bool is_file_protocol = url.SchemeIsFile();
169+
v8::Local<v8::Object> nodeGlobal = node::g_context->Global();
170+
v8::Local<v8::Object> v8Global = context->Global();
171+
172+
// Use WebKit's console globally
173+
nodeGlobal->Set(v8::String::New("console"),
174+
v8Global->Get(v8::String::New("console")));
169175

170176
// Do we integrate node?
171177
bool use_node =
@@ -184,8 +190,6 @@ void ShellContentRendererClient::InstallNodeSymbols(
184190
symbols->Set(2, v8::String::New("Buffer"));
185191
symbols->Set(3, v8::String::New("root"));
186192

187-
v8::Local<v8::Object> nodeGlobal = node::g_context->Global();
188-
v8::Local<v8::Object> v8Global = context->Global();
189193
for (unsigned i = 0; i < symbols->Length(); ++i) {
190194
v8::Local<v8::Value> key = symbols->Get(i);
191195
v8Global->Set(key, nodeGlobal->Get(key));
@@ -227,9 +231,6 @@ void ShellContentRendererClient::InstallNodeSymbols(
227231

228232
if (use_node || is_nw_protocol) {
229233
v8::Local<v8::Script> script = v8::Script::New(v8::String::New(
230-
// Use WebKit's console globally
231-
"global.console = console;"
232-
233234
// Overload require
234235
"window.require = function(name) {"
235236
" if (name == 'nw.gui')"

0 commit comments

Comments
 (0)