admin管理员组

文章数量:1323348

What is a good way to debug a popup window in Chrome? I need to debug some code that is run when the window is opened and I was wondering if there was a better way to debug it than pressing f12 as soon as the window opens. I'm looking for something similar to using Visual Studio where you can open a window, set a breakpoint on some JS, then open the window back up and VS will break on that breakpoint without you having to do anything.

If it can be done some way on Firefox I'd switch to that, as long as I don't have to use IE.

What is a good way to debug a popup window in Chrome? I need to debug some code that is run when the window is opened and I was wondering if there was a better way to debug it than pressing f12 as soon as the window opens. I'm looking for something similar to using Visual Studio where you can open a window, set a breakpoint on some JS, then open the window back up and VS will break on that breakpoint without you having to do anything.

If it can be done some way on Firefox I'd switch to that, as long as I don't have to use IE.

Share Improve this question asked Nov 25, 2013 at 17:00 sheodoxsheodox 8351 gold badge10 silver badges17 bronze badges 10
  • Did you enter a debugger statement in the page you want to look at? – Mike Cheel Commented Nov 25, 2013 at 17:41
  • Yes, but if the dev tools aren't open it won't break. Which brings me back to the same problem unfortunately. – sheodox Commented Nov 25, 2013 at 17:49
  • What is preventing you from opening the devtools and then opening the page? I do this all the time. – Mike Cheel Commented Nov 25, 2013 at 18:16
  • I need to debug some initialization code on a popup window, not just a normal page. – sheodox Commented Nov 25, 2013 at 18:29
  • After putting the debugger statement in your code you should be able to go to the initial page BEFORE opening the popup, open the chrome debugger and then launch the popup which should then break on the debugger statement. – Mike Cheel Commented Nov 25, 2013 at 18:51
 |  Show 5 more ments

2 Answers 2

Reset to default 5

Nowadays there's an option in the Chrome devtools settings. "Auto-open DevTools for popups".

Check that checkbox, then if you have devtools open on the parent window and that opens a popup or new tab devtools will automatically open in that window/tab.

Short Answer:

"Ctrl + click"

Long Answer:

I had the same problem. It seems that it's a bug in Google Chrome and there's nothing we can do about it until it is fixed in future versions. I found a way around it, though, which is not an actual solution but solved my problem.

1) Close the popup window.

2) Open it again using "Ctrl + click" instead of just clicking on the link to the popup window.

3) The window will be opened in a new normal tab.

4) Now you can press F12 and go to debug mode.

Hope this solves someone else's problem too.

本文标签: Debugging JavaScript in popup windows on ChromeStack Overflow