chrome devtools 调试反应,命中 "refresh" 导致调试卡住
chrome devtools debug react, hit "refresh" cause debug stuck
我不使用任何远程调试(webstorm 和 devtools)
只需使用 chrome devtools
当调试在 devtools 中的断点处停止时
点击“ctrl+r”刷新也卡住了(标签空白,调试会话无法重启)
<!DOCTYPE html>
<html>
<head>
<meta charset="UTF-8"/>
</head>
<body>
<script src="../node_modules/react/umd/react.development.js"></script>
<script src="../node_modules/react-dom/umd/react-dom.development.js"></script>
<div id="root"></div>
<script>
var e = React.createElement
class App extends React.Component {
render() {
return e("div")
}
}
const domContainer = document.querySelector('#root');
ReactDOM.render(e(App), domContainer);
</script>
</body>
</html>
更新:
这是我的解决方案:
更新:
我向 chrome 团队报告了这个错误,请帮我投票这个问题:https://bugs.chromium.org/p/chromium/issues/detail?id=1134899#c_ts1603534836
旧:
我猜这是 chrome 错误,所以这是我的 tmp 解决方案
简而言之,使用chrome扩展api“结束进程”当前选项卡进程,然后重新加载,与手动相同chrome>任务管理器 > 结束进程,然后点击重新加载
详细:
使用chrome.processes, it require latest chrome dev channel(不是chrome稳定版)
chrome.processes.terminate
终止当前标签进程
chrome.tabs.onUpdated
监听“ctrl+r”reload事件,当reload“localhost”devurl时,先“end process”再reload
以下是我的部分解决代码(完整代码很长所以省略了,但你可以参考自己制作代码)
/**
*
*/
import {CrxAsync} from "./node_modules/ro-crx/src/index.js"
class ForceReloadInLocalhost extends CrxAsync {
constructor() {
super()
chrome.processes.onExited.addListener(() => {
this.startReload()
})
}
start(tab) {
if (tab == null) {
this.getCurTab((curTab) => {
this.start(curTab)
})
} else {
this.tabId = tab.id;
var tabId = this.tabId
if (tab.url.match(/localhost/)) {
this.killProcess(tabId, (status) => {
if (status == "not_process") {
this.startReload()
}
})
} else {
this.startReload()
}
}
}
startReload() {
if (this.tabId) {
this.reload(this.tabId, {}, () => {
this.tabId = null
})
}
}
}
var forceReload = new ForceReloadInLocalhost()
chrome.commands.onCommand.addListener((cmd) => {
if (cmd == "forceReload") {
forceReload.start()
}
})
var isForceReload = true
chrome.tabs.onUpdated.addListener((tabId, changeInfo, tab) => {
if (tab.url.match(/^https?:\/\/localhost/)) {
if (changeInfo.url == undefined /* it means is reload, so url doesn't change*/ && changeInfo.status == "loading") {
if (!isForceReload) {
isForceReload = true
forceReload.start(tab);
} else {
isForceReload = false
}
}
}
})
我发现 this workaround 有类似的问题:
- 尝试以隐身模式打开开发者工具
- 在 devtools 中选择另一个选项卡
- 关闭隐身模式window
- 再次尝试使用常规开发工具
我不使用任何远程调试(webstorm 和 devtools)
只需使用 chrome devtools
当调试在 devtools 中的断点处停止时
点击“ctrl+r”刷新也卡住了(标签空白,调试会话无法重启)
<!DOCTYPE html>
<html>
<head>
<meta charset="UTF-8"/>
</head>
<body>
<script src="../node_modules/react/umd/react.development.js"></script>
<script src="../node_modules/react-dom/umd/react-dom.development.js"></script>
<div id="root"></div>
<script>
var e = React.createElement
class App extends React.Component {
render() {
return e("div")
}
}
const domContainer = document.querySelector('#root');
ReactDOM.render(e(App), domContainer);
</script>
</body>
</html>
更新:
这是我的解决方案:
更新: 我向 chrome 团队报告了这个错误,请帮我投票这个问题:https://bugs.chromium.org/p/chromium/issues/detail?id=1134899#c_ts1603534836
旧: 我猜这是 chrome 错误,所以这是我的 tmp 解决方案
简而言之,使用chrome扩展api“结束进程”当前选项卡进程,然后重新加载,与手动相同chrome>任务管理器 > 结束进程,然后点击重新加载
详细:
使用chrome.processes, it require latest chrome dev channel(不是chrome稳定版)
chrome.processes.terminate
终止当前标签进程
chrome.tabs.onUpdated
监听“ctrl+r”reload事件,当reload“localhost”devurl时,先“end process”再reload
以下是我的部分解决代码(完整代码很长所以省略了,但你可以参考自己制作代码)
/**
*
*/
import {CrxAsync} from "./node_modules/ro-crx/src/index.js"
class ForceReloadInLocalhost extends CrxAsync {
constructor() {
super()
chrome.processes.onExited.addListener(() => {
this.startReload()
})
}
start(tab) {
if (tab == null) {
this.getCurTab((curTab) => {
this.start(curTab)
})
} else {
this.tabId = tab.id;
var tabId = this.tabId
if (tab.url.match(/localhost/)) {
this.killProcess(tabId, (status) => {
if (status == "not_process") {
this.startReload()
}
})
} else {
this.startReload()
}
}
}
startReload() {
if (this.tabId) {
this.reload(this.tabId, {}, () => {
this.tabId = null
})
}
}
}
var forceReload = new ForceReloadInLocalhost()
chrome.commands.onCommand.addListener((cmd) => {
if (cmd == "forceReload") {
forceReload.start()
}
})
var isForceReload = true
chrome.tabs.onUpdated.addListener((tabId, changeInfo, tab) => {
if (tab.url.match(/^https?:\/\/localhost/)) {
if (changeInfo.url == undefined /* it means is reload, so url doesn't change*/ && changeInfo.status == "loading") {
if (!isForceReload) {
isForceReload = true
forceReload.start(tab);
} else {
isForceReload = false
}
}
}
})
我发现 this workaround 有类似的问题:
- 尝试以隐身模式打开开发者工具
- 在 devtools 中选择另一个选项卡
- 关闭隐身模式window
- 再次尝试使用常规开发工具