如何防止当前浏览器窗口关闭时 Chrome 开发工具关闭?

我正在尝试使用 chrome 开发工具来调试一个问题,我与 Twitter 的誓言。

当宣誓窗口出现时,我打开开发人员工具来监视请求-但是一旦宣誓窗口关闭,开发人员工具窗口也会关闭。我希望能够保持开发人员工具窗口打开,以便我可以检查所提出的请求。

这可能吗?

53482 次浏览

Try using remote debugging: https://developers.google.com/chrome-developer-tools/docs/remote-debugging In this case Developer Tools will be opened in a separate browser tab that won't be closed automatically.

Also consider setting a breakpoint in the code that closes the window if you can find it.

Not a perfect solution, but you can add breakpoints on the events Window.close and unload by turning on the checkboxes at:

Developer tools -> "Sources" tab -> Event Listener Breakpoints -> Window -> close

And

Event Listener Breakpoints -> Load -> unload

Try to mark both and see which one works best for you

Another option is to manually add a breakpoint yourself. Open up your closes-too-quickly window, open up JS console, and:

window.addEventListener('unload', function() { debugger; })

But it all comes down to exactly what the window is doing, and when exactly you want to stop things, so experimenting with Event Listener Breakpoints in the Sources tab, as in @jfhfhf839's answer, is a good idea too.

In my case (debugging Google OAuth flow), neither Window -> Close nor Load -> Unload did the trick, but Script > Script First Statement was useful, though I had to resume execution a few times before I got to where I wanted.

Just press F8 before closing and pause, then add breakpoints.