简体   繁体   English

我可以在Chrome开发者工具中执行Node.js javascript脚本吗?

[英]Can I execute nodejs javascript scripts in chrome devtools?

Is it possible to use chrome devtools to execute the terminal command node myfile.js , so the chrome console would output all console.log s from my code? 是否可以使用chrome devtools执行终端命令node myfile.js ,所以chrome控制台将从我的代码输出所有console.log I have got some terminal plugin installed in my IDE and I use some keyboard shortcuts when I want to run this command on my files, to get my logs immediately (like when running html+js in the browser) but it prints out just plain text. 我在IDE中安装了一些终端插件,并且想在文件上运行此命令时使用一些键盘快捷键来立即获取日志(例如在浏览器中运行html + js时),但它只打印纯文本。 Chrome can recognize the output data type and structurize it well (arrays, objects) , what is really cool. Chrome可以识别输出数据类型并将其结构化(数组,对象) ,这真的很酷。

I've already tried out node inspect-brk but its purpose seems to be quite different than just printing out my logs. 我已经尝试过node inspect-brk但是它的目的似乎与仅打印我的日志完全不同。

UPDATE: 更新:

I've found very interesting link with npm modules that do what I mean. 我发现与npm模块非常有趣的链接可以实现我的意思。

I have alredy tested node-monkey but it does not work on my Windows, but iron-node works great and I can run my .js files with iron-node file.js command and get all console.log s in Chrome devtools! 我已经对node-monkey进行了测试,但是它不能在Windows上运行,但是iron-node可以正常工作,我可以使用iron-node file.js命令运行.js文件,并在Chrome devtools中获取所有console.log

run your file with 使用运行文件

node --inspect <your file name>.js

and then type in chrome 然后输入chrome

chrome://inspect

See https://nodejs.org/api/debugger.html#debugger_v8_inspector_integration_for_node_js for reference 请参阅https://nodejs.org/api/debugger.html#debugger_v8_inspector_integration_for_node_js以获取参考

--inspect-brk is used for breakpoint purposes, with that flag the debugger is ready to run your code but is expecting the developer to add something before it begins to run your script. --inspect-brk用于断点,带有该标志的调试器可以运行您的代码,但是希望开发人员在开始运行脚本之前先添加一些内容。 There is a play button at the top corner of the chrome devtools debugger, and if there are no other breakpoints or debugger; chrome devtools调试器的左上角有一个播放按钮,如果没有其他断点或调试器,则为播放按钮。 statments in your code it will run as it would run or your workstation 您的代码中的陈述将按其运行方式或您的工作站的方式运行

暂无
暂无

声明:本站的技术帖子网页,遵循CC BY-SA 4.0协议,如果您需要转载,请注明本站网址或者原文地址。任何问题请咨询:yoyou2525@163.com.

相关问题 如何识别Chrome DevTools中调用JavaScript文件的位置? - How can I identify where JavaScript files are being called from in Chrome DevTools? 如何通过 devtools(chrome、Edge 等)查看 JavaScript 使用的内存中的哪些变量? - How can I see which variables are specifically in memory used by JavaScript through devtools (chrome, Edge, etc.)? 我可以检测Chrome是否存在“错误暂停”或通过网站javascript打开的devtools吗? (用于错误处理) - Can I detect whether Chrome has 'pause on errors' or devtools open from website javascript? (For error handling) 在Chrome Devtools中调试Javascript时,遇到DOM断点后如何继续? - When debugging Javascript in Chrome Devtools, how can I continue after hitting a DOM breakpoint? Chrome为什么可以在其他页面上执行javascript,但我不能执行? - Why can Chrome execute javascript on other pages but I can't? 如何使用JavaScript将Google Chrome DevTools控制台设置为全屏显示? - How can the Google Chrome DevTools Console be made fullscreen using JavaScript? 一些 javascript 代码让我无法在 chrome 上打开 devTools - some javascript codes make me can't open the devTools on chrome 在 chrome [devtools] 中管理 JavaScript setIntervals - Managing JavaScript setIntervals in chrome [devtools] 用于JavaScript代理的Chrome Devtools格式化程序 - Chrome Devtools formatter for javascript proxy 如何在 Chrome DevTools 中修复 JavaScript? - How to fix JavaScript in Chrome DevTools?
 
粤ICP备18138465号  © 2020-2024 STACKOOM.COM