I want to extract all the dynamic javascript functions from a web page, with a userscript.
Someone suggested using a hook for DOM objects. They also provided this example:
var f = document.createElement;document.createElement = function(tagName){
console.log(tagName);
f.apply(document, arguments); }
I think this functions logs all the document.createElement() calls,
but where do I add this function in my userscript?
I tried creating a userscript which contains only this function, but it did not work.
The userscript gets executed after the page is loaded. How can this function be changed so that it tracks the dynamic functions before hand?
To track all dynamically loaded arguments “before hand”, use
// @run-at document-start.Also, you must inject the code into the target page, because the page’s javascript is what you want to track.
Here is a complete script that logs all
createElement()calls. It works with both Greasemonkey (Firefox) and Chrome userscripts: