使用Google Extension获取当前Facebook页面的源代码

时间:2018-02-07 12:44:32

标签: javascript jquery html facebook

我想在chrome中进行扩展,以查看当前页面的源代码使用它(在本例中是Facebook页面)。我已经获得了当前的url,然后将其传递给函数以获取源代码。但是,当我使用Chrome浏览器的View页面源时,我获得的源代码并不相同。我试图调试,但它没有任何错误或问题,也没有警告。我很困惑,不知道为什么。

HTML文件:

<!doctype html>
<html>
  <head>
    <title>Getting Started Extension's Popup</title>   
    <script src="popup.js"></script>
      <script src="https://ajax.googleapis.com/ajax/libs/jquery/2.2.2/jquery.min.js"></script>
  </head>
  <body>
      <div id="host"></div>
      <div id="sourcex"></div>
  </body>
</html>

JS文件:

chrome.tabs.query({'active': true, 'windowId': chrome.windows.WINDOW_ID_CURRENT},
   function(tabs){     
       var currentURL = tabs[0].url;
       window.onload = function getSourceCode() {
           var b = currentURL;
           var url = b, xmlhttp;//Remember, same domain
           if ("XMLHttpRequest" in window)
               xmlhttp = new XMLHttpRequest();
           if ("ActiveXObject" in window)
               xmlhttp = new ActiveXObject("Msxml2.XMLHTTP");
           xmlhttp.open('GET', url, true);
           xmlhttp.onreadystatechange = function () {
               if (xmlhttp.readyState == 4 && xmlhttp.status == 200) {
                   var a = xmlhttp.responseText;
                   var c = String(a);
                   document.getElementById('sourcex').innerHTML = c;
               }
           };
           xmlhttp.send();
       }  
   }
);

manifest.json文件:

{
  "manifest_version": 2,

  "name": "One-click Kittens",
  "description": "This extension demonstrates a browser action with kittens.",
  "version": "2.0",

  "permissions": [
        "tabs",
        "webRequest",
        "http://*/*",
        "https://*/*",
        "cookies",
        "webRequestBlocking",
        "unlimitedStorage",
        "storage",
    "management",
    "http://facebook.com/",
    "https://facebook.com/",
        "downloads"
    ],
  "browser_action": {
    "default_icon": "img/icon.png",
    "default_popup": "popup.html"
  },
  "web_accessible_resources": [
        "*"
    ],
  "content_security_policy": "script-src 'self' https://ajax.googleapis.com; https://ssl.google-analytics.com; object-src 'self'"

}

0 个答案:

没有答案