how to debug the js in jsfiddle
Asked Answered
D

8

105

I am looking at this jsfiddle: http://jsfiddle.net/carpasse/mcVfK/ It works fine that is not the problem , I just want to know how to debug through the javascript. I tried to use the debugger command and I cant find it in the sources tab? any idea how I can debug this?

some code from the fiddle:

angular.module('app', ['appServices'])
    .config(['$routeProvider', function($routeProvider) {
        $routeProvider.
                when('/home', {templateUrl: 'home.html',   controller: HomeCtrl}).
                when('/list', {templateUrl: 'list.html',   controller: ListCtrl}).
                when('/detail/:itemId', {templateUrl: 'detail.html',   controller: DetailCtrl}).
                when('/settings', {templateUrl: 'settings.html',   controller: SettingsCtrl}).
                otherwise({redirectTo: '/home'});
}]);
Domel answered 18/10, 2013 at 22:32 Comment(2)
Insert the word debugger; into the code. Chrome and Firefox will automatically open a step-through debugger! (I've copied this tip from @user3335908's answer to make it more prominent)Etruria
as WS says (add "debugger") - but make sure the dev-tools is open tooBacteroid
F
53

The JavaScript is executed from the fiddle.jshell.net folder of the Sources tab of Chrome. You can add breakpoints to the index file shown in the Chrome screenshot below.

Debugging JSFiddle in Chrome

enter image description here

Featherstone answered 7/4, 2015 at 12:25 Comment(5)
this shows nothing for me. I get an empty index fileAluminiferous
@OliverWatkins it was empty for me too, I fixed this by clicking "Update" on the top, then I noticed after I ran again, in Sources tab in the developers tool panel, under "jsfiddle.net", then under my named folder, there was an extra directory with another index file that showed the code. Hope this helps!Septennial
I have a 3rd folder under fiddle.jshell.net which has (index) as well. If I open that, there's an html file with the js embedded in it. (on line 48 when I wrote this)Ohmmeter
fiddle.jshell.net contains only _display with (index) inside, which is a nearly empty HTML page with <p>That page doesn't exist.</p>. My js code is not thereStocktaking
not working anymore it seems. The current structur looks different. the js files in fiddle.jshell.net does not contain the actual jsChondrite
I
48

Use the debugger; statement in the code. The browser inserts a breakpoint at this statement, and you can continue in browser's debugger.

This should work atleast in chrome and firefox. https://developer.mozilla.org/en/docs/Web/JavaScript/Reference/Statements/debugger

angular.module('app', ['appServices'])
.config(['$routeProvider', function($routeProvider) {
    // *** Debugger invoked here
    debugger;
    $routeProvider.
            when('/home', {templateUrl: 'home.html',   controller: HomeCtrl}).
            when('/list', {templateUrl: 'list.html',   controller: ListCtrl}).
            when('/detail/:itemId', {templateUrl: 'detail.html',   controller: DetailCtrl}).
            when('/settings', {templateUrl: 'settings.html',   controller: SettingsCtrl}).
            otherwise({redirectTo: '/home'});
}]);
Irreducible answered 18/5, 2017 at 8:56 Comment(2)
This is the best answer !Opine
This is the simplest and fastest solution to this. Simply the best answer!Ramakrishna
R
6

Something worth mentioning. If you are ever using chrome dev tools. Press ctrl+shift+F and you can search through all the files in the source.

Rectocele answered 26/11, 2016 at 23:47 Comment(3)
That is very handy, on Mac it is Cmd + Alt + FJaworski
This would be a far better answer, but breakpoints set on the code you find this way will not be honored.Indignant
Thx to this hint I could find the code in a file that is not appearing in the source tree...Postoperative
T
4

Adding a debugger statement in the code and enable the "Developer Tools" in the bowser. Then when you are running the code in JSFiddle, the debugger will be hit!.

Tafilelt answered 18/2, 2019 at 14:15 Comment(0)
A
3

In addition to the other answers.

Very often it is useful just write debug information into the console:

console.log("debug information here");

The output is available in browsers dev tools console. Like it was logged from the usual javascript code.
This is quite simple and effective.

Ardor answered 13/1, 2016 at 16:11 Comment(0)
I
2

One of the answers above works but just that you need to add the keyword debugger at the line you want the break points and run the code which will then fire them on the dev tool. The code then gets visible at the source tab under editor_console=true.

Indebtedness answered 27/1, 2022 at 14:25 Comment(0)
C
0

Here is another place :)

Under the Jsfiddle.net node.

enter image description here

Copernicus answered 17/4, 2016 at 13:15 Comment(2)
This seems to cointain the source code that is shown on the page, surrounded with <pre> ... </pre>. It is not an actual runnable code.Stocktaking
You can't debug this code. One hint that you can't is the missing highlighting...Postoperative
R
0

The JavaScript is executed from the file ?editor_console=true in the folder result (fiddle.jshell.net)/fiddle.jshell.net/_display folder of the Sources tab of Chrome when using the developper tool. You can add breakpoints to your code then and refresh the page. enter image description here

More information on using chrome debugger can be found at Trying to debug Javascript in Chrome

Redfish answered 22/7, 2020 at 13:39 Comment(0)

© 2022 - 2025 — McMap. All rights reserved.