0

我有一个适用于 Chrome 和 Firefox 的扩展,我也尝试让它在 Microsoft Edge 中运行。由于某种原因,内容脚本停留在“runtime.sendMessage”功能上。我使用的是 Edge 40.15063。

Edge 控制台说:

“API 调用:'runtime.sendMessage'”

“脚本块 (9) (214,17)。”

清单.json:

{

  "manifest_version": 2,
  "name": "injecter",
  "version": "0.1.5.9",
  "author": "kovler",

  "description": "check the page url and then inject a code",
  "icons": {
    "48": "icons/icon32.png",
    "96": "icons/icon96.png"
  },
  "applications": {
    "gecko": {
      "id": "test@test.com",
      "strict_min_version": "45.0"
    }
  },
  "content_scripts": [{
    "matches": ["http://*/*", "https://*/*"],
    "js": ["edge.js", "content.js"]
  }],
  "background": {
    "scripts": ["edge.js", "constants.js", "promises.js", "main.js"],
    "persistent": true
  },
  "permissions": [
    "http://*/",
    "https://*/",
    "storage",
    "webNavigation",
    "tabs",
    "activeTab",
    "cookies",
    "webRequest",
    "webRequestBlocking"
  ],
  "-ms-preload": {
    "backgroundScript": "backgroundScriptsAPIBridge.js",
    "contentScript": "contentScriptsAPIBridge.js"
  }
}

边缘.js:

if (typeof chrome == "undefined" || typeof chrome.runtime == "undefined")
    chrome = browser;

内容.js:

(function(){

  function injectLocalScript (content, node) {
    var th = document.getElementsByTagName(node)[0];
    var s = document.createElement('script');
    s.setAttribute('type', 'text/javascript');
    s.innerHTML = content;
    th.appendChild(s);
  }

  function getAnswer(theMessageEvent) {
    if (theMessageEvent) {
      if (theMessageEvent.name === "Inject") {
        injectLocalScript(theMessageEvent.codeLine, 'body'); 
        console.log("injected");
      }      
    }
  }

  chrome.runtime.sendMessage({ name: "injectionCompleted" }, getAnswer );

}());
4

0 回答 0