Unable to get property 'onMessage' of undefined or null reference in Edge extension content script

1.2k views Asked by At

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/

0

There are 0 answers