0

I have a working extension for Chrome and Firefox and I tried to make it work in Microsoft Edge as well. for some reason the content script stuck on "runtime.sendMessage" function. I have using Edge 40.15063.

the Edge console says:

"API Call: 'runtime.sendMessage'"

"script block (9) (214,17)."

manifest.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"
  }
}

edge.js:

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

content.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 );

}());
TylerH
  • 20,799
  • 66
  • 75
  • 101
  • What version of Edge do you use? Check the console in both background and your content page, they don't share errors. Manual background.html approach might be worth trying as well - not sure how well Edge handles persistent bg scripts. – Anatoly Sazanov Jun 19 '17 at 08:42
  • the edge version is Edge 40.15063. – Ariel Kovler Jun 19 '17 at 14:40
  • `chrome` has been mapped to `browser` already in `-ms-preload` scripts, you don't have to do it again. – zhm Aug 21 '17 at 09:19

0 Answers0