2

I'm converting an Chrome extension which works well to Edge extension, and I need to have message listener in my content script.

Here is the code in my content script:

browser.runtime.onMessage.addListener(listener);

function listener(message) {
    console.log(message);
}

However, each time script executes, I get this error, pointing to first line of my content script code:

Unable to get property 'onMessage' of undefined or null reference

I've tried changing browser.runtime into chrome.runtime, but nothing changes.

Here I've found that Edge supports runtime.onMessage with some minor incompatibilities:

https://developer.microsoft.com/en-us/microsoft-edge/platform/documentation/extensions/api-support/supported-apis/

Makyen
  • 31,849
  • 12
  • 86
  • 121
kecman
  • 813
  • 3
  • 14
  • 34
  • You may want to provide more details about your extension, like how do you send the message and what manifest file looks like. Also, you could check https://developer.microsoft.com/en-us/microsoft-edge/platform/issues/8473140/ and see if it helps. – Haibara Ai Nov 17 '16 at 05:19
  • Yes I've checked that issue before posting question and it didn't help. I don't see a reason for providing more details and making it more complicated than it is, because it's obvious that script gets injected into page, but crashes on first line, being unable to get reference to browser.runtime – kecman Nov 17 '16 at 14:55
  • _"because it's obvious that script gets injected into page"_ And yet, it may help to see how exactly. Is it from a manifest entry? Is it programmatic injection? – Xan Nov 19 '16 at 10:40
  • It's manifest defined content-script. – kecman Nov 19 '16 at 13:14
  • 1
    @kecman Please add the manifest entry then. Mask out urls with `example.com` if needed. – Xan Nov 24 '16 at 09:37
  • Just see you (or other people) have reported this issue on [Edge Issue Tracker](https://developer.microsoft.com/en-us/microsoft-edge/platform/issues/9823671/), we may want to wait for Edge team to confirm if it's a bug. – Haibara Ai Nov 24 '16 at 11:32
  • @Xan "content_scripts": [ { "matches": ["http://*.example.com/*","https://*.example.com/*"], "js": ["js/jquery-3.1.1.min.js","js/cs.js"], "all_frames":true } – kecman Nov 30 '16 at 19:19

0 Answers0