Sourcemap in DevTools : change styles without losing the link to the SASS/Less file? - css

When I use sourcemap with DevTools for CSS, is it possible to change styles without losing the link to the preprocessing file?
More explanation
Step 1 : I inspect an element, I see its style and I can see a link "global.scss", perfect.
Step 2 : I change a style (like a pixel under), and I lose my "global.scss" link, now is "global.css" and I need to reload my page!

No, that is not possible, see https://developer.chrome.com/devtools/docs/css-preprocessors:
Changes made in an external editor are not detected by DevTools until the Sources tab containing the associated source file regains focus. Also, manual editing of a CSS file generated by the Sass/LESS/other compiler will break the source map association until the page is reloaded

This is an issue reported on chromium bug tracker, there you can follow the progress https://code.google.com/p/chromium/issues/detail?id=257778#makechanges
EDIT 1
Finally this issue is currently resolved in Chrome Canary :-)
Link to confirmation: https://code.google.com/p/chromium/issues/detail?id=257778#c61
EDIT 2
Source map finally landed in Chrome

Related

Visual Studio 2022 ASP.NET Core 6 Default application and Add folder to workspace in Chrome DevTools is not working anymore

After some update to either Visual Studio (I have the same issue in both VS2019 and VS2022) or Chrome I can no longer update the CSS in DevTools and have it reflect and persist the changes to site.css file in my project. Instead when I try to change a CSS property I get the following in the DevTools console:
Unable to find a stylesheet to update. Updating all local css files.
15:54:01.800 aspnetcore-browser-refresh.js:82
And the green dot disappears from my CSS pane immediately after I hit the up or down arrow on my keyboard to try and change the CSS value.
Why is that? It used to work not too long ago. I think it's been broken for me for half a year or so now.
I've been googling but haven't find any good resources. Or maybe I'm the only one coding directly in Chrome? :) Surely this can't be the case?
If anyone knows a workaround please share because I'm really frustrated atm :)
Disabling "Enable CSS Auto-Sync" seems to do the trick.
Update 1: The above no longer works for me for some reason. I managed to find another fix on SO: https://stackoverflow.com/a/70096917/687549
And here are some screenshots:
Update 2: Update 1 works when you only need to update the CSS directly in Chrome. It's better to have Hot Reload enabled and the set the following setting to None - then you'll get the best of both worlds (Hot Reload + Edit CSS directly in Chrome using workspaces): https://stackoverflow.com/a/68954979/687549
Update 3: I'm now using VSCode. If none of the above works try the following (block .js file in Network tab in Chrome DevTools): https://stackoverflow.com/a/68966524/687549

Why I need to reload my CSS to display it properly ?

I have built a stylesheet but it doesn't appears on the page on the first load. It needs a reload to appear properly. However when I look to the source download on the dev console's network tab, I see the CSS is well downloaded. So what can lead to the non-display of my CSS on the first load since it is well loaded in a CSS module-hash's mode ?
Any hint would be great,
thanks

Chrome not loading CSS source maps?

Until recently, my Chrome browser was loading CSS source map files correctly. Now, it is not.
The setting is on:
And the CSS files have a source mapping tag at the bottom:
/*# sourceMappingURL=Home.cshtml.css.map */
But the Network tab and Fiddler2 show that Chrome is not even trying to load the source map file.
Is there something that I'm missing? Is the sourceMappingURL syntax correct? I've toggled the "Enable CSS source maps" setting on and off.
Chrome version: 44.0.2403.30 beta-m
Sourcemap files generated by Web Essentials in VS 2013.
You can try the following steps:
1- delete the map file and regenerate it again.
2- Using the chrome inspector, go to Settings > General and then click on the button "Restore defaults and reload"
When the CSS file has the sourcemapping embedded as base64, then it seems to work fine.
For example:
/*# sourceMappingURL=data:application/json;base64,eyJ2....5235== */
OMG! The problem made me crazy! I found that the CSS file is not complete.
Here is what I did to solve the problem:
Make sure that CSS maps are enabled in Dev tools settings.
Check the end of CSS file whether it contains a link to the source map.
Press Shift + Click on the refresh button to force resources update.
Your code seems to be okay, the only reason why it is not reflecting the changes because you are loading the cached CSS file. To load the new CSS file, you need to hold shift and press the reload button to ask chrome to reload all the files instead of to loading it from the cash.
Does each scss file need to be accesible from the outside to make this work? I have css maps configured but I have see that each .scss file that is being processed is not accesible from the browser

chrome developer mode style sidebar linked css no more

In my Google Chrome version 38.0.2125.104, stylesheet filename/linked css has been disappeared. I'm not sure if updated version removed this or there is somewhere to set this up again, but when i restored to default, still it does not appear.
To make it clear to you guys, This is an example of old version Style Panel which have the link to the related stylesheet (filename & line) next to the class name.
http://i.pictr.com/7g52x66rw8.png (i cant attach images here yet)
and below is the latest Style Panel. Each classes usually have link to the CSS stylesheet .
http://i.pictr.com/sks0tp1sem.png
Any idea on how to enable back the stylesheet link?
Thanks in advance.
when you open the inspect element on the top right side of the dev eloper tools panel you have a cog wheel (settings). click that and go to general setting s tab and check out the elements section and sources section and see if all the boxes that needs to be checked are checked.... in mine i have the source maps box checked and enabled

