开发者

Chrome extension to access source code of any website

I'd like to write an extension that will display a popup with a text box, where y开发者_JS百科ou enter a word, then the number of occurrences of this word on the current page's source code is displayed. How would I access the current page's source code? Do I have to add a permission in the manifest?


I think you can't. You can access the page's DOM source:

document.body.InnerHTML
document.head.InnerHTML

Though this is different from page source, because it contains results of JavaScript.

If you want to get the page source, you can just fire a XMLHTTPRequest at the page and search the results.

To get the current tab's URL you need the "tabs" permission. To download pages in the background page you need the "http://*/*" and (if you like) "https://*/*" permissions.


HERE! I'm actually working on something kind of similar.
Source: http://code.google.com/chrome/extensions/xhr.html

var xhr = new XMLHttpRequest();
xhr.open("GET", window.location, true);
xhr.onreadystatechange = function() {
   if (xhr.readyState == 4) {
      alert(xhr.responseText);

      }
   }
}
xhr.send();


The webpage source code can be seen by clicking the options or properties of the chrome and there you can see the more tools option that further gives the developer tools or you can just press the shortcut keys. (Ctrl+Shift+I).

0

上一篇:

下一篇:

精彩评论

暂无评论...
验证码 换一张
取 消

最新问答

问答排行榜