Logo Questions Linux Laravel Mysql Ubuntu Git Menu
 

Chrome Dev Tools - Mapping network resource to local file not working

Is Local file mapping dev tools alternative to Charles proxy in firefox? I am trying to map a remote server resource to a local file, but it doesn't seem to be working. The console statements and changes in the JS file doesn't seem to be applied when I reload the page.

I can see the local folder and file listed in the sources folder. Also, see that the sources doesn't show the original JS file. But I see this message in the sources tab for the local file.

Workspace mapping mismatch

Rest of the warning states that the file in local folder is different from the remote loaded file. Why is that a problem, wouldn't that be always the case, since you want to edit the file locally?

What am I missing? Any pointers to fixing this? Is my assumption wrong that this feature in chrome dev tools can allow loading a resource locally, as if it was loaded from the original location?

I tested this again with a simple html page with a single js file having a simple console log statement - "loading remote file ...". This file is mapped to a local js with a different log statement "loading local file.." However, I still see the log message from the remote file.

Added snapshot from dev tools sources tab for more context. Sources tab shows the local folder and file correctly, but shows the mapping warning. Also notice that sources doesn't have the remote.js file anymore. Snapshot from dev tools sources tab

like image 392
3coins Avatar asked Oct 22 '14 18:10

3coins


People also ask

What is the difference between transferred and resources in Chrome DevTools Network tab?

"Transferred" is the compressed size of all resources. You can think of it as the amount of upload and download data that a mobile user will use in order to load this page. "Resources" is the uncompressed size of all resources.

How do I troubleshoot Chrome developer tools?

Alternatively, you can access the Chrome developer tools by clicking on the three dots at the top-right corner of the screen. Head to More tools and select Developer tools. Another option is to right-click on the web page and click on the Inspect option.

How do I add Source Maps to Chrome?

All modern browsers offer complete support for source maps. If you are using Google Chrome, you can easily see the available source maps by clicking on the “Sources” tab in the Chrome dev tools.


2 Answers

Is my assumption wrong that this feature in chrome dev tools can allow loading a resource locally, as if it was loaded from the original location?

I don't think this is accurate. When you map a file on a server to your local workingspace, Chrome acts as a sort of editor for your local files. You can edit the files through Chrome and Command+S to save your local files. But nothing has changed on the server. It doesn't update the files on the server, and it doesn't tell Chrome to "Use my local files instead of what's on the server".

What many people do is automate the deployment process so that when a local file is updated (either through Chrome + Workspace Mapping or just simply by editing in your editor), your working copy gets deployed. That way, next time you reload the browser, you'll see your edits.

Edit: From the workspace documentation:

And you can map resources served from a local web server to files on disk, so when you change and save those files, you can view them as if they were being served.

I think the key here is local web server. I did a bit more digging and found this dev tools docs issues, with a comment effectively saying that what you're trying to do isn't supported:

The DevTools currently does not do resource substitution. It can simply map the remote files to your local copy so if things are kept in sync (like using a local server on-system) then when refreshing your modifications can persist.

Looks like you'll need a way to deploy after making changes or have your devtools workspace point to the server docroot.

like image 183
dontGoPlastic Avatar answered Oct 15 '22 22:10

dontGoPlastic


The Charles Proxy "map local" feature was requested of the Chromium team in this issue and the team declined to pursue it.

like image 22
Ben Creasy Avatar answered Oct 15 '22 22:10

Ben Creasy