I have developed a website which I intend to display inside a webview, within a Chrome App. This works fine.
Now, I want to use postMessage from the website, to send
In the guest page inside the contained webview, use chrome.runtime.sendMessage()
to send messages to the containing app.
In the app, use chrome.runtime.onMessage.addListener()
to listen to those messages.
Note that you can message any app this way, not only the one containing your webview, but you'll need to know the app's ID for that, and use onMessageExternal
instead of onMessage
. For the containing app, the ID is optional.
Here's a working example of this mechanism. It's a Polymer element, but that doesn't change the mechanism: designerProxy_
is the equivalent of your guest page; registerDesignerProxyListener_
is the equivalent of your app.