javascript Chrome 开发工具命中代码但未命中断点

声明:本页面是StackOverFlow热门问题的中英对照翻译,遵循CC BY-SA 4.0协议,如果您需要使用它,必须同样遵循CC BY-SA许可,注明原文地址和作者信息,同时你必须将它归于原作者(不是我):StackOverFlow 原文地址: http://stackoverflow.com/questions/20385505/
Warning: these are provided under cc-by-sa 4.0 license. You are free to use/share it, But you must attribute it to the original authors (not me): StackOverFlow

提示:将鼠标放在中文语句上可以显示对应的英文。显示中英文
时间:2020-10-27 18:23:04  来源:igfitidea点击:

Chrome Dev Tools hitting code but not breakpoints

javascriptdebugginggoogle-chromegoogle-chrome-devtools

提问by ford prefect

I have breakpoints enabled on chrome dev tools and I have a breakpoint on a line. I know chrome is hitting the line because I put the breakpoint on a line that has the following statement: alert("why is this not breaking")The breakpoint works if I find the file in the localhost. The breakpoints used to function in the local editor but now they won't. Has anyone else had a similar problem?

我在 chrome 开发工具上启用了断点,并且我在一行上有一个断点。我知道 chrome 正在执行该行,因为我将断点放在具有以下语句的行上:alert("why is this not breaking")如果我在 localhost 中找到该文件,则断点有效。断点曾经在本地编辑器中起作用,但现在它们不会了。有没有其他人遇到过类似的问题?

回答by baralong

I had a similar problem not hitting my breakpoints. Turned out it was because it was a deployed version of the site but the dev tools still had my local dev folder mapped to the workspace, the meant I had the local script files open not the ones on the server. The solution was to close the opened local scripts, opening the right files in the navigator and then setting the breakpoints.

我有一个类似的问题,没有达到我的断点。原来这是因为它是站点的部署版本,但开发工具仍然将我的本地开发文件夹映射到工作区,这意味着我打开了本地脚本文件而不是服务器上的文件。解决方案是关闭打开的本地脚本,在导航器中打开正确的文件,然后设置断点。

OK I was a bit dumb not realising it in the first place, but this might serve as a good note for anyone else having the same problem as me.

好吧,我一开始没有意识到这一点有点愚蠢,但是对于与我有同样问题的其他人来说,这可能是一个很好的说明。

回答by ford prefect

Should anyone stumble across this later. I have yet to find a definitive answer to this question but these are some other where I have found some helpful info:

如果有人以后偶然发现这一点。我还没有找到这个问题的明确答案,但我在其他一些地方找到了一些有用的信息:

Chrome developer tools workspace mappings

Chrome 开发者工具工作区映射

Chrome Stable/Canary Dev Tools Issues - Syntax Highlighting Auto-Complete etc

Chrome 稳定版/Canary 开发工具问题 - 语法高亮自动完成等

I will continue to update this should I find a real solution

如果我找到真正的解决方案,我将继续更新

The accepted answer is correct here.

接受的答案在这里是正确的。

回答by Ben

The debugger;tip in Chrome javascript debugger breakpoints don't do anything?helped me find where my mistake was.

Chrome javascript 调试器断点中debugger;提示没有做任何事情?帮助我找到了我的错误所在。

I'm working on a Rails project for the first time, and there were two versions of the file without my knowing it. Rails' "asset pipeline" used a //= require foostatement to import, and the same foofile was also included somewhere else.

我第一次在 Rails 项目上工作,在我不知道的情况下有两个版本的文件。Rails 的“资产管道”使用了一个//= require foo语句来导入,同样的foo文件也被包含在其他地方。

The debugger;pointed me to the right place, thankfully.

debugger;谢天谢地,这把我指向了正确的地方。

回答by Markus

You should enable the setting to stop on any exception, in the Sources tab on the developer page (F12 in chrome). (Unload your other extensions to help focus only on the problem one, and remove their thumbnails on the left panel too).

您应该在开发人员页面的 Sources 选项卡中启用设置以在任何异常时停止(chrome 中的 F12)。(卸载您的其他扩展程序以帮助只关注问题之一,并在左侧面板上删除它们的缩略图)。

There may be an exception thrown earlier than any debug breakpoint you have set. E.g. there if there is a missing extension permission requirement in the manifest file, which causes an exception to be thrown once it tries to use the resource but can't.

可能会在您设置的任何调试断点之前抛出异常。例如,如果清单文件中缺少扩展权限要求,一旦它尝试使用资源但不能使用,则会导致抛出异常。