John John
John John

Reputation: 1

Unable to debug and add a breakpoint to my custom javascript file using F12 firefox

I have a JavaScript file which i want to debug and test, so i want to add some breakpoints to it. now i read that i can do so using Firefox F12 tool. so i did the following steps:-

  1. i navigate to my application.
  2. click on F12.
  3. then under "Debugger" tab i can see all the script which are loaded with the ability to add breakpoints to it.

But I can not find a way to write a custom JavaScript and add breakpoints to it.. is this possible ? or the JavaScript need to be already loaded inside the page to debug it ?

Thanks

Upvotes: 0

Views: 457

Answers (2)

Nelson Teixeira
Nelson Teixeira

Reputation: 6580

One relevant point:

"You can place a debugger; statement anywhere in your JavaScript code. Once the JS interpreter reaches that line, it will stop the script execution, allowing you to inspect variables and step through your code."

Running a script in your computer

Normally you would have to run an local apache server to do this.

The other option is run the script with node.js. You have plenty of debug options.

Here you got a excelent tutorial about debugging on Node (called Bug Clinic):

https://nodeschool.io/#workshoppers

Upvotes: 1

Ruan Mendes
Ruan Mendes

Reputation: 92314

Just open your console, and use debugger as one of your statements and the debugger will stop there;

(function(){
    var x = 1;
    debugger;
    console.log(x);
})()

Upvotes: 1

Related Questions