best way to get list of all javascript files loaded on entire website

What’s the best way to get a list of all Javascript files loaded on an entire website, not 1 specific page? I’m thinking a spider would be needed but haven’t been able to find one that delivers what I’m looking for. This would be for security auditing purposes. Thanks!

5 thoughts on “best way to get list of all javascript files loaded on entire website”

  1. First, you will need to index a starting point for your webpage, like the home page for example, for links to other HTML files. You can make AJAX requests to the files found, and index those, etc. This will work as long as you are always requesting files that end in .html and you are not relying on JavaScript redirects, window.location.href = "https://website...".

    You will then need to index each of the collected URLs for JS files:

    If you are not using modules, you can use:

    const scriptURLs = [...document.getElementsByTagNames("script")].map(element => element.src);
    

    But if you are using modules, you can make AJAX requests to the initial JS file, make a program to process it for other imported scripts, and follow the tree of modules. This is made even more difficult if you have dynamically imported modules, import("./file.js").

    Reply

Leave a Comment