4

I'm writing a Chrome extension that needs to be able to analyze the source code of a specific HTML page and all the external Javascript and CSS files it loads without loading them again via an XHR request - that is, it will be analyzing the running copies loaded by the browser.

Is that possible? I know it's possible to analyze the source of a particular open tab, but while these Javascript files will be loaded by the browser, they obviously won't be occupying their own tab or window (only the HTML loading them will be.) Please help!

1
  • I suggest you start looking into the Developer's Console, since I think that does what you want, and it is written in plain HTML, CSS, and JavaScript Commented Sep 15, 2011 at 16:21

1 Answer 1

1

Out of the box, there is no way to get the source of the resources without resorting to the chrome.experimental.devtools.resources APIs.

However, when the experimental APIs are enabled using the --enable-experimental-extension-apis switch, you can do the following to retrieve the source of each resource:

chrome.experimental.devtools.resources.onFinished.addListener(function(resource) {
  resource.getContent(function(content, encoding) {
    if(encoding !== 'base64') {
      alert(content);
    }
  });
});
Sign up to request clarification or add additional context in comments.

2 Comments

Thanks very much, but is there a way that would work on all Chrome browsers? This plugin needs to be usable by everyone.
@kaepora: Until that particular API gets released from experimental, unfortunately not. However, you can detect if the APIs are unavailable and instruct the users on how to enable them.

Your Answer

By clicking “Post Your Answer”, you agree to our terms of service and acknowledge you have read our privacy policy.

Start asking to get answers

Find the answer to your question by asking.

Ask question

Explore related questions

See similar questions with these tags.