Debug popup.html of a Chrome Extension?

JavascriptDebuggingGoogle Chrome-Extension

Javascript Problem Overview


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?

Javascript Solutions


Solution 1 - Javascript

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

Solution 2 - Javascript

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.

Solution 3 - Javascript

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.

Solution 4 - Javascript

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

Solution 5 - Javascript

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.

Attributions

All content for this solution is sourced from the original question on Stackoverflow.

The content on this page is licensed under the Attribution-ShareAlike 4.0 International (CC BY-SA 4.0) license.

Content TypeOriginal AuthorOriginal Content on Stackoverflow
QuestionSkizitView Question on Stackoverflow
Solution 1 - JavascriptTimCodes.NETView Answer on Stackoverflow
Solution 2 - JavascriptTom NView Answer on Stackoverflow
Solution 3 - JavascriptPavel HlobilView Answer on Stackoverflow
Solution 4 - JavascriptaCodeView Answer on Stackoverflow
Solution 5 - JavascripthypersView Answer on Stackoverflow