![](/img/trans.png)
[英]How do I print debug messages in the Google Chrome JavaScript Console?
[英]How do you print messages to openDevTools's console in Electron js?
我刚刚完成了电子js的hello world应用程序。 我可以通过console.log打印到终端,也可以在应用程序窗口中打开openDevTools,但如果可能的话,我希望console.log语句可以在窗口中打印到openDevTools。 有谁知道如何做到这一点?
要以电子方式打印到开发工具,您的console.log必须位于以客户端身份运行的JavaScript内,而不是从控制台运行的服务器部分。
说这是您的电子应用(摘录)
app.on('ready', () => {
// load the local HTML file
let url = require('url').format({
protocol: 'file',
slashes: true,
pathname: require('path').join(__dirname, '/build/index.html')
})
mainWindow.loadURL(url);
mainWindow.webContents.openDevTools();
console.log('this will go to the terminal');
});
index.html的:
<script>
console.log('this will go to electron dev tools');
</script>
声明:本站的技术帖子网页,遵循CC BY-SA 4.0协议,如果您需要转载,请注明本站网址或者原文地址。任何问题请咨询:yoyou2525@163.com.