You signed in with another tab or window. Reload to refresh your session.You signed out in another tab or window. Reload to refresh your session.You switched accounts on another tab or window. Reload to refresh your session.Dismiss alert
We have a problem with PostWebMessageAsJson to an Iframe.
We use ICoreWebView2Frame2::add_WebMessageReceived to receive messages from an iframe.
The iframe sends commands to the host app via window.chrome.webview.postMessage.
The host app processes the commands and sends the result back to the iframe via ICoreWebView2Frame2::PostWebMessageAsJson.
Within the iframe we use window.chrome.webview.addEventListener('message', ... to receive the response.
This works most of the time. But if we change the source of the iframe to load a new version for a new command, then receiving the responses often does not work. I say often because sometimes it works and sometimes it does not work.
I've tested a bit around and I tried to send the command in an interval until I receive a response. This works sometimes and after a few seconds and retries I get the response. This is really weird and currently I do not see a reason for this and I also can not debug this because I do not have access to the internal code to see what happens here.
The host app always receives the message from the iframe. That part is OK. But the iframe does not always receives the reply from the host app, but the the host app sends the message back. Sometimes it works, but most of the time not.
Then I tried to use ICoreWebView2Frame2::ExecuteScript right after ICoreWebView2Frame2::PostWebMessageAsJson just to figure out whether a test script can be executed in the iframe. ICoreWebView2Frame2::ExecuteScript always works even if the prior call to ICoreWebView2Frame2::PostWebMessageAsJson fails to receive the message.
Response of ICoreWebView2Frame2::PostWebMessageAsJson is always S_OK, even if the message does not receive the iframe.
The question now is why this is so. How can I debug this case to find out the problem?
Version
SDK: 1.0.1150.38
Runtime: WebView2-x64-99.0.1150.39
Framework: Win32
OS: Win10
I have prepared a sample project where you can see the problem. Just open and start it.
The sample app opens the devtools window and there you can follow the outputs in the console. Normally there should be alternating messages from test.html and iframe.html but if the message from iframe.html is not logged, that the iframe did not receive the message, the message was completely lost in that case which is a bug.
HRESULT of PostWebMessageAsJson is always S_OK, even if the message is lost.
The following image shows the console output in devtools, and here the messages from test.html and iframe.html should alternate what they sometimes do, but most of the time only test.html receives the message.
I hope this helps you to find the bug because I can't because I don't have access to the source code.
Thanks for the bug report, sample, and detailed description @sz5000! I'm sorry you're running into this. I've added this bug to our backlog to take a look.
We have a problem with PostWebMessageAsJson to an Iframe.
We use
ICoreWebView2Frame2::add_WebMessageReceived
to receive messages from an iframe.The iframe sends commands to the host app via
window.chrome.webview.postMessage
.The host app processes the commands and sends the result back to the iframe via
ICoreWebView2Frame2::PostWebMessageAsJson
.Within the iframe we use
window.chrome.webview.addEventListener('message', ...
to receive the response.This works most of the time. But if we change the source of the iframe to load a new version for a new command, then receiving the responses often does not work. I say often because sometimes it works and sometimes it does not work.
I've tested a bit around and I tried to send the command in an interval until I receive a response. This works sometimes and after a few seconds and retries I get the response. This is really weird and currently I do not see a reason for this and I also can not debug this because I do not have access to the internal code to see what happens here.
The host app always receives the message from the iframe. That part is OK. But the iframe does not always receives the reply from the host app, but the the host app sends the message back. Sometimes it works, but most of the time not.
Then I tried to use
ICoreWebView2Frame2::ExecuteScript
right afterICoreWebView2Frame2::PostWebMessageAsJson
just to figure out whether a test script can be executed in the iframe.ICoreWebView2Frame2::ExecuteScript
always works even if the prior call toICoreWebView2Frame2::PostWebMessageAsJson
fails to receive the message.Response of
ICoreWebView2Frame2::PostWebMessageAsJson
is always S_OK, even if the message does not receive the iframe.The question now is why this is so. How can I debug this case to find out the problem?
Version
SDK: 1.0.1150.38
Runtime: WebView2-x64-99.0.1150.39
Framework: Win32
OS: Win10
AB#38543222
The text was updated successfully, but these errors were encountered: