Chrome console - breakpoint for the whole file

is it possible to set something like a “breakpoint” in a file in the Chrome console (a kind of shortcut to set a breakpoint on each line of code in the file)?

It would be extremely useful when trying to understand third-party scripts that, as you know, are executed, but have no idea what part of the code is coming from.

My current usage example: I downloaded a script (form validation) that does not work properly. The fastest way to solve the problem is to pause execution at any time when the JS runtime enters this file and begins to examine it from there.

+8
javascript google-chrome developer-console
source share
5 answers

If you can list the functions publicly exposed by a third party script (for example, if all the objects of the object or their name has a template), you can make another script that dynamically replaces all these functions and force a breakpoint:

thirdpartfunc = (function () { var oldfunc = thirdpartfunc; return function () { debugger; oldfunc.call(null, arguments); }()); 

With appropriate reference to this (if applicable).

+1
source share

Not. You will need to add breakpoints to the various entry points of the function that the file contains in order to catch wherever it could enter.

0
source share

Can't you just put a breakpoint on the first line of each function in the file of interest?

0
source share

If you know that a function (s) is being called, you can use function breakpoints

 debug(function); function(...args); 

When you call a function, it hits the breakpoint. They are not saved when the page reloads, but you can set the breakpoint of the line as soon as you click the breakpoint of the function.

This may seem tedious.

If you have a feature set, you can do

 [function0, function1].map(debug) 

@Tibos the answer in another post would be nice if there was some kind of Babel transform to insert a debugger; at the beginning of each function, instead of inserting it manually.

0
source share

All Articles