Chrome developer tools workspace mappings

前端 未结 3 1663
既然无缘
既然无缘 2020-12-01 01:47

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

相关标签:
3条回答
  • 2020-12-01 02:02

    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.

    0 讨论(0)
  • 2020-12-01 02:02

    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.

    0 讨论(0)
  • 2020-12-01 02:18

    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();
            }
        }
    
    0 讨论(0)
提交回复
热议问题