80

I'm making a Chrome Extension and need to view the HTML/CSS/JS of the popup.html.

I can't right click to inspect elements. Is there another way? I need to make sure CSS and JavaScript is being inserted correctly. How to debug a problem in that popup file?

1

6 Answers 6

140

Right click the extension's button, then 'Inspect Popup'

6
  • 7
    In Chrome 22 (Canary on 8/1/2012), the 'Inspect Popup' option has been removed, probably because you can 'Inspect Element' from within the popup. However, because of this, there is no way to debug/set a breakpoint on code that runs on load. So far my only solution is to put a setTimeout for 10-15 seconds, which allows me time to open the popup, select 'Inspect Element', find the Scripts tag and set the breakpoint inside the timed-out function. Do you know of an easier way?
    – Schmuli
    Commented Jul 31, 2012 at 22:08
  • 5
    I don't know, sorry, I wish the chrome team would stop breaking things. Commented Aug 1, 2012 at 16:59
  • 13
    inspect the popup windows itself and then use location.reload(true) to relead it Commented Sep 27, 2013 at 3:12
  • 3
    Inspect popup is verified present in version 38, possibly in earlier versions as well. Commented Oct 26, 2014 at 14:26
  • 1
    This seems outdated. Please consider @Tom N's reply below.
    – lephleg
    Commented Nov 19, 2017 at 19:04
107

Inspect Popup has gone away with the latest build.

Here's how I debug Chrome Extension Popups.

  1. Click your popup button to see the webpage (the popup window itself).
  2. Right-click in the window and select Inspect element
  3. The Chrome Debugger window comes up with the right context, but you've already missed your breakpoints and debugger statements.
  4. HERE'S THE TRICK. Click on the Console part of the debugger and type: location.reload(true) and press enter.

Now your breakpoints are hit! Great way to reload changed scripts without revisiting the Extension page.

4
  • I do get the popup when I rightcilck on the page action icon.
    – ripper234
    Commented Nov 23, 2012 at 1:06
  • 5
    You can also just hit F5 while in the debugger, it triggers "reload" not "run". Though this should be considered as UI bug, since developers would expect F5 to "run", not "reload". So, beware of this helpful F5 has messed up some debuggings of mine too when hit at the wrong time. The latter also happens in Firefox. Commented Aug 30, 2015 at 0:07
  • 1
    In Chrome 47 not hitting breakpoints on extension load is still a problem, so your location.reload(true) tip is priceless! Commented Aug 31, 2015 at 1:37
  • This is a great workaround. Very often "Inspect Popup" will not hit breakpoints.
    – DShultz
    Commented Aug 2, 2018 at 17:45
40

Perhaps another way may be to find the ID: for your application in chrome://chrome/extensions/

You can then load your popup in a regular window by

chrome-extension://id_of_your_application/popup.html

Exchange popup.html for the file you have specified in manifest.json under "default_popup" property.

6
  • I tried it and it works if your extension is a popup. Here is an example of AdBlock popup link that runs in the browser. You must have AdBlock installed. chrome-extension://gighmmpiobklfepjocnamgkkbiglidom/button/popup.html Commented May 10, 2013 at 17:18
  • This is especially nice because Chrome reloads the popup page every time you click the toolbar button, and the "Inspect Popup" console is automatically closed whenever the popup is blurred.
    – chbrown
    Commented Oct 23, 2014 at 18:15
  • Some extensions do not have popup.html. You have to know the file's name before debugging.
    – Brian
    Commented Aug 22, 2015 at 8:03
  • Sweet! This and Tom N answer are priceless. Accepted answer is not the best, at all.
    – brasofilo
    Commented Feb 13, 2016 at 4:03
  • 1
    This totally gets around the issue of not being able to see initial requests in DevTools when the extension is first opened. Thanks! Commented Jul 3, 2018 at 5:15
2

Yes, 'Inspect Popup' on the extension icon, and apart from that - from extension manager you can also inspect your options page.

0
2

Try switching Auto-open DevTools for popups in the bottom right of DevTools Settings:

Auto-open DevTools

Another good way to inspect Javascript being part of the extension popup is adding special comments to the end of the script to be debugged:

// @sourceURL=popup.js

This is de-facto a directive for DevTools to include this specific file into Sources tab. From there you can inspect code, add breakpoints, output to console, etc. as usual.

0

One way to get the popup.js to be debugged is to let it first do its popup by pressing the extension icon at the tool bar. Then right click the popped window to get "Inspect" choice and the developer window opens. But then you need to be able to reload the page to get initial javascript breakpoints to work. At that developer page find Sources->Page then right click: Select 'Open in new tab'. Then open Devtools on that new full page and you can reload: enter image description here

Your Answer

By clicking “Post Your Answer”, you agree to our terms of service and acknowledge you have read our privacy policy.

Not the answer you're looking for? Browse other questions tagged or ask your own question.