3

Is there a way to see which functions are being executed on a page?

If I load an external script on a page, is it possible to change what a function does on the fly or prevent it from running?

4
  • 3
    You can use your browser's developer tools. Commented May 29, 2014 at 21:54
  • In practice this wouldn't be very useful, as there are often thousands of functions executing per second when things are actually happening. Commented May 29, 2014 at 21:55
  • 1
    codeschool.com/courses/discover-devtools is a free course about the developer tools in chrome. I think they're the best compared to other popular browsers, but it is a matter of personal preference. Commented May 29, 2014 at 21:55
  • JavaScript is single threaded, so you cannot run other JS code in parallel to monitor other JS code. You'd need access to the engine if you wanted change its behavior. Commented May 29, 2014 at 21:58

3 Answers 3

4

HTML5 introduces onbeforescriptexecute event, which you can use to detect new scripts on the fly, and block them if you want.

For example:

window.addEventListener('beforescriptexecute', function(e) {
    // e.target.src is the URL of the external loaded script
    // e.target.innerHTML is the content of the inline loaded script
    if (e.target.src === urlToBlock)
        e.preventDefault(); // Block script
}, true);
Sign up to request clarification or add additional context in comments.

Comments

0

Use Firebug for Firefox or Chrome Developer Tools. You can set the breakpoints and debug your code very well.

Comments

0

https://developer.chrome.com/devtools/docs/javascript-debugging Here's a good place to start.

Comments

Your Answer

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

Start asking to get answers

Find the answer to your question by asking.

Ask question

Explore related questions

See similar questions with these tags.