bigwavesoftware bigwavesoftware - 1 year ago 69
Javascript Question

debugging into a javascript anonymous function

I am trying to reverse engineer a Microsoft CRM 2011 web page. The page loads a massive number of scripts and HTML. My current development focus is on the click event of a checkbox element on the page. Clicking the element causes behavior on the page to change, and I want to walk through the code that handles this.

The problem is the checkbox's click handler is attached during page load via an anonymous method. So the code is there, but trying to find it is asking one to locate a needle in a haystack.

Is there a technique using the Internet Explorer debugging tools to somehow make the debugger stop when the checkbox is clicked? There may not be, but I thought I would ask.

Answer Source

Your best bet is to run this in the console:


If null appears in the console, you can continue reading. Otherwise the onclick handler and it's code should appear right there in the console.

Use Chrome's dev tools: Right click something on the page -> inspect element. You'll see this: A screenshot of chrome dev tools

Go to "SOURCES" (no longer called "Scripts") and there is a '||' Pause button as you see in the screenshot. If the page doesn't fail, you can check the checkbox, and since scripts are paused, you'll see the code for the anonymous function become highlighted and the page will be frozen. You can then use the tools to step through the code.

However, we can certainly better help you with what you actually want from the page...

You can also use attach a onbeforescriptexecute from the console: You would be something like this in the console:

document.getElementById('theCheckBoxId').onbeforescriptexecute = function (e) {
  alert('hey same thing as pausing the script!');
  console.error('script with this id about to run: ' +;
  //Could also try .src .innerText etc. 
  //Reference this:

  //the full argument to checkout in the console:

You can also play around with the currentScript method:

You can also right click and inspect the check box, and then on the right panel of dev tools, look at the 'Click' event listener code, but often this is garbled and hard to work with.