如何访问nwjs应用程序的控制台输出?

问题描述:

我想玩nwjs,我无法弄清楚如何调试。如何访问nwjs应用程序的控制台输出?

require('nw.gui').Window.get().showDevTools() 
var menu = new nw.Menu(); 

menu.append(new nw.MenuItem({ 
    label: 'Item A', 
    click: function(){ 
    alert('You have clicked at "Item A"'); 
    } 
})); 

menu.append(new nw.MenuItem({ label: 'Item B' })); 
menu.append(new nw.MenuItem({ type: 'separator' })); 
menu.append(new nw.MenuItem({ label: 'Item C' })); 

document.body.addEventListener('contextmenu', function(ev) { 
    console.log("Hello"); 

    ev.preventDefault(); 
    menu.popup(ev.x, ev.y); 

    return false; 
}, false); 

我加了两行代码:

require('nw.gui').Window.get().showDevTools(); 
console.log("Hello"); 

我运行一个脚本,看到两个窗口:

enter image description here

我的教程有基本的脚本如果我右键单击文字,使显示的菜单,但不在调试工具栏中输出。

我在做什么错?

+0

请参阅[“应该问题包括”标签“在他们的标题?”](http://meta.stackexchange.com/questions/19190/should-questions-include-tags-in - 他们的标题),其*识是“不,他们不应该”! –

+0

是特定于Windows 10,还是[tag:nwjs]? –

+0

特定于nwjs – kevas

对于showDevTools()的工作,您需要下载SDK版本的nwjs。您正在获得白色屏幕,因为它是普通版本。使用SDK版本,showDevTools()将打开chrome Developer Tools,其中包含控制台输出的选项卡。看到下面的图片: Developer Tools Console