title | author | ms.author | ms.date | ms.topic | ms.prod | keywords |
---|---|---|---|---|---|---|
Sources Panel Overview |
MSEdgeTeam |
msedgedevrel |
01/06/2020 |
article |
microsoft-edge |
microsoft edge, web development, f12 tools, devtools |
Use the Microsoft Edge DevTools Sources panel to:
- View files.
- Edit CSS and JavaScript.
- Create and save Snippets of JavaScript, which you can run on any page. Snippets are similar to bookmarklets.
- Debug JavaScript.
- Set up a Workspace, so that changes you make in DevTools get saved to the code on your file system.
Use the Page pane to view all of the resources that the page has loaded.
How the Page pane is organized:
- The top-level, such as
top
in Figure 1, represents an HTML frame. You'll findtop
on every page that you visit.top
represents the main document frame. - The second-level, such as
docs.microsoft.com
in Figure 1, represents an origin. - The third-level, fourth-level, and so on, represent directories and resources that were loaded from that origin. For example, in Figure 1 the full path to the resource
devtools-guide-chromium
isdocs.microsoft.com/en-us/microsoft-edge/devtools-guide-chromium
Click a file in the Page pane to view its contents in the Editor pane. You can view any type of file. For images, you see a preview of the image.
Viewing the contents of
a4d10f71.index-docs.js
in the Editor pane
Use the Editor pane to edit CSS and JavaScript. DevTools updates the page to run your new code. For example, if you edit a CSS file by adding the style rule below:
.metadata.page-metadata {
color: red;
}
you'll see that change take effect immediately.
Editing CSS in the Editor pane to change the text color of the subtitle to red
CSS changes take effect immediately, no save needed. For JavaScript changes to take effect, press Control
+S
(Windows) or Command
+S
(macOS). DevTools doesn't re-run a script, so the only JavaScript changes that take effect are those that you make inside of functions. For example, in Figure 4 note how console.log('A')
doesn't run, whereas console.log('B')
does. If DevTools re-ran the entire script after making the change, then the text A
would have been logged to the Console.
DevTools erases your CSS and JavaScript changes when you reload the page. See Set up a Workspace to learn how to save the changes to your file system.
Snippets are scripts which you can run on any page. Imagine that you repeatedly type out the following code in the Console, in order to insert the jQuery library into a page, so that you can run jQuery commands from the Console:
let script = document.createElement('script');
script.src = 'https://code.jquery.com/jquery-3.2.1.min.js';
script.crossOrigin = 'anonymous';
script.integrity = 'sha256-hwg4gsxgFZhOsEEamdOYGBf13FyQuiTwlAQgxVSNgt4=';
document.head.appendChild(script);
Instead, you can save this code in a Snippet and run it with a couple of button clicks, any time you need it. DevTools saves the Snippet to your file system.
To run a Snippet:
- Open the file via the Snippets pane, and click Run .
- Open the Command Menu, delete the
>
character, type!
, type the name of your Snippet, then pressEnter
.
See Run Snippets Of Code From Any Page to learn more.
Rather than using console.log()
to infer where your JavaScript is going wrong, consider using the Microsoft Edge DevTools debugging tools, instead. The general idea is to set a breakpoint, which is an intentional stopping place in your code, and then step through your code's execution, one line at a time. As you step through the code, you can view and change the values of all currently-defined properties and variables, run JavaScript in the Console, and more.
See Get Started With Debugging JavaScript to learn the basics of debugging in DevTools.
By default, when you edit a file in the Sources panel, those changes are lost when you reload the page. Workspaces enable you to save the changes that you make in DevTools to your file system. Essentially, this lets you use DevTools as your code editor.
See Edit Files With Workspaces to get started.
Note
Portions of this page are modifications based on work created and shared by Google and used according to terms described in the Creative Commons Attribution 4.0 International License.
The original page is found here and is authored by Kayce Basques (Technical Writer, Chrome DevTools & Lighthouse).
This work is licensed under a Creative Commons Attribution 4.0 International License.