mirror of
https://github.com/mdn/webextensions-examples.git
synced 2026-04-17 23:08:33 +02:00
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:
@@ -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 + "\"");
|
||||
}
|
||||
|
||||
Reference in New Issue
Block a user