title: How to check if message for window.addEventListener("message") is from a specific iframe
body: <p>I'm working on a chrome extension where I have a content script which injects an iframe into the page, I can send a message specifically from the content script to the iframe with iframeVariable.postMessage but I can't specifically send message to the content script as the parent.window.postMessage posts message entirely onto the page to which any script can listen to, I tried with the e.target == iframeVariable but it doesn't work. So for the moment for security concerns I'm wrapping the message in a unique way but I don't think that's the best solution,</p>
  <p>This is the code:</p>
  <pre><code>contentscript
  window.addEventListener(&quot;message&quot;, function (e) {
  console.log(
    e.target == appIframeContainer
    );
    if (e.data.toString().includes(&quot;test&quot;)) {
      const data = JSON.parse(e.data);
      if (data) {
        if (data.test) {
          if (data.test.message == &quot;toggleApp&quot;) {
            toggleApp();
          }
        }
      }
     }
  }
  
  Inside iframe:
  
        parent.window.postMessage(
          JSON.stringify({
            test: {
              message: &quot;toggleApp&quot;,
              
            },
          }),
          &quot;*&quot;,
          []
        );
  
  </code></pre>
  <p>I want to check if it is the iframe that the content script injected not the domain as the domain doesn't matter because content script and the iframe are on same page</p>