Web dev tools show you the code and source files in your web pages. They also let you type code into the source file. Is there a way to save those changes to the file?
For example, let's say I have mypage.html and myjavacript.js or myjavascript.ts and I am viewing it in the browser with web dev tools open. I then add console.log("hello world") to myjavascript.js. FYI The source code field is editable. I then click a button to save those changes. Then myjavascript.js is updated on the filesystem. I return to vscode and the javascript is updated.
Is this possible?
Currently, if I change the contents of the source file in web dev tools and use CTRL + S to save, an icon appears and the tool tip says, "Changes to this file were not saved to the filesystem".
The other question asks how to handle the error. My question asks how to save to the file system. Though some answers overlap it's not the same.
Possible answer (SO is not letting me add an answer because someone on this site closed this question):
It seems the answer is to add the source folder here:
Reopen this question so I can add an answer to, "How to save changes from web dev tools"
Update:
It doesn't work sometimes. Then one time I noticed a message across the top of the screen, "Allow dev tools to save to the file system? Warning, this could reveal sensitive information." with a yes or no option. Wait a second? What is this about? Why? I only want to allow web dev tools to save files to the hard drive. Why would this option be risky? Or why would you allow this option to be risky? I have tried to enable this feature since.
Use the workspaces feature. Read the full instructions and list of limitations (Ex. build toolchain transformations and source maps, editing HTML via sources panel vs elements panel) there. Open devtools, go to "Sources" > "Workspace", add a folder mapping, and then when prompted to allow devtools to access the directory, make sure you remove any sensitive info from that directory (Ex. secrets files), or are okay with the risk of allowing devtools to access it, and then allow it.
Why would this option be risky?
Depending on how much an application in any nesting of runtimes is sandboxed from the rest of your system / enclosing runtimes, running any arbitrary application is "risky".