I am wondering whether it is possible to get all the JavaScript functions that are included in the HTML. For example, if my HTML includes the following:
<script src="https://www.example.com/script.js"></script>
<script>
function foo() {}
function bar() {}
</script>
How do I use JavaScript to retrieve all the JS functions available to this webpage. In this case, I would need to retrieve foo, bar and all the functions defined in https://www.example.com/script.js. Doing document.getElementsByTagName("script"); only returns the scripts as HTML objects, but I need to get all the functions for each script included in the HTML. Can this be done?
"Can this be done?"Yes, but it is extremely hard to do so. You'd need to get all of the script tags' innerHTML if it has nosrc, but if it does, you'd need to usefetch()with that url and get the text response. One you get all of that, you'd need a JS parser to find every single function declaration and modifications towindow.