Julius S. Julius S. - 1 year ago 110
Javascript Question

Is it allowed to use window.postMessage() in a chrome extension?

I have finished coding my extension for Chrome and FireFox (WebExtensions). I have used window.postMessage() for communication between website script and the extension and everything works.

But now I am reading that there are methods by chrome (https://developer.chrome.com/extensions/messaging) like

to send messages. Will my extension be rejected if I use window.postMessage() so I have to recode everything?

Xan Xan
Answer Source

Yes, this is a perfectly valid way of communication - between a page and a content script.

In fact, if you look at the Content Script documentation, it lists postMessage as a way of communication to the content script.

The method described at the Messaging documentation allows to cut out the content script as a middleman, and provides some degree authentication for messages (only the indended recipient will receive them), providing you configured "externally_connectable".

But "externally_connectable" is not supported in Firefox yet, and I can't quickly find a bug that tracks its implementation.

Recommended from our users: Dynamic Network Monitoring from WhatsUp Gold from IPSwitch. Free Download