javascript 为什么 Google Chrome 的脚本调试器不能让我设置断点?

声明:本页面是StackOverFlow热门问题的中英对照翻译,遵循CC BY-SA 4.0协议,如果您需要使用它,必须同样遵循CC BY-SA许可,注明原文地址和作者信息,同时你必须将它归于原作者(不是我):StackOverFlow 原文地址: http://stackoverflow.com/questions/4359101/
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-25 11:10:30  来源:igfitidea点击:

Why won't Google Chrome's script debugger let me set a breakpoint?

javascriptjquerydebuggingscriptinggoogle-chrome

提问by Kev

I'm running Google Chrome 8.0.552.215 on Windows 7 x64 Ultimate. I have a simple jQuery inline script much like any I've successfully debugged in the past:

我在 Windows 7 x64 Ultimate 上运行 Google Chrome 8.0.552.215。我有一个简单的 jQuery 内联脚本,就像我过去成功调试过的任何脚本一样:

<script type="text/javascript">
  $(document).ready(function () {
    // do stuff here
    // but reduced to a simple
    alert('here!');
  });
</script>

I'm browsing to the secure (https) section of the site I'm working on.

我正在浏览我正在处理的网站的安全 (https) 部分。

There are no script errors, the scripts all run just fine, but I can't set a breakpoint.

没有脚本错误,脚本都运行得很好,但我无法设置断点。

I tried debugging this in Firefox's Firebug and and can set and hit breakpoints just fine.

我尝试在 Firefox 的 Firebug 中调试它,并且可以很好地设置和命中断点。

Why would this happen?

为什么会发生这种情况?

采纳答案by Patrick Lewis

This bug was fixed yesterday (February 3) with the introduction of a new api for managing JavaScript breakpoints: http://code.google.com/p/chromium/issues/detail?id=69988

此错误已于昨天(2 月 3 日)修复,引入了用于管理 JavaScript 断点的新 API:http: //code.google.com/p/chromium/issues/detail?id= 69988

I downloaded the most recent Chromium nightly from http://build.chromium.org/f/chromium/snapshots/and was able to successfully set breakpoints in JavaScript, which I had been unable to do using the current stable/beta/dev builds of Chrome.

我每晚从http://build.chromium.org/f/chromium/snapshots/下载了最新的 Chromium,并且能够在 JavaScript 中成功设置断点,而使用当前的 stable/beta/dev 版本我无法做到这一点铬。

Hopefully this fix will be incorporated into the next releases of Chrome. Until then, adding debugger; statements to your code is a decent workaround for setting breakpoints.

希望此修复程序将合并到下一个版本的 Chrome 中。在此之前,添加调试器;代码中的语句是设置断点的一个不错的解决方法。

回答by Jan

Does this happen when you refresh the page when the developer tools are already open? It happened to me too in that case.

在开发者工具已经打开的情况下刷新页面会发生这种情况吗?在这种情况下,它也发生在我身上。

Workaround:

解决方法:

  1. Set resource tracking to always enabled.

  2. Close the developer tools.

  3. Refresh the page.

  4. Open the developer tools, tab resources.

  5. Set your breakpoint.

  6. File a bugreport herebecause it is not normal behavior.

  7. Post a link to this bugreport back on SO so we can all star it.

  1. 将资源跟踪设置为始终启用。

  2. 关闭开发者工具。

  3. 刷新页面。

  4. 打开开发者工具,标签资源。

  5. 设置断点。

  6. 在此处提交错误报告因为这不是正常行为。

  7. 在 SO 上发布此错误报告的链接,以便我们所有人都可以为它加注星标。