How would I find this file if it didn't has breackpoint in it? Filename is axios-setToken.js and it is displayed in top tab, but not in navigator.
If you press Ctrl+P and start typing the filename, devtools should find the file and list it below; clicking it opens it. I use that often when files aren't listed in the navigation pane for whatever reason.
You see a message about this when there are no open editors:
Here for instance I've opened devtools on this SO page, opened a file (just to show that Ctrl+P works even when there's already an editor open), and typed the first three letters of "jQuery" since I know SO uses jQuery:
As you can see, it found jquery.min.js for me.
This is often handy even when files are listed in the navigator.
I need to debug my javascript using firebug or google chrome but my javascript is in the same file with the html, when I try to find my javascript code I dont know where is it becase it is not in a specific file it is in the same file with my html, if I use the firebug or google chrome debuger I find the script tab but then I dont know in what file is my javascript because it is not in a javascript file , how can I to find my javascript to debug?
The problem is because I am using ASP.MVC and I have only one view and many partial views that I put in the view, the view has a lateral menu when someone click on the option in the lateral menu one partial view is loaded next to the lateral menu, so this partial view has html and javascript but this new javascript in the partial view is not found for me in firebug or google chrome devtools because only is showed the firs html and script to the view and the code of partial view is not showed in these tools because this code was inserted dinamically and the firebug not refresh it.
What can be the solution?
Thanks.
You can know error in which line .look here
you can see file name and number of line error and when you click in name of file you will get
error line.
Go to the URL. For example, this page, I can put a break point in the file "debuging-with-firebug-or-google-chrome". I believe Google Chrome works similarly.
Also, they're sorted by domain, so that should help you find the URL's file.
Firefox build-in debugger (Main menu button > Developer > Debugger, or CTRL+SHIFT+S) lists all files that contains loaded scripts in left sidebar 'Sources'. It contains even html files if they contain <script> tag with content inside. You can check it out at stackoverflow.com.
The picture shows debugger with loaded html file.
Sometimes a file may be not present in the list because there were an error during loading of the script. Check "Console" tab to see any javascript errors. Similar feature (reporting errors to Console) also provide both Firebug and Chrome devtools.
Edit:
There is a bug / misleading behavior in both Firefox and Chrome. In order to see all scripts (especially those deferredly loaded) it is necessary to open debugger window before the page starts loading. Deferred scripts are shown only if the debugger is open by the time scripts are loaded.
Let's say the page http://www.example.com is opened in my browser. I click on the button button1 on that page that triggers
$('.popup').load(popupContentURL);
to be executed.
The new content is displayed in the popup. Everything is perfect.
The question is: the page popupContentURL has such a code inside:
<script type="text/javascript" src="jspopup.js"></script>
As result, when you click on the button button1, the javascript code from jspopup.js is being loaded and executed.
My question is: is there any way to debug jspopup.js from the Chrome console?
I wish to start debugging from the very first line.
The problem is that when I'm on the http://www.example.com and on the way to click the "button1" button, I can NOT set up a breakpoint inside the jspopup.js as it is not loaded yet.
All that files are not local. They are located at http://www.example.com .
Yes you can very well do that . The Chrome DevTools include a number of useful tools to help make debugging JavaScript less painful. Check here
In Chrome you can use the debugger; statement within your loaded code.
If you have the Chrome F12 developer console open it will break at that line so you can debug from that point onwards.
Lots of other useful tips here: https://developer.chrome.com/devtools/docs/javascript-debugging
I created a notification window using the Chrome Extension API:
var notification = webkitNotifications.createHTMLNotification("notification.html");
notification.show();
Also there is an external notification.js for all the scripts I would like to run in the notification window (Since the manifest version 2 discourages inline javascript). Everything works fine except I couldn't open developer tools for the notification window to inspect the page. I can do it for the background as well as the popup pages, so not sure if I didn't find it or I simply can't inspect notification through the developer tool. I know I can send messages between background and notification so that outputs show up on the console, but it would be nice if I could inspect directly.
Thanks much!
Navigate to chrome://inspect/ and you can see all the pages that can be inspected. Under the section "Extensions" you should be able to see your notification page and you can inspect it.
Adding this answer for completeness, because #JJin's answer may had been working before but not in Chrome versions 24 and 25.
After some experimenting I accidently found that the developer tool is available for the notification page. The trick is to
fire up the notification window first and keep it on;
navigate to chrome://extensions and notification.html should appear alongside the background.html or whatever name the background page's name is,
as shown in the screenshot:
Make sure the notification window is on otherwise the notification.html would disappear.
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