MessageSource Property  
 

Returns the source URI for the most recent message.

Syntax

object.MessageSource

Remarks

The MessageSource property returns the URI of the document that sent the most recent message received by the browser. This property is typically checked along with the Message property to retrieve both the message contents and its source. The source URI identifies the document at the time the message was received and may differ from the browser's current URL if navigation has occurred since then.

The source URI remains available until another message is received, at which point the previous source is discarded. The control does not maintain a history of received messages or their sources. Applications that need to preserve this information should store their own copy. It is not required for you to check this property inside a handler for the MessageReceived event.

The source URI can be used to determine whether a message originated from a trusted document before processing its contents. This is particularly important when displaying content from external websites or allowing scripts to request privileged operations from the host application. Applications should validate the URI against a list of trusted origins, including the scheme, hostname and port, rather than relying on partial string comparisons. An unavailable or empty source URI should not be considered trusted. The source URI identifies the document that posted the message; it does not independently establish the origin of data that may have been forwarded to that document by another frame or script.

This property will return an empty string if no message has been received, if the WebView2 runtime did not return a source for the message or if messages have not been enabled by setting the AllowMessages property to True. If the Reset method is called, it will clear both the most recent message and message source.

Data Type

String

See Also