简体   繁体   English

是否可以直接在Google Chrome浏览器中运行JS文件并对其进行调试?

[英]Is it possible to run JS-file in the Google Chrome directly and debug it?

It is possible to use Google Chrome as JS-file simple editor: 可以将Google Chrome浏览器用作JS文件简单编辑器:

在此处输入图片说明

It is my c:\\js\\foo.js local file. 这是我的c:\\js\\foo.js本地文件。 Context menu of foo.js tab has Evaluate in console menu item but it doesn't work as I expected: I don't see the stuff... string in the console output and breakpoint doesn't work. foo.js选项卡的上下文菜单在控制台菜单项中具有“ 评估”,但是它没有按我预期的那样工作:我看不到stuff...控制台输出中的字符串,并且断点不起作用。

Is it possible to run JS-file in the Google Chrome directly and debug it? 是否可以直接在Google Chrome浏览器中运行JS文件并对其进行调试?

Yes, you didn't select whole code and Chrome didn't evaluate it. 是的,您没有选择完整的代码,Chrome也没有对其进行评估。

  1. Press CTRL+SHIFT+P in debug tools, then select "create new snippet". 在调试工具中按CTRL + SHIFT + P,然后选择“创建新代码段”。
  2. Then you can write your snippet. 然后,您可以编写代码段。
  3. Select whole code (press CTRL+A). 选择整个代码(按CTRL + A)。
  4. Press CTRL+SHIFT+E (or from the context menu select "Evaluate in console"). 按CTRL + SHIFT + E(或从上下文菜单中选择“在控制台中评估”)。

Remember, you have to select whole code. 记住,您必须选择整个代码。 If you don't select, you will see Window object outputted in the console. 如果未选择,则将在控制台中看到Window对象输出。

Unfortunately, there isn't a way to debug code. 不幸的是,没有一种方法可以调试代码。 I didn't find any. 我没找到 You should consider using of Codepen or another service. 您应该考虑使用Codepen或其他服务。 Also, you can create simple HTML file and include that js file in it that you need to debug. 另外,您可以创建简单的HTML文件,并在其中包含需要调试的js文件。

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

 
粤ICP备18138465号  © 2020-2024 STACKOOM.COM