Message Listener Only Receives "{isTrusted: true}" Object
See original GitHub issueThe 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 this this.webview.injectJavaScript(
window.postMessage(${stringMessage}, ‘*’); true;)
where stringMessage is as JSON.stringified
object
Expected 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:
- OS: Windows, Android OnePlus 5
- OS version: 10
- react-native version: 0.59.8 using Expo https://github.com/expo/react-native/archive/sdk-33.0.0.tar.gz
- react-native-webview version: 5.12.0
Issue Analytics
- State:
- Created 4 years ago
- Reactions:3
- Comments:8
Top Results From Across the Web
Message Listener Only Receives "{isTrusted: true}" Object
This is simply what I've made. And it seems it only can recive {isTrusted: true} and I dont know how window.addEventListener('message' ...
Read more >Event.isTrusted - Web APIs - MDN Web Docs
The isTrusted read-only property of the Event interface is a boolean value that is true when the event was generated by a user...
Read more >isTrusted Event Property - W3Schools
Find out if a specific event is trusted: ... The isTrusted event property returns a Boolean value indicating whether the event is trusted...
Read more >Dispatching custom events - The Modern JavaScript Tutorial
The property event.isTrusted is true for events that come from real user actions and false for script-generated events. Bubbling example.
Read more >MessageEvent | typescript - v3.7.7 - Microsoft Open Source
A message received by a target object. ... True if event invokes listeners past a ShadowRoot node that is the root of its...
Read more >Top Related Medium Post
No results found
Top Related StackOverflow Question
No results found
Troubleshoot Live Code
Lightrun enables developers to add logs, metrics and snapshots to live code - no restarts or redeploys required.
Start FreeTop Related Reddit Thread
No results found
Top Related Hackernoon Post
No results found
Top Related Tweet
No results found
Top Related Dev.to Post
No results found
Top Related Hashnode Post
No results found
Top GitHub Comments
@reggie3 … Humor me and trying changing
this.addDebugMessage({event})
tothis.addDebugMessage(event.data)
Solutions above didn’t work for me.
What worked for me.
I had a false false report. WebView logs
{isTrusted: false}
when the event data is from an “untrusted source”. Even though the data is as expected.console.log(data) // {isTrusted: false}
Ignoring the log and treating the data as expected (assuming the correct data was logged) worked for me.