Export CSS changes from inspector (webkit, firebug, etc)

When I'm working with CSS, I'll often test in a browser - say, Chrome - right click an element, click Inspect Element, and edit the CSS right there. The use of arrow keys to change things like margin and padding makes lining things up super easy.
It's not too hard to then take those changes and apply them to the CSS file, but it would be cool if I could just right click the selector in the inspector and select "export" or "copy", and have the contents available in my clipboard.
Does something like this exist?
I have found the answer to this, at least as of Chrome v14.
While in the Elements section, just click on the "filename:linenumber" link next to the CSS rules. The CSS file that shows up will contain all of the modifications.
This place exactly:
In Chrome, you can right-click a CSS file in the Sources tab and click "Local Modifications"
This shows you all of your local changes. Each revision is timestamped and you can rollback to any previous revision.
See the Live Editing and Revision History section of this tutorial.
Firediff is a Firebug add-on that tracks changes done in Firebug. It logs everything you'll do in the HTML pane (great) but also your brief use of the Web Developer Toolbar extension (not so great), say Shift-Ctrl-F to obtain a font-size information in px.
I have seen a Firebug extension in Chrome but didn't test it, I use Firediff with Firefox.
In Chrome there is also the Changes tab in the console drawer that displays all the modifications of CSS. It's not an export, but at least it is very convenient to quickly grasp what has changed.
I built a Chrome extension that does exactly this.
It's called StyleURL - it takes whatever CSS changes you made in Chrome Inspector and outputs valid CSS as the diff: https://chrome.google.com/webstore/detail/styleurl/emplcligcppnlalfjknjbanolhlnkmgp
Here's an example where I added "padding-bottom: 50px" to this page:
It's open-source and on GitHub too: https://github.com/Jarred-Sumner/styleurl-extension
Both Firefox and Chrome support this feature now, but worth to note that in some platforms if not all Chrome does not show it by default, you need to enable the "Changes" view to see it (in my Kubuntu Linux 20.04 it wasn't by default), here is how you can enable it: go to the "Customize and Control DevTools" button in the Developer Tools bar > "More tools" > "Changes", then the tab will appear at the button:
In Firefox there is no need to enable it, but if you come from the Chrom* world may be hard to find it. Just check the last section in the right at the "Inspector" tab:
I've suggested this product on SO before (I'm not affiliated with them in any way).
http://www.skybound.ca/
Excellent product. Sounds like exactly what you're looking for and much more.
EDIT: Several other answers here have mentioned Google Chrome's ability to link to your local files (which is very very cool). Check out the other answers!
If you edit external CSS, then you can drag its latest revision out of the Resources panel into any text editor that supports DnD (see http://www.webkit.org/blog/1463/web-inspector-styles-enhanced/, the "Persisting Changes" section for more detail.) You can also revert your CSS changes to any earlier version of the stylesheet resource (in the right-click popup menu of any stylesheet revision.)
As mentioned by cloudworks, the answer to this has changed. This can now be accomplished rather well by the Chrome DevTools Autosave extension. This tool tracks CSS and JavaScript changes made within the Chrome Developer Tools console, and saves them back to local files. For instructions to install and setup the extension, please refer to the guide written by #addyosmani on his blog, here.
There is also a handy screencast which details the extension rather well.
With Workspaces you can have your CSS saved as you type them in your inspector (in Chrome). The problem is that every change is automatically saved and there's no way to disable this feature, as pointed in http://www.html5rocks.com/en/tutorials/developertools/revolutions2013/ and Disable automatic saving of CSS changes in Chrome Developer Tools.
My in-beta-soon product LIVEditor does this exactly.
To let you understand it easily, you can think of Firebug's inspector is embedded into your text editor.
That way you don't have to make the changes manually again in your code editor after you tweaking it using Firebug or Webkit's developer tools.
If you're using the Firefox stock dev tools you can edit the css directly in the tools dialog - click the CSS viewport button (that's the button at the top with the {} symbol) and edit your css directly. It will update in realtime in the browser and when you're done just copy-paste it directly into your css file. Nice!
To add an answer for Safari specifically — it's kind of possible.
When you edit CSS in the Styles section in the Inspector for an existing CSS file, you can hit Cmd-S to re-save the entire file with the changes. However, if you're using a meta language like Sass / preprocessor / generating your CSS with bundling etc, I don't think this really solves that problem, though it may be possible with CSS source maps.
When you edit CSS at the top of the Styles section, under Style Attribute to add inline styles (not tied to an existing CSS file), it doesn't seem possible to easily export all of those changes. For now, I'm just copying and pasting the overrides manually for each element.
The official Apple docs are a little dated but found here: Web Inspector Tutorial - Editing Code to Change Your Webpage.
In Chrome, in the css inspector you can click and hold the + button, then choose to add your changes to the inspector-stylesheet. It's not as convenient as directly editing in your css-selectors, but what you write will all be in inspector-stylesheet.css

Resources