Change made in developer tools remains after refreshing the page - javascript

I inspected an element on the webpage through Chrome dev tools. I added to the styling: "font-weight:normal". I didn't mean for it to be permanent but now the change won't go away. It remains after refreshing. So whenever I inspect the element, that element isn't bolded like it's supposed to be. But when I got to the actual file in my source code, there's no "font-weight:normal" code.
What's going on? Why is the change remaining? How can I revert changes?

Try clearing your browser cache. And open and close your dev tools.

Problem resolved. I guess I had compiled my SCSS file into a CSS file where the "font-weight:normal" was saved. So when I was trying to change my SCSS file and didn't see changes in the webpage, I was confused. However, when I recompiled the SCSS file into CSS, I see that everything it working as it should and the browser reflects correct code changes as I recompile.

1) Try to open in a new tab and see if the changes stick
2) You are saying your source code doesn't reflect this change- make sure you the browser is loading the file you are editing (maybe you made a copy of it?)

Related

How to see all of scripts on Chrome's dev tool?

Hello. I'm fixing some scripts from website which made by other one.
First I should look all of existing scripts but chrome dev tool doesn't show all of the source code in script tag.
I tried to copy it but still copied with "...".
I searched some keyword from the whole webpage code and I can find it in hidden part so maybe Chrome get a full script but just not showing to me.
How can I see all of scripts?
Double click the ellipsis or single click on the arrow to expand the script region:
You could also try right click and copy the outer HTML or you can edit the node as HTML inline... Explore the other options available to you in the context menu:
NOTE: If you are editing an existing web page you should probably start with the source code for the site and use an HTML code editor to edit the page and scripts, otherwise any changes you make wont be fixing the site for all users, the changes will be just for you.

Website - Keeps reverting back to old version after changes have been made?

So I've created my website using HTML, CSS, Javascript, Bootstrap and PHP. Now I created a basic website and I decided to change a few things on it. So I have done this by opening up Notepad++ and changing things like spelling and glyphicons and then I save the changes and then click run in Notepad++ and all is great in the browser. Changes applied successfully. Then I go back to my folder and open with either chrome, IE or firefox and again great the change was successful.
Though as soon as I click on a tab to got to another newly changed page the changes aren't there and it's reverted back to an older version. Then I'll click to go back to the page I was just on and it will have one or two of the features I've just changed but the rest has reverted.
But if I go back into the folder or Notepad++ and run the index.html or about.html file then it's fine again until I navigate the pages then it starts reverting back.
I need help as this is such a pain and I have no idea why it's not just updating?
Any questions please just ask. Been at this for three days!
I think you should check if your hyperlinks are linking to the right pages. Maybe you renamed your pages? Make sure you run the right, changed, index.html from the right direction in your browser, not the old version.

I am bot able to edit the js file at runtime using chrome debugger

I tried to save the changes by inserting breakpoints and tried to reload the page,And added by changes in the form of alert messages but still the newly added alerts aren't visible.
You have to save the changes (Ctrl + S) you made to apply them, make sure you apply the changes before the code is executed (with a breakpoint)
the javascript is most likely cached by your browser and the new one is not being downloaded.
click Control +R in your browser to do a "strong refresh" it will redownload the website and the new js file

page source doesn't have dynamic div element

I am dynamically adding the content of "div" in jquery it is added in DOM. but in view page source i can't see dynamic content of an element
<div id="pdf"></div>
("#btn").click(function(){
$("#pdf").html("ffff");
});
how can i get updated page source after made dynamic changes. it is added in DOM but page source doesn't have the content ? why ?
Thanks,
Siva
The page source is the page source - a raw text file which cannot be changed. It is hosted on the server and it's obvious you can't made any changes to it. Once you visit a web page, your browser queries to read that text file and then it parses it to the DOM. When you do any javascript/jQuery magic like adding new html elements, you do it on the DOM.
that's just normal behavior, the source is allways the original source of the page and it doesn't show changes made after page load. If you want to check the source after changes use a tool like firebug or chrome developer tools.
EDIT:
As Johannes H stated you no longer require firebug since major browsers all include developer tools.
If you use Firefox you can get the "web developer" plugin, then view "generated source". This will show the jQuery added div.
When You are viewing the page source the javascript will not run, so the dynamic elements will not be added.
To get the sources you can use your browser developer tools:
click f12
choose the top element and press copy as html.

Editing in the Chrome debugger

How do I "dynamically" edit JavaScript code in the Chrome debugger? It's not for me, so I don't have access to the source file. I want to edit code and see what effects they have on the page, in this case stopping an animation from queuing up a bunch of times.
I came across this today, when I was playing around with someone else's website.
I realized I could attach a break-point in the debugger to some line of code before what I wanted to dynamically edit. And since break-points stay even after a reload of the page, I was able to edit the changes I wanted while paused at break-point and then continued to let the page load.
So as a quick work around, and if it works with your situation:
Add a break-point at an earlier point in the script
Reload page
Edit your changes into the code
CTRL + s (save changes)
Unpause the debugger
You can use the built-in JavaScript debugger in Chrome Developer Tools under the "Scripts" tab (in later versions it's the "Sources" tab), but changes you apply to the code are expressed only at the time when execution passes through them. That means changes to the code that is not running after the page loads will not have an effect. Unlike e.g. changes to the code residing in the mouseover handlers, which you can test on the fly.
There is a video from Google I/O 2010 event introducing other capabilities of Chrome Developer Tools.
You can use "Overrides" in Chrome to persist javascript changes between page loads, even where you aren't hosting the original source.
Create a folder under Developer Tools > Sources > Overrides
Chrome will ask for permission to the folder, click Allow
Edit the file in Sources>Page then save (ctrl-s). A purple dot will indicate the file is saved locally.
This is what you are looking for:
1.- Navigate to the Source tab and open the javascript file
2.- Edit the file, right-click it and a menu will appear: click Save and save it locally.
In order to view the diff or revert your changes, right-click and select the option Local Modifications... from the menu. You will see your changes diff with respect to the original file if you expand the timestamp shown.
More detailed info here: http://www.sitepoint.com/edit-source-files-in-chrome/
Chrome Overrides
Open the JS file in the sources panel.
Right Click on script src URL > Reveal in Sources panel
Make sure "Enable Local Overrides" is checked.
Right Click anywhere in the JS file > Save for overrides
All Set!
Just edit the file, and save with CMD/CTRL + S. Now whenever you refresh the page, it'll use the modified file. (As long as the filename remains the same)
You'll know it's working if you see a purple dot in the file icon.
Place a breakpoint
Right click on the breakpoint and select 'Edit breakpoint'
Insert your code. Use SHIFT+ENTER to create a new line.
Pretty easy, go to the 'scripts' tab. And select the source file you want and double-click any line to edit it.
If its javascript that runs on a button click, then making the change under Sources>Sources (in the developer tools in chrome ) and pressing Ctrl +S to save, is enough. I do this all the time.
If you refresh the page, your javascript changes would be gone, but chrome will still remember your break points.
As this is quite popular question that deals with live-editing of JS, I want to point out another useful option. As described by svjacob in his answer:
I realized I could attach a break-point in the debugger to some line of code before what I wanted to dynamically edit. And since break-points stay even after a reload of the page, I was able to edit the changes I wanted while paused at break-point and then continued to let the page load.
The above solution didn't work for me for quite large JS (webpack bundle - 3.21MB minified version, 130k lines of code in prettified version) - chrome crashed and asked for page reloading which reverted any saved changes. The way to go in this case was Fiddler where you can set AutoRespond option to replace any remote resource with any local file from your computer - see this SO question for details.
In my case I also had to add CORS headers to fiddler to successfully mock response.
Now google chrome has introduce new feature. By Using this feature You can edit you code in chrome browse. (Permanent change on code location)
For that Press F12 --> Source Tab -- (right side) --> File System - in that please select your location of code. and then chrome browser will ask you permission and after that code will be sink with green color. and you can modify your code and it will also reflect on you code location (It means it will Permanent change)
Thanks
Just like #mark 's answer, we can create a Snippets in Chrome DevTools, to override the default JavaScript. Finally, we can see what effects they have on the page.
here's a gentle introduction to the js debugger in chrome that i wrote. Maybe it will help others looking for info on this: http://meeech.amihod.com/getting-started-with-javascript-debugging-in-chrome/
you can edit the javascrpit files dynamically in the Chrome debugger, under the Sources tab, however your changes will be lost if you refresh the page, to pause page loading before doing your changes, you will need to set a break point then reload the page and edit your changes and finally unpause the debugger to see your changes take effect.
I was looking for a way to change the script and debug that new script. Way I managed to do that is:
Set the breakpoint in the first line of the script you want to change and debug.
Reload the page so the breakpoint is being hit
Paste your new script and set desired breakpoints in it
Ctrl+s, and the page will refresh causing that breakpoint in first line to be hit.
F8 to continue, and now your newly pasted script replaces original one as long as no redirections and reloads are made.
Chrome DevTools has a Snippets panel where you can create and edit JavaScript code as you would in an editor, and execute it.
Open DevTools, then select the Sources panel, then select the Snippets tab.
https://developers.google.com/web/tools/chrome-devtools/snippets

Categories