| title | Edit files with Workspaces (Filesystem tab) |
|---|---|
| description | How to save changes made within DevTools to disk. |
| author | MSEdgeTeam |
| ms.author | msedgedevrel |
| ms.topic | conceptual |
| ms.prod | microsoft-edge |
| ms.date | 05/04/2021 |
This tutorial provides hands-on practice in setting up and using a Workspace. After you add files to a Workspace, the changes that you make in your source code within DevTools are saved on your local computer, and are preserved after you refresh the webpage.
Before beginning this tutorial, you should know how to do the following:
- Use html, CSS, and JavaScript to build a web page
- Use DevTools to make basic changes to CSS
- Run a local HTTP web server
Workspaces enable you to save a change that you make in Devtools to a local copy of the same file on your computer. For this tutorial, you should have the following settings on your machine.
-
You have the source code for your site on your desktop.
-
You are running a local web server from the source code directory, so that the site is accessible at
localhost:8080. -
You opened
localhost:8080in Microsoft Edge, and you are using DevTools to change the CSS of the site.
With Workspaces enabled, the CSS changes that you make within DevTools are saved to the source code on your desktop.
If you are using a modern framework, it probably transforms your source code from a format that is easy to maintain into a format that is optimized to run as quickly as possible.
Workspaces is usually able to map the optimized code back to your original source code with the help of source maps. But there is a lot of variation between frameworks over how each framework uses source maps. Devtools doesn't support all of the variations.
The Workspaces feature doesn't work with the Create React App framework.
Local Overrides is another DevTools feature that is similar to Workspaces. Use Local Overrides when you want to experiment with changes to a webpage, and you need to display the changes across webpage loads, but you don't care about mapping your changes to the source code of the webpage.
We'll set up the demo and then set up DevTools.
-
Create an
appdirectory on your desktop. Save copies of theindex.html,styles.css, andscript.jsfiles from the demo source code to theappdirectory. For the rest of the tutorial, the directory is referred to as~/Desktop/app. -
Start a local web server in
~/Desktop/app. Below is some sample code for starting upSimpleHTTPServer, but you can use whatever server you prefer.cd ~/Desktop/app python -m SimpleHTTPServer # Python 2
cd ~/Desktop/app python -m http.server # Python 3
-
Open a tab in Microsoft Edge and navigate to the locally hosted version of the site. You should be able to access it using a URL like
localhost:8080orhttp://0.0.0.0:8080. The exact port number might be different.
-
Press
Ctrl+Shift+J(Windows, Linux) orCommand+Option+J(macOS) to open the Console panel of DevTools. -
Navigate to the Sources tool.
-
In the Navigator pane (on the left), click the Filesystem tab.
-
Click Add Folder To Workspace.
-
Type
~/Desktop/app. -
Click Allow to give DevTools permission to read and write to the directory.
In the Filesystem tab, a green dot now appears next to index.html, script.js, and styles.css. A green dot indicates that DevTools has established a mapping between a network resource of the page, and the file in ~/Desktop/app.
-
Open
styles.css. Thecolorproperty ofh1elements is set tofuchsia. -
Select the Elements tool.
-
Change the value of the
colorproperty of the<h1>element to your favorite color. To do this, select the<h1>element in the DOM Tree.The CSS rules that are applied to the
<h1>element are shown in the Styles pane. The green dot next tostyles.css:1means that any change that you make are mapped to~/Desktop/app/styles.css. -
Open
styles.cssin a text editor again. Thecolorproperty is now set to your favorite color. -
Refresh the page.
The color of the <h1> element is still set to your favorite color. The change remains across a refresh, because when you made the change DevTools saved the change to disk. And then, when you refreshed the page, your local server served the modified copy of the file from disk.
You can change HTML tagging using the Elements tool, but to be able to save the edits, we'll use the Sources tool.
You can make changes to the HTML content in the Element tool, but your changes to the DOM tree aren't saved to disk, and only affect the current browser session.
The DOM tree is not the HTML source tagging.
If you want to save a change to the HTML of the webpage, use the Sources tool.
-
Navigate to the Sources tool.
-
In the Navigator pane (on the left), click the Page tab.
-
Click (index). The HTML for the page opens.
-
Replace
<h1>Workspaces Demo</h1>with<h1>I ❤️ Cake</h1>. Review the following figure. -
Press
Ctrl+S(Windows, Linux) orCommand+S(macOS) to save the change. -
Refresh the page. The
<h1>element continues to display the new text after the page is refreshed. -
Open
~/Desktop/app/index.html. The<h1>element contains the new text.
The main place to use the code editor of DevTools is the Sources tool. But sometimes you need to access other tools, such as the Elements tool or the Console panel, while editing files. The Quick source tool gives you just the editor from the Sources tool, while any tool is open.
To open the DevTools code editor alongside other tools:
-
Navigate to the Elements tool.
-
Press
Ctrl+Shift+P(Windows, Linux) orCommand+Shift+P(macOS). The Command Menu opens. -
Type
quick, and then select Show Quick source. At the bottom of the DevTools window, the Quick source tool appears, displaying the contents ofindex.html, which is the last file you edited in the Sources tool. -
Press
Ctrl+P(Windows, Linux) orCommand+P(macOS) to open the Open File dialog, as shown below. -
Type
script, then select app/script.js.[!NOTE] The
Save Changes To Disk With Workspaceslink in the demo is styled regularly. -
Add the following code to the bottom of script.js using the Quick source tool.
console.log('greetings from script.js'); document.querySelector('a').style = 'font-style:italic';
-
Press
Ctrl+S(Windows, Linux) orCommand+S(macOS) to save the change. -
Refresh the page. The link on the page is now italicized.
Use what you have learned in this tutorial to set up Workspaces in your own project.
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.









