简体   繁体   English

在使用断点进行调试时强制使用chrome来刷新页面

[英]Force chrome to refresh a page while debugging with breakpoints

If I have a breakpoint in a loop or frequent interval I can't refresh chrome without forcing a reload with ctrl-r . 如果我在循环或频繁的间隔中有一个断点,我不能刷新chrome而不强制使用ctrl-r重新加载。

Hitting F5 /clicking the refresh button will do a normal refresh, loading just the modified content, unless the debugger has paused on a breakpoint in which case the debugger continues. F5 /单击刷新按钮将执行正常刷新,仅加载修改后的内容,除非调试器在断点处暂停,在这种情况下调试器将继续。 Holding/spamming F5 just cycles through breakpoints and I can't refresh the page after spotting a bug and making code changes. 保持/发送垃圾邮件F5只是循环通过断点,我发现错误并进行代码更改后无法刷新页面。 I'd prefer not to do a full reload ( ctrl-r ) because I have images and other content that get cached and don't need to be re-downloaded. 我不想完全重新加载( ctrl-r )因为我有图像和其他内容被缓存而不需要重新下载。

One solution is to close the debugger, refresh and then open the debugger. 一种解决方案是关闭调试器,刷新然后打开调试器。 However, the JS then gets a chance to run before the debugger is back up. 但是,JS在调试器备份之前有机会运行。 I then have to refresh again so the JS runs from the beginning. 然后我必须再次刷新以便JS从头开始运行。

Has anyone found a workaround? 有没有人找到解决方法?

It could be just me, but I frequently want to make changes to my code and debug it at the same time. 它可能只是我,但我经常想要更改我的代码并同时调试它。


  • Refresh: F5 刷新: F5

  • No, actually refresh: 不,实际刷新: 锤子 + F5 ? + F5

What works for me is to CMD + R (I'm on OS X) then F8 . 对我有用的CMD + R (我在OS X上),然后是F8

It seems that reload is done only after you pass the current breakpoint. 似乎只有在传递当前断点后才会重新加载。

Right click on refresh button. 右键单击刷新按钮。 Then choose one of the reload options. 然后选择其中一个重新加载选项。

Have you tried running the following from the Console? 您是否尝试从控制台运行以下命令?

window.location.reload() window.location.reload()

What would reload only the content of the page, and not web inspector. 什么会重新加载页面的内容,而不是web检查器。

A simple solution could be to use the "Deactivate breakpoints" button. 一个简单的解决方案是使用“Deactivate breakpoints”按钮。 This will let the flow happen without stopping. 这将使流程不停地发生。

Then you can use the F5 to just reload the changes. 然后,您可以使用F5重新加载更改。

UPDATE UPDATE

Given you want to have breakpoints enabled as soon as you load the page, you can do following. 如果您希望在加载页面后立即启用断点,则可以执行以下操作。

  1. Set a global flag = true in your page. 在页面中设置全局标志= true。 Say, window.shouldbreak = true; 说,window.shouldbreak = true;
  2. Set up your breakpoints as "conditional breakpoints" as described here Chrome Dev Tools Debugging Javascript . 将断点设置为“条件断点”,如此处所述Chrome Dev Tools调试Javascript Of course your condition will be if(window.shouldbreak === true) then break else proceed. 当然你的条件是if(window.shouldbreak === true)然后打破其他的继续。
  3. Run your regular debugging flow. 运行常规调试流程。
  4. Once done. 一旦完成。 In console set window.shouldbreak = false; 在控制台集window.shouldbreak = false; Now the debugger won't stop at any of the breakpoints for current session. 现在,调试器不会在当前会话的任何断点处停止。
  5. On page reload with F5 , because the variable is set again in the page, you have your breakpoints working again 在页面上使用F5重新加载,因为在页面中再次设置变量,您的断点会再次运行

This is to echo @Munteanu Sergiu's answer. 这是为了回应@Munteanu Sergiu的回答。 Here is a screenshot on OS/X. 这是OS / X上的屏幕截图。

在此输入图像描述

In Chrome, Debug Toolbar, go to settings icon at the bottom left corner (or on the toolbar header) and choose disable cache. 在Chrome的“调试工具栏”中,转到左下角(或工具栏标题)上的设置图标,然后选择“禁用缓存”。 then try reloading. 然后尝试重新加载。

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

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