简体   繁体   English

Chrome javascript 调试器断点什么都不做?

[英]Chrome javascript debugger breakpoints don't do anything?

I can't seem to figure out the Chrome debugging tool.我似乎无法弄清楚 Chrome 调试工具。

I have chrome version 21.0.1180.60 m.我有 chrome 版本 21.0.1180.60 m。

Steps I took:我采取的步骤:

  1. I pressed ctrl-shift-i to bring up the console.我按下 ctrl-shift-i 调出控制台。
  2. Clicked on Sources then select the relevant javascript file that I want to debug.单击 Sources,然后单击 select 我要调试的相关 javascript 文件。
  3. I set breakpoints where I want the code to stop by putting a blue tag on the gutter next to the line on the left.我通过在左侧行旁边的排水沟上放置一个蓝色标记来设置我希望代码停止的断点。
  4. I clicked on the button on my webpage (which is a php rendered page) that initiates the javascript code.我单击了网页上的按钮(这是一个 php 渲染页面),该按钮启动了 javascript 代码。
  5. The code ran successfully without stopping.代码没有停止就成功运行。

I also noticed that the Watch Expressions don't work either.我还注意到 Watch Expressions 也不起作用。 It keeps telling me that the variable that I want to watch is undefined.它一直告诉我,我想看的变量是未定义的。

Further testing found that it's my code that's causing the breakpoint to fail.进一步测试发现是我的代码导致断点失败。 It seems that it fails on the "$("#frmVerification").submit(function(){" line. It doesn't step into the breakpoints inside that function().似乎它在“$("#frmVerification").submit(function(){" 行上失败了。它没有进入该函数() 内的断点。

Below is the:以下是:

//function to check name and comment field 
var test = "this is a test";
var test2 = "this is another test";

function validateLogin(){
    //if(userEmail.attr("value") && userPass.attr("value"))
        return true;
    //else
        //return false;
}

//onclick on different buttons, do different things.
function ajaxRequest(){

}
$(document).ready(function(){
  //When form submitted
    $("#frmVerification").submit(function(){
        var username = $("#username");
        var token = $("#token");
        var action = $("#action");
        var requester = $("#requester");
        if(validateLogin()){
            $.ajax({
            type: "post",
            url: "verification.php",
            data: "username="+username.html()+"&token="+token.val()+"&action="+action.val()+"&requester="+requester.val(),
            success: function(data) {
                try{
                    var jsonObj = $.parseJSON(data); //convert data into json object, throws exception if data is not json compatible
                    if(jsonObj.length > 0){//if there is any error output all data
                        var htmUl = $('<ul></ul>');
                        $.each(jsonObj, function(){
                            htmUl.append('<li>' + this + '</li>');
                        });
                        $("#errOut").html(htmUl);
                    }else{
                        alert("Your account is now activated, thank you. If you have already logged in, press OK to go to the home page. If not, you must log in first.");
                        window.location.replace("home.php");
                    }
                }
                catch(e){//if error output error to errOut]
                    $("#errOut").html("PHP module returned non JSON object: <p>"+data+"</p>");
                }
            }
        });
    }
    else alert("Please fill UserName & Password!");
        return false;
    });
});

I'm not sure why your breakpoints aren't hitting, but one sure-fire way to step into your code is to type我不确定为什么您的断点没有命中,但是进入您的代码的一种可靠方法是键入

debugger;

where you want the code to halt, and then run again with the chrome developer tools window open.您希望代码停止的位置,然后在 chrome 开发人员工具窗口打开的情况下再次运行。


Just one small thing to be aware of, be sure to clean up after you done and remove the debugger lines.只需注意一件小事,请务必在完成后清理并删除调试器行。 If you ever run JavaScript files through YUI compressor, the existence of a debugger;如果您曾经通过 YUI 压缩debugger;运行 JavaScript 文件,那么debugger;的存在debugger; line will cause it to error out.行会导致它出错。

This is a late answer, but I had the same problem, but the answer was different.这是一个迟到的答案,但我遇到了同样的问题,但答案不同。

In my case, there was a sourceURL reference in my code:就我而言,我的代码中有一个 sourceURL 引用:

//@ sourceURL=/Scripts/test.js

When this Javascript file is minified and loaded by the browser, it normally tells Chrome Dev Tools where the unminified version is.当这个 Javascript 文件被浏览器缩小并加载时,它通常会告诉 Chrome Dev Tools 未缩小版本的位置。

However, if you are debugging the unminified version and this line exists, Chrome Dev Tools maps to that sourceURL path instead of the "normal" path.但是,如果您正在调试未缩小版本并且此行存在,则 Chrome Dev Tools 会映射到该 sourceURL 路径而不是“正常”路径。

For example, if you work locally on a web server, then in the Sources tab in Chrome Dev Tools, the path to a given JS file will be http://localhost/Scripts/test.js例如,如果您在本地 Web 服务器上工作,则在 Chrome Dev Tools 的 Sources 选项卡中,给定 JS 文件的路径将为http://localhost/Scripts/test.js

If test.js has this at the bottom如果 test.js 在底部有这个

//@ sourceURL=/Scripts/test.js

then breakpoints will only work if the file path is /Scripts/test.js , not the fully-qualified URL of http://localhost/Scripts/test.js那么断点只有在文件路径是/Scripts/test.js时才有效,而不是http://localhost/Scripts/test.js的完全限定 URL

In Chrome 38, staying with my example above, if you look at the Sources tab, every file runs off http://localhost/ , so when you click on test.js, Chrome loads up http://localhost/Scripts/test.js在 Chrome 38 中,继续我上面的示例,如果您查看 Sources 选项卡,每个文件都会从http://localhost/ ,因此当您单击 test.js 时,Chrome 会加载http://localhost/Scripts/test.js

You can put all the breakpoints you want in this file, and Chrome never hits any of them.你可以把所有你想要的断点放在这个文件中,Chrome 永远不会命中它们中的任何一个。 If you put a breakpoint in your JS before it calls any function in test.js and then step into that function, you will see that Chrome opens a new tab whose path is /Scripts/test.js .如果在调用 test.js 中的任何函数之前在 JS 中放置一个断点,然后进入该函数,您将看到 Chrome 打开一个新选项卡,其路径为/Scripts/test.js Putting breakpoints in this file will stop the program flow.在此文件中放置断点将停止程序流程。

When I got rid of the @ sourceURL line from the JS file, everything works normally again (ie the way you would expect).当我从 JS 文件中删除@ sourceURL行时,一切又正常工作(即您期望的方式)。

I got a similar problem.我遇到了类似的问题。 Breakpoints where not working unless I used debugger;除非我使用debugger;否则断点不起作用debugger; . . I fixed my breakpoints problem with "Restore defaults and reload".我用“恢复默认值并重新加载”修复了我的断点问题。 It's located in the Chrome Developer Tools, Settings, Restore defaults and reload.它位于 Chrome 开发者工具、设置、恢复默认值和重新加载中。

Probably this bug https://code.google.com/p/chromium/issues/detail?id=278361可能是这个错误https://code.google.com/p/chromium/issues/detail?id=278361

This is reproduced with my Chrome 31.0.1650.57 (Official Build 235101) on Linux.这是在 Linux 上用我的 Chrome 31.0.1650.57(官方版本 235101)重现的。

I'm restarting browser to fix it.我正在重新启动浏览器以修复它。

Make sure the script with the "debugger;"确保脚本带有“调试器”; statement in it is not blackboxed by Chrome.其中的声明没有被 Chrome 黑盒化。 You can go to the Sources tab to check and turn off blackboxing if so.如果是这样,您可以转到“源”选项卡检查并关闭黑盒。

EDIT: Added screenshot.编辑:添加了屏幕截图。

如何关闭黑盒。

I met this several times, at first it works well by localhost, suddenly, the breakpoints don't work, i switch to 127.0.0.1, then it works again.我遇到过几次,起初它在本地主机上运行良好,突然间,断点不起作用,我切换到 127.0.0.1,然后它再次运行。 Hope helps.希望有所帮助。

I encountered similar problems in both chrome and firefox though it may not be the solution for your issue.我在 chrome 和 firefox 中都遇到了类似的问题,尽管它可能不是您问题的解决方案。 Am sharing here in the hopes it may help others.我在这里分享希望它可以帮助其他人。 I have encountered this situation before in other unrelated projects but never understood why until it cropped up again today.我之前在其他不相关的项目中遇到过这种情况,但一直不明白为什么,直到今天再次出现。

Scenario:设想:

I have one page that uses two bootstrap modals that come from the same source and one set of javascript files (blueimp's awesome jquery fileupload).我有一个页面使用来自同一来源的两个引导模式和一组 javascript 文件(blueimp 的很棒的 jquery 文件上传)。

  • BS Modal 1 is rendered on page load (via php) and is always present on the page. BS Modal 1 在页面加载时呈现(通过 php)并且始终出现在页面上。 It is used for adding a new related record.它用于添加新的相关记录。 (CakePHP....think SalesForcey type stuff) (CakePHP ......想想 SalesForcey 类型的东西)

  • BS Modal 2 is used for editing existing related records and it's html content is pulled in from an ajax call and appended to the DOM via jQuery. BS Modal 2 用于编辑现有的相关记录,它的 html 内容从 ajax 调用中提取并通过 jQuery 附加到 DOM。

  • Javascript supporting both modals included via standard html <script> tags. Javascript 支持通过标准 html <script>标签包含的两种模式。

I noticed that breakpoints are only triggered on Modal 1. They do not work when the code is being executed on the dynamically added Modal 2, even though it is quite obvious that the code is indeed being evaluated and run.我注意到断点仅在 Modal 1 上触发。当代码在动态添加的 Modal 2 上执行时,它们不起作用,即使很明显代码确实正在评估和运行。 Alert boxes pop up, codey type things get executed and output follows the logic set forth in the code.弹出警告框,codey 类型的东西被执行,输出遵循代码中规定的逻辑。

I have not dived deeper to investigate further because I'm pressed for time, but wanted to put it out there and give back to the community.由于时间紧迫,我没有深入研究以进一步调查,但我想将其发布并回馈社区。

PS: I use SO all the time, but this is my first post, so go easy on me :-) PS:我一直在使用 SO,但这是我的第一篇文章,所以请放轻松 :-)

Make sure that you're using the same host in the URL that you were when you set up the mapping.确保您在 URL 中使用与设置映射时相同的主机。 Eg if you were at http://127.0.0.1/my-app when you set up and mapped the workspace then breakpoints won't work if you view the page via http://localhost/my-app .例如,如果您在设置和映射工作区时位于http://127.0.0.1/my-app ,那么如果您通过http://localhost/my-app查看页面,断点将不起作用。 Also, thanks for reading this far.另外,感谢您阅读到这里。 See my answer to the Chromium issue here . 在此处查看我对 Chromium 问题的回答。

make sure that you have opened javascript console(or sources) in your chrome window.确保您已在 chrome 窗口中打开了 javascript 控制台(或源代码)。 otherwise it will never hit the breakpoint.否则它永远不会到达断点。 you can open javascript console by option button in right upper corner-->tools-->javascript console.您可以通过右上角的选项按钮打开javascript控制台-->工具-->javascript控制台。

I had an issue where Chrome's breakpoints weren't firing anything.我遇到了一个问题,Chrome 的断点没有触发任何东西。 When I tried to use 'debugger' in my code, I could only step through the code in the VM version of my code.当我尝试在我的代码中使用“调试器”时,我只能在我的代码的 VM 版本中单步执行代码。 My issue was that I was mapping the resources incorrectly.我的问题是我错误地映射了资源。 Re-mapping fixed my problem.重新映射解决了我的问题。

My solution was to clear the Local Storage, Session Storage, and Cookies from the Applications tab.我的解决方案是从应用程序选项卡中清除本地存储、会话存储和 Cookie。 After that, Chrome would pause script execution on the breakpoints defined in Sources.之后,Chrome 会在 Sources 中定义的断点上暂停脚本执行。

  1. Click on the Applications tab of Google Chrome点击谷歌浏览器的应用程序标签
  2. Right-click on the URL under each folder > Clear右键单击每个文件夹下的 URL > 清除

Screenshot: Applications tab屏幕截图:应用程序选项卡

我有一个压缩debugger正在剥离debugger语句¯_(ツ)_/¯

Make sure you are putting breakpoint in correct source file.确保将断点放在正确的源文件中。 Some tools create multiple copies of code and we try on different source file.一些工具会创建多个代码副本,我们会尝试不同的源文件。

Solution: Instead of opening file using shortcut like Ctrl+P or Ctrl+R , open it from File Navigator.解决方案:不要使用Ctrl+PCtrl+R等快捷方式打开文件,而是从文件导航器打开它。 In Source tab, there is icon for it at left top.在源选项卡中,左上角有它的图标。 Using it we can open correct source file.使用它我们可以打开正确的源文件。

This may be a Chrome bug.这可能是 Chrome 的错误。 Unfortunately Chrome routinely breaks debugging.不幸的是,Chrome 经常中断调试。 It often has some kind of memory leak and it often breaks or changes every few releases.它通常有某种内存泄漏,并且每隔几个版本就会中断或更改。

Debugging with formatted sources is currently extremely unreliable.使用格式化源进行调试目前非常不可靠。

It's possible you're also trying to break on dead code.您也有可能试图破解死代码。

To be certain it's not the browser you should also try to debug it in firefox.为了确定它不是浏览器,您还应该尝试在 firefox 中调试它。

So, in addition to Adam Rackis' answer, if you have errors in your javascript file above the breakpoint, you won't reach it regardless if you flag it, or put in debugger;因此,除了 Adam Rackis 的回答之外,如果您在断点上方的 javascript 文件中有错误,无论您是标记它还是放入debugger; ,您都不会到达它debugger; . .

Here's an example:下面是一个例子:

if (nonExistentVar === "something") {
  console.log("this won't happen as the above errors out");
}
debugger;
console.log("this won't print either")

as I experienced with chrome we need to open browser console to make debugger run when loading page.正如我在使用 chrome 时所经历的那样,我们需要打开浏览器控制台才能在加载页面时运行调试器。

put this somewhere in javascript file you want to run把它放在你想运行的javascript文件中的某个地方

debugger

open browser console and reload page.打开浏览器控制台并重新加载页面。

debugger will run like example image below调试器将像下面的示例图像一样运行

在此处输入图片说明

我不确定它是如何工作的,但是按 F1 进行设置并在右下角按“恢复默认值并重新加载”对我有用。

Pretty late answer but none of the above helped my case and was something different答案很晚,但以上都没有帮助我的情况,并且有所不同

while referring the javascript file type="text/javascript" was missing in the legacy application i was working在引用 javascript 文件类型 =“text/javascript”时,我正在工作的旧应用程序中缺少

<script  src="ab.js" ></script>

below one worked and breakpoints were hitting as expected低于一个工作并且断点按预期击中

 <script  src="ab.js" type="text/javascript"></script>

I need my damn breakpoints!我需要我该死的断点! Very strange behavior - the normally red spot in Sources was going grey;非常奇怪的行为 - Sources 中通常的红点变灰了; these and debugger;这些和debugger; breakpoints would still appear to hit but show somewhere in some non-executable HTML.断点仍然会出现,但会显示在某些不可执行的 HTML 中。

After a couple hours of hacking away code the breakpoints were finally being hit correctly, however had more or less just the equivalent of "Hello World" left.经过几个小时的破解代码,断点终于被正确命中,但或多或​​少只剩下相当于“Hello World”的东西。 Hahaha.哈哈哈。

So I had some serverside data being output in the page (in my case in a @razor statement), but it would be the same in any similar case.所以我在页面中输出了一些服务器端数据(在我的例子中是@razor 语句),但在任何类似的情况下都是一样的。

There was some incorrectly formed 0A/0D chars in the server output - the old carriage returns - causing Chrome the confusion with its own line numbering.服务器输出中有一些格式不正确的 0A/0D 字符 - 旧的回车 - 导致 Chrome 与自己​​的行号混淆。

Cleaning the server injected HTML and I got my breakpoint.清理服务器注入的 HTML,我得到了断点。

Now let's see how much of this code I can CTRL-Z back...现在让我们看看我可以 CTRL-Z 返回多少这段代码......

I'll add yet another random answer just because this question came up in response to my several searches.我将添加另一个随机答案,因为这个问题是针对我的几次搜索而提出的。 I have jQuery objects that have public and private methods.我有具有公共和私有方法的 jQuery 对象。 The pattern is:图案是:

myObject = (function($){
  function publicFunction() {}
  function privateFunction() {}
  return {
    theOnlyMethod: publicFunction
  }
})(jQuery);

If I put a breakpoint on a line inside a private function, Chrome will not debug it, the line moves down to the return statement!如果我在私有函数内的一行上放置断点,Chrome 将不会调试它,该行会向下移动到 return 语句! So to debug, I have to expose the private functions!所以为了调试,我必须公开私有函数! This is new to me this morning (8/20/2020, Version 84.0.4147.125 (Official Build) (64-bit)), I can't believe I've not run into this in 3 years.今天早上这对我来说是新的(2020 年 8 月 20 日,版本 84.0.4147.125(官方版本)(64 位)),我不敢相信我已经 3 年没有遇到过这个了。

I encountered this issue, and I realized that in my case it had to do with the dev tools using cached version.我遇到了这个问题,我意识到在我的情况下它与使用缓存版本的开发工具有关。

Adding a debugger statement would indeed cause it to break but it would point the cursor to a wrong line (although the tooltips variables values were actually correct).添加调试器语句确实会导致它中断,但它会将 cursor 指向错误的行(尽管工具提示变量值实际上是正确的)。

Forcing the option "Empty Cache and Hard Reload" on the refresh button (on top left of the browser, see image) did the trick for me, and the breakpoints started to work as expected.强制刷新按钮上的选项“空缓存和硬重新加载”(在浏览器的左上角,见图)对我有用,断点开始按预期工作。

“空缓存和硬重新加载”图像

I am struggling debugging a rouge Bootstrap Modal popup, but I found the "debugger" tag to help me get the debugger started.我正在努力调试一个 rouge Bootstrap Modal 弹出窗口,但我找到了“调试器”标签来帮助我启动调试器。 In my case the BS modal is being triggered by a piece of code I can't seem to find, so I wanted to see what the stack was when the modal was "show.bs.modal", this is the event that fires right before the modal is shown.在我的情况下,BS 模态是由我似乎找不到的一段代码触发的,所以我想看看当模态为“show.bs.modal”时堆栈是什么,这是正确触发的事件在模态显示之前。 I opened the Chrome developers console, and typed this code directly into the console to trigger the debugger to open at this event:我打开了 Chrome 开发者控制台,直接在控制台中输入了这段代码来触发调试器在这个事件中打开:

$('#myModal').on('show.bs.modal', (e) => {
    debugger;
});

Now just as my BS modal is shown, the debugger kicks in and I can see the stack.现在就像我的 BS 模态显示一样,调试器启动,我可以看到堆栈。 Of course the stack isn't showing me what caused the event to trigger, so I have to dig deeper, but for others this is a good way to debug some DOM object without directly modifying your code.当然,堆栈没有向我显示导致事件触发的原因,所以我必须更深入地挖掘,但对于其他人来说,这是调试某些 DOM object 而不直接修改代码的好方法。

I had the same issue in a 10K line file.我在 10K 行文件中遇到了同样的问题。 The breakpoints were being ignored,断点被忽略,
hard coded _debugger statements worked, but they can't be toggled and can be annoying when placed in a loop.硬编码的 _debugger 语句可以工作,但它们不能被切换,并且在放入循环时会很烦人。 My solution, which is a bit of a hack but it works is to add the following to the top of the file:我的解决方案有点麻烦,但它的工作原理是将以下内容添加到文件顶部:

let myDebuggerFlag = false;
let myDebugger = function () {
    if (myDebuggerFlag) {
        debugger;
    }
}

then I add a myDebugger();然后我添加一个 myDebugger(); inline where I would usually use a breakpoint.内联我通常会使用断点的地方。

to turn debugging on i simply enter myDebuggerFlag = true;要打开调试,我只需输入 myDebuggerFlag = true; on the console line.在控制台线上。 (you have to step out of myDebugger first of course. (当然,您必须先退出 myDebugger。

nothing worked until i restart the computer.在我重新启动计算机之前没有任何效果。

when nothing work : restart当没有任何工作时:重新启动

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

相关问题 Chrome javascript 调试器断点不起作用 - Chrome javascript debugger breakpoints are not working Chrome调试器将忽略VScode Javascript断点 - VScode Javascript Breakpoints are ignored by Chrome debugger 无法使用 Debugger for Chrome 在 Visual Studio Code 中放置断点 - Can't place breakpoints in Visual Studio Code with Debugger for Chrome 在 Chrome 和 VS Code 中,断点不会留在调试器中 - Breakpoints do not stay on their line in debugger both in Chrome and VS Code 在Javascript中,如果if语句不返回任何内容,则什么也不做 - In Javascript, if the if statement don't return anything, then do nothing JavaScript调试器; 语句即使启用了断点也不起作用 - JavaScript debugger; statement doesn't work even if breakpoints are enabled 使用Aptana调试器的javascript无法使用设置断点 - javascript using Aptana debugger can't set breakpoints using ajax 和 php 什么都不做 - ajax with php don't do anything Javascript不起作用,但是在放置断点并从chrome调试器工具中单击文件时可以正常工作 - Javascript not working but works fine when put breakpoints and click the file from chrome debugger tools 为什么 Visual Studio javascript 断点在萤火虫中不起作用? - Why don't visual studio javascript breakpoints work in firebug?
 
粤ICP备18138465号  © 2020-2024 STACKOOM.COM