12

Is there any way to specify the debugger for listening for specific method names? Example: When the function myFunc get called, I want to start debugging. Yes, I know that this seems strange, but in some projects I don't know the name of the javascript file to start the debugging, but I do know the name of the method.

It would be something like the Event Listener Breakpoints, but with an arbitrary method name instead an event name.

5
  • Put a breakpoint inside the function, try debugger;
    – elclanrs
    May 12, 2014 at 21:01
  • You can set breakpoints on lines inside the function that gets called. May 12, 2014 at 21:02
  • 3
    @elclanrs: To do that, he'd have to know what file it was in. May 12, 2014 at 21:02
  • 1
    @T.J.Crowder: Well he can debug it to find out, oh the irony. If the function is anonymous and minified, good luck with that
    – elclanrs
    May 12, 2014 at 21:02
  • 2
    @elclanrs I am starting to wonder if you actually read the OP's question. May 12, 2014 at 21:09

2 Answers 2

9

You can find the function name with a search and set the break point. You can use the following key combination to search accross the files.

  • Windows: ctrl+shift+F
  • OSX: Cmd + Opt + F

enter image description here

2
  • 3
    Yeah. Fairly sure the literal answer to the OP's question is "no" and this is the best workaround. If the function is defined by a function declaration or named function expression, you can type tion foo when looking for function foo, to avoid hitting everywhere it's used. (That won't help with anonymous function expressions, of course.) May 12, 2014 at 21:03
  • 1
    It's indeed not the exactly answer for my question, but it's more than enough for my usecase, with that I solve the problem of debugging some generated JS files that are hard to trace in the project source. May 13, 2014 at 11:38
8

Just wanted to add another method that I came across today while searching, you can open the JS console and use debug(Some.path.to.myFunc) and it will set a debug breakpoint on the function. Use undebug(func) to unset it. You can also use monitor(func) and unmonitor(func) to get a console log when that function is called. Learned about these from: https://amasad.me/debugging

1

Your Answer

By clicking “Post Your Answer”, you agree to our terms of service and acknowledge that you have read and understand our privacy policy and code of conduct.

Not the answer you're looking for? Browse other questions tagged or ask your own question.