Fix value check in page-to-extension-messaging example (#229)

Check the value of "event.data" before dereferencing it,
to avoid errors when void messages are sent using postMessage.

And remove the "event.data.direction" truthness check, because the
actual value is already tested at the next line.
This commit is contained in:
Rob Wu
2017-06-08 17:06:34 +02:00
committed by wbamberg
parent ea0f7f392a
commit 3870a213bb

View File

@@ -4,7 +4,7 @@ If the message was from the page script, show an alert.
*/
window.addEventListener("message", function(event) {
if (event.source == window &&
event.data.direction &&
event.data &&
event.data.direction == "from-page-script") {
alert("Content script received message: \"" + event.data.message + "\"");
}