I'm working on a new client's website that loads Javascript from a CDN so the Javascript is not embedded or inline with the webpage source. I would like to pause everytime getCurrentPosition()
is executed in order to determine which external JS file it is contained in.
I realize I could use other tools to do a string search through the contents of the JS files but I would rather keep to Chrome's debugging tools.
Should I be trying to create a watch expression or is there another way to pin down when and where a certain JS function is fired?
You can search in all files using Chrome DevTools. Find your function and debug it:
ctrl + shift + f
(Win) or cmd + option + f
(Mac)In the opened box search for all files(JS, CSS, ...).
In the box you have 5 options:
At the first select a file for using options 2-5
In this option, if you write @JSFunctionName or @CSSClassName then the cursor will navigate to the JSFunctionName or the CSSClassName.
一种方法是用包装函数替换Geolocation.getCurrentPosition
方法,以便您可以在其中设置断点,然后检查堆栈以查看谁在调用它。
If you know where in the code the method is called you can set breakpoints . This will pause the javascript execution during runtime and allow you get a stack trace.
You can find all the information that you need at the webpage:https://developer.chrome.com/devtools/docs/javascript-debugging
By simply putting it (copied from the webpage)
Open a site such as the Google Closure hovercard demo page or the TodoMVC
Open a site such as the Google Closure hovercard demo page or the TodoMVC Angular app
Open the DevTools window.
If it is not already selected, select Sources.
Debugging with breakpoints
A breakpoint is an intentional stopping or pausing place in a script. Use breakpoints in DevTools to debug JavaScript code, DOM updates, and network calls.
Add and remove breakpoints In the Sources panel, open a JavaScript file for debugging. In the example below, we are debugging the todoCtrl.js file from the AngularJS version of TodoMVC.
Click the line gutter to set a breakpoint for that line of code. A blue tag will indicate if a breakpoint has been set:
With the above simple example you can actually "stop" the function getCurrentPosition()
and debug it.
The technical post webpages of this site follow the CC BY-SA 4.0 protocol. If you need to reprint, please indicate the site URL or the original address.Any question please contact:yoyou2525@163.com.