-
Notifications
You must be signed in to change notification settings - Fork 3k
New issue
Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.
By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.
Already on GitHub? Sign in to your account
Message Listener Only Receives "{isTrusted: true}" Object #689
Comments
@reggie3 - have you tried (in your webview's JS to log/message the |
@rgoldiez Actually, I'm not getting a data property. I am using the following code to handle and debug incoming messages for the page that the WebView renders:
When the webview runs the following code: The screenshot below show's the "conversation" between the webview and the page its rendering: The text in the orange background is what the rendered page is doing. "Handle Message 1" correlates to Unfortunately, I'm not seeing a data property. |
@reggie3 ... Humor me and trying changing |
@rgoldiez That worked. Thank you for your help. |
@reggie3 - Glad to hear! I've faced the same issue so I thought it might be what you were facing. |
@reggie3 @rgoldiez I'm facing this exact same issue. Sending message via:
And receiving it with:
The onReceiveMessage function does:
The receiver method always errors trying to JSON.parse the data payload because it's undefined. When I stringify and send back the nativeEvent, it's just "{ "isTrusted": true }". Any ideas on how to proceed? |
Aha -- the error wasn't due to a missing payload, it was due to the JSON.parse. Apparently when you send the payload via injectJavaScript vs. postMessage it's already parsed, so you can just use it as a JS object directly. |
Solutions above didn't work for me. What worked for me. I had a false false report. WebView logs
Ignoring the log and treating the data as expected (assuming the correct data was logged) worked for me. |
This isn't true for me! I do something hardcoded like
This comes back as a string for me on the webside - I have to |
The webpage rendered inside webview only receives
{isTrusted: true}
when receiving events.This issue can be reproduced by adding the following code to the webage that attaches a function to the
message
event:window.addEventListener('message', this.handleMessage);
In the webview, I activate the message event using the
injectJavaScript
method like thisthis.webview.injectJavaScript(
window.postMessage(${stringMessage}, '*'); true;)
where stringMessage is as
JSON.stringified
objectExpected behavior:
I expected the entire stringified object to be received as a variable in the
handleMessage
function. Instead, I only receive the{isTrusted: true}
Environment:
The text was updated successfully, but these errors were encountered: