Chrome扩展名 - 背景/事件JavaScript不响应或加载



新的进行扩展,我正在尝试加载cookie,但意识到我的eventpage.js似乎并没有加载 - 因为基本的console.log(" hello hello"(wasn't加载。

我正在通过Chrome"负载打开包装扩展"加载扩展,其中清单,内容和背景脚本为。

下面附加的代码是我用来查看是否可以从事件页面获得控制台日志的内容。只有内容脚本加载,即使我按键并已记录。

Chrome:58

有什么建议?

subtest.son

{
"manifest_version": 2,
"name": "Facebook  Extension  ",
"version": "1.0",
"description": "",
"permissions": ["storage", "webNavigation", "activeTab", "tabs", "cookies",  
"*://*.facebook.com/*"], 
"background": [
{
"scripts": ["event_Page.js"],
"persistent" : false
}
],
"content_scripts": [
{
 "matches": ["*://*.youtube.com/*"],
"css": ["style.css"],
"js": ["jquery-2.1.0.min.js", "talkToEvent.js"]
}

]

TalktoEvent.js

   console.log("Hello World!s");
   $(document).ready(function() {
   console.log("DOM READY!");
  $(document.documentElement).keydown(function (e) {
    console.log("Key Has Been Pressed!");
    chrome.runtime.sendMessage({Message: "getTextFile"}, function (response) {
        ;
    })
  })
});

event_page.js

     console.log("Atleast reached background.js")
     chrome.runtime.onMessage.addListener (
    function (request, sender, sendResponse) {
    console.log("Reached Background.js");
    if (request.Message == "getTextFile") {
        console.log("Entered IF Block");
        $.get("http://localhost:63342/Projects/StackOverflow/ChromeEXT/helloWorld1", function(response) {
            console.log(response);
            // to send back your response  to the current tab
            chrome.tabs.query({active: true, currentWindow: true}, function(tabs) {
                chrome.tabs.sendMessage(tabs[0].id, {fileData: response}, function(response) {
                    ;
                });
            });

        })
    }
    else {
        console.log("Did not receive the response!!!")
    }
}
);

您的manifest.json不正确。

根据事件页面文档,它应该是一个对象,但是在您的清单中,它是一个数组。

正确 subtest.json

{
  "manifest_version": 2,
  "name": "Facebook  Extension  ",
  "version": "1.0",
  "description": "",
  "permissions": [
    "storage",
    "webNavigation",
    "activeTab",
    "tabs",
    "cookies",
    "*://*.facebook.com/*"
  ],
  "background": {
    "scripts": [
      "event_Page.js"
    ],
    "persistent": false
  },
  "content_scripts": [
    {
      "matches": [
        "*://*.youtube.com/*"
      ],
      "css": [
        "style.css"
      ],
      "js": [
        "jquery-2.1.0.min.js",
        "talkToEvent.js"
      ]
    }
  ]
}

还固定了错过的逗号和封闭式。

最新更新