description | title | author | ms.author | ms.date | ms.topic | ms.prod | keywords |
---|---|---|---|---|---|---|---|
With F12 Developer Tools, learn how to debug an extension's background script, content scripts, and extension pages. |
Extensions - Debugging extensions |
abbycar |
abigailc |
03/08/2017 |
article |
microsoft-edge |
edge, web development, html, javascript, developer, debug, debugging |
You can debug your extensions in Microsoft Edge by using F12 Developer Tools.
The following video goes through a buggy Microsoft Edge extension, walking though each debugging scenario and fixing it up along the way. See the step-by-step instructions below for more info.
[!VIDEO https://channel9.msdn.com/Blogs/One-Dev-Minute/Debugging-Microsoft-Edge-Extensions/player]
Note
In order to take advantage of extension debugging with F12, you must first turn on developer features in about:flags. See Adding and removing extensions for details on how to do this.
To start debugging the background script of your extension:
- Click on More (...) followed by Extensions to go into the extension pane.
- Click on the extension that you want to debug.
- Click on the Background page link to bring up F12 for the background process.
- Select the Debugger tab in F12.
- Navigate to and select your extension's background script.
- Place breakpoints for debugging by clicking to the left of the source code line number.
- Select the Console tab and execute the command "
location.reload()
". This will re-execute the background script, allowing you to step through your code.
To start debugging the content script of your extension:
- Launch F12 by either navigating to the More (...) button and selecting "F12 Developer Tools" or by pressing F12 on your keyboard.
- Navigate to and select your extension's content script. Content scripts for extensions currently running will be depicted by a different folder for each extension.
Note
Only running content scripts will appear.
- Place breakpoints for debugging by clicking to the left of the source code line number.
- Refresh the browser tab to begin stepping though your code.
There are two methods that can be used for accessing the source code of your extension page for debugging. One method applies to a variety of pages while the other only works for popup pages.
The following method works for all extension pages like the options page and popups:
-
Right-click on the background of your page.
-
Select "View source".
-
Once F12 opens, place breakpoints within the file you want to debug.
-
Select the Console tab and execute the command
location.reload()
. This will re-execute the page script, allowing you to step through your code.
While the method for debugging extension pages also applies to popup extension pages, the following steps outline another way to debug your popup:
- Right-click your extension's icon.
- Select "Inspect popup".
3. Follow steps 3 and 4 above for placing breakpoints and reloading the popup.