javascript 使用断点调试时强制 chrome 刷新页面
声明:本页面是StackOverFlow热门问题的中英对照翻译,遵循CC BY-SA 4.0协议,如果您需要使用它,必须同样遵循CC BY-SA许可,注明原文地址和作者信息,同时你必须将它归于原作者(不是我):StackOverFlow
原文地址: http://stackoverflow.com/questions/22279615/
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
Force chrome to refresh a page while debugging with breakpoints
提问by jozxyqk
If I have a breakpoint in a loop or frequent interval I can't refresh chrome without forcing a reload with ctrl-r
.
如果我在循环或频繁间隔中有断点,我无法在不强制使用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. Holding/spamming F5
just cycles through breakpoints and I can't refresh the page after spotting a bug and making code changes. 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.
点击F5
/单击刷新按钮将进行正常刷新,仅加载修改后的内容,除非调试器在断点处暂停,在这种情况下调试器将继续。保留/垃圾邮件F5
只是在断点之间循环,在发现错误并更改代码后我无法刷新页面。我不想完全重新加载 ( 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. I then have to refresh againso the JS runs from the beginning.
一种解决方案是关闭调试器,刷新然后打开调试器。但是,JS 将有机会在调试器恢复之前运行。然后我必须再次刷新,以便 JS 从头开始运行。
Has anyone found a workaround?
有没有人找到解决方法?
It could be just me, but I frequently want to make changes to my code anddebug it at the same time.
可能只有我一个人,但我经常想对我的代码进行更改并同时对其进行调试。
Refresh: F5
No, actually refresh:
+F5?
刷新: F5
不,实际上刷新:
+ F5?
回答by avetisk
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.
似乎只有在您通过当前断点后才完成重新加载。
回答by Munteanu Sergiu
Right click on refresh button. Then choose one of the reload options.
右键单击刷新按钮。然后选择重新加载选项之一。
回答by thinkbigthinksmall
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.
什么只会重新加载页面的内容,而不是网络检查器。
回答by Anshul
A simple solution could be to use the "Deactivate breakpoints" button. This will let the flow happen without stopping.
一个简单的解决方案是使用“停用断点”按钮。这将使流动发生而不会停止。
Then you can use the F5to just reload the changes.
然后您可以使用F5来重新加载更改。
UPDATE
更新
Given you want to have breakpoints enabled as soon as you load the page, you can do following.
鉴于您希望在加载页面后立即启用断点,您可以执行以下操作。
- Set a global flag = true in your page. Say, window.shouldbreak = true;
- Set up your breakpoints as "conditional breakpoints" as described here Chrome Dev Tools Debugging Javascript. Of course your condition will be if(window.shouldbreak === true) then break else proceed.
- Run your regular debugging flow.
- Once done. In console set window.shouldbreak = false; Now the debugger won't stop at any of the breakpoints for current session.
- On page reload with F5, because the variable is set again in the page, you have your breakpoints working again
- 在您的页面中设置全局标志 = true。说,window.shouldbreak = true;
- 将您的断点设置为“条件断点”,如Chrome Dev Tools Debugging Javascript 中所述。当然你的条件是 if(window.shouldbreak === true) 然后 break else 继续。
- 运行您的常规调试流程。
- 一旦完成。在控制台中设置 window.shouldbreak = false; 现在调试器不会在当前会话的任何断点处停止。
- 在页面重新加载时F5,因为在页面中再次设置了变量,所以您的断点再次工作
回答by Tzunghsing David Wong
回答by Prakash S
In Chrome, Debug Toolbar, go to settings icon at the bottom left corner (or on the toolbar header) and choose disable cache. then try reloading.
在 Chrome 中,调试工具栏,转到左下角(或工具栏标题)的设置图标,然后选择禁用缓存。然后尝试重新加载。