question-mark
Stuck on an issue?

Lightrun Answers was designed to reduce the constant googling that comes with debugging 3rd party libraries. It collects links to all the places you might be looking at while hunting down a tough bug.

And, if you’re still stuck at the end, we’re happy to hop on a call to see how we can help out.

Message Listener Only Receives "{isTrusted: true}" Object

See original GitHub issue

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 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:

Issue Analytics

  • State:closed
  • Created 4 years ago
  • Reactions:3
  • Comments:8

github_iconTop GitHub Comments

10reactions
rgoldiezcommented, Jul 5, 2019

@reggie3 … Humor me and trying changing this.addDebugMessage({event}) to this.addDebugMessage(event.data)

2reactions
LindaOjocommented, Oct 21, 2021

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.

Read more comments on GitHub >

github_iconTop 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 >

github_iconTop Related Medium Post

No results found

github_iconTop Related StackOverflow Question

No results found

github_iconTroubleshoot Live Code

Lightrun enables developers to add logs, metrics and snapshots to live code - no restarts or redeploys required.
Start Free

github_iconTop Related Reddit Thread

No results found

github_iconTop Related Hackernoon Post

No results found

github_iconTop Related Tweet

No results found

github_iconTop Related Dev.to Post

No results found

github_iconTop Related Hashnode Post

No results found