Logo Questions Linux Laravel Mysql Ubuntu Git Menu
 

Is there a browser API to get a list of page resources?

I'm working on a remote JavaScript debugger and page inspector. I'm trying to find a way to programmatically get a list of all page assets (stylesheets, scripts, images, fonts, etc.) that a page loads, and pass them along to the remote inspector. I'd like to be able to edit the assets on the inspector side and pass them back to the client as well. Finally, I'd like to force asset reloads after the page has loaded (e.g. reload a stylesheet).

Are there any browser APIs or JavaScript techniques to do this?

I can think of two ways:

  1. Use window.performance to get a list of assets. Doesn't contain the resource content, however, and relies on parsing the URL for determining the type of resource that it is. I'm not sure that it includes things like CSS images as well.
  2. Scrape/parse the page for <style>, <script>, <img> tags and look through the CSS for additional resources. Very labor intensive and error prone, and I still don't know that it contains the resource content.

Any suggestions on how to do this?

like image 641
colbin8r Avatar asked Jul 08 '15 17:07

colbin8r


People also ask

What is an API and list the APIs available in HTML5?

API stands for Application Programming Interface. An API is a set of pre-built programs that can be used with the help of JavaScript. APIs are used to implement already written code to fulfill the needs of the project you are working on. Let us discuss some useful and popular APIs provided by HTML5.

What is API browser?

API stands for Application Programming Interface. A Web API is an application programming interface for the Web. A Browser API can extend the functionality of a web browser. A Server API can extend the functionality of a web server.

What's a JavaScript API?

API stands for Application Programming Interface and is a concept that is not limited or specific to JavaScript, but is used in almost all web application languages. Being a web developer, it is expected that you know about API, so let's try to understand the concept first.

Is web API part of JavaScript?

APIs in client-side JavaScript Client-side JavaScript, in particular, has many APIs available to it — these are not part of the JavaScript language itself, rather they are built on top of the core JavaScript language, providing you with extra superpowers to use in your JavaScript code.


1 Answers

window.performance.getEntries() is something good to start with. If you have the list, maybe you can pass them on by manually retrieving the content (you have the URL + session already). Good luck!

like image 191
Sander Avatar answered Sep 17 '22 20:09

Sander