38

Can anyone tell me how the Chrome developer tools workspace mappings work. I believe it is only available in Canary at the moment.

I thought it is supposed to allow me to make changes to the CSS rules in the elements view and have them automatically saved to the local files as demonstrated by Paul Irish at Google IO 2013. I can't get this functionality to work.

https://developers.google.com/events/io/sessions/325206725

Mike
  • 3,855
  • 5
  • 30
  • 39
  • Does this answer your question? [How to save CSS changes of Styles panel of Chrome Developer Tools?](https://stackoverflow.com/questions/6843495/how-to-save-css-changes-of-styles-panel-of-chrome-developer-tools) – GorvGoyl Nov 03 '19 at 18:59

4 Answers4

57

It works only in canary at the moment.

EDIT: Now in Chrome (since ver 30+)

1) you need to open devtools settings panel. It has 'Workspace' section.

Screenshot of settings page

2) in this section you need to click on 'Add folder' item. It will show folder selection dialog.

3) After selecting a folder you will see an info bar about access rights for the folder.

Screenshot of access rights infobar

4) As a result you will see two top level elements in the Source panel file selector pane. In my case it were localhost:9080 site and devtools local file system folder. At this moment you need to create a mapping between site files and your local files. You can do that via context menu on a file.

Mapping screenshot

It doesn't matter what file to map, local or site file.

5) at that moment devtools will ask you about restart. restart screenshot

After restart devtools will show you the singe folder entry in the files pane and will apply all the changes you do to the local file each time when you press Ctrl + S or Cmd + S on mac.

Community
  • 1
  • 1
loislo
  • 14,025
  • 1
  • 28
  • 24
  • 2
    I should have explained that I did all the above steps and it still was not working when I was using "codeavengers.com" as my server. ("codeavengers.com" is mapped to localhost in my windows hosts file). When I changed to using localhost in my urls it worked as described above. However, JavaScript debugging seemed to stop working. – Mike May 19 '13 at 22:08
  • I subsequently opted to install the Chrome extension Tincr. So far it works great. http://addyosmani.com/blog/lets-tincr-bi-directional-editing-and-saving-with-the-chrome-devtools/ – Mike May 19 '13 at 22:11
  • You need to check carefully that mapping is applied. It could happen that your site structure doesn't reflect the local folders structure. Also you need to have two mappings for two urls, one for localhost and another for codeavengers.com. If devtools can't map a local file to a site file then it can't set a breakpoint inside it. – loislo May 20 '13 at 04:19
  • 5
    It now appears to be in the normal Chrome release. I'm running version 30.0.1599.101 – Greg Tatum Oct 29 '13 at 21:27
  • @Mike I had a similar problem with the debugging... It worked for a while then suddenly stopped. Did Tincr Fix this? – ford prefect Dec 09 '13 at 15:56
  • It is possible to do this for a folder instead of a single resource? – Willem de Wit Dec 11 '13 at 09:43
  • 4
    When you map a single resource DevTools actually maps everything. – loislo Dec 16 '13 at 13:31
  • In order to get JavaScript debugging working without the extension, I had to remove version numbers I was appending at the end of javascripts files after ?. Now I only append the version numbers when we build and deploy a new version. The local version excludes version numbers. – Mike Jul 04 '15 at 21:39
  • @Mike That's exactly what's happening to me, I have build #s appended to the end of the JS `?v=1.2.3` causing issues. Thanks man – Mark Pieszak - Trilon.io Nov 18 '15 at 19:56
  • Today everybody uses all kinds of compilers for `css` and `js` - compass, sass, babel, webpack, browserify, etc, etc, etc. I use `comapss`, for example. It has only one `main.scss` file that includes all necessary `_partials.scss` files. Now pls tell me how do I map my `main.scss` (or whatever `.scss` file I don't know which one, you name it) to enable this Chrome Devtools feature? Or it doesn't work with compilers, only with plain vanilla `.css`? – Green Feb 18 '16 at 06:22
4

Just a correction on what loislo has said. "It works only in canary at the moment."

You can trigger all these experimental features in stable chrome releases by typing Chrome://flags in the address bar.

Vennsoh
  • 4,853
  • 5
  • 26
  • 41
1

Can anyone tell me how the Chrome developer tools workspace mappings work?

In current version of Chrome (I have version 80) the manual mapping option is gone. In the DevTools under Settings > Workspace it only says "Mappings are inferred automatically". From what I found the automatic mapping considers the following characteristics:

(1) Resource name and file name must be equal.
(2) Resource content and file content must be equal.
(3) The header field "Last-Modified" of the resource must be equal to the last modification date of the file on the file system.

Note that for (2) also the encoding must be the same. For example mixing "UTF-8" and "UTF-8 with BOM" will not work.

(3) Was not true in my case because I served the resource using a custom HttpServlet (Java), in which this header field was not set. Now I set this header field in my HttpServlet and the workspace mapping in Chrome is working. Simplified example:

    @Override
    protected void doProcess(HttpServletRequest httpRequest, HttpServletResponse httpResponse) throws IOException
    {

        try
        {
            // (1) file_name must be equal to the queried resource name of the website.
            String path = "path/to/the/file_name.js";
            File file = new File(path);

            httpResponse.setContentType("application/javascript");
            // (3) the Last-Modified header field of the resource must match the file's last modified date
            httpResponse.setDateHeader("Last-Modified", file.lastModified());

            // (2) the content of the resource must match the content of the file
            // Note: CopyStream is a utility class not part of standard Java. But you get the idea ;)
            CopyStream.copyAll(new FileInputStream(path), httpResponse.getOutputStream());
        }
        catch (Exception ex)
        {
            ex.printStackTrace();
        }
    }
mihca
  • 997
  • 1
  • 10
  • 29
-1

For me I just needed to update Chrome (there was a light red "update" button that I'd been ignoring for some time).

user6096790
  • 380
  • 4
  • 8