title: Salesforce Lightning CORS issue: Failed to execute postMessage on DOMWindow
body: <p><strong>Synopsis: we have a Salesforce lightning app that works fine in the dev org, but once we create a managed package and install it in orther orgs, if fails with this CORS error:</strong></p>
  
  <blockquote>
    <p><em>Failed to execute ‘postMessage’ on ‘DOMWindow’: The target origin provided (‘<a href="https://ashoktest-dev-ed.lightning.force.xn--com-to0a" rel="nofollow noreferrer">https://ashoktest-dev-ed.lightning.force.xn--com-to0a</a>) does
    not match the recipient window’s origin
    (‘<a href="https://ashoktest-dev-ed--blusign.ap15.visual.force.xn--com-to0a" rel="nofollow noreferrer">https://ashoktest-dev-ed--blusign.ap15.visual.force.xn--com-to0a</a>).</em></p>
  </blockquote>
  
  <p>Here are the steps to reproduce the issue in a simple lightning app</p>
  
  <p>1) Create a Custom Button on Opportunity with following formula.
  "/apex/namespace__testHelloVFpage" 
  Name This button testHello. Drag and drop this button in Opportunity pagelayout to use it.</p>
  
  <p>2) Create a Visual force page using below code and Name it as testHelloVFpage</p>
  
  <pre><code>&lt;apex:page sidebar="true" showHeader="true" standardController="Opportunity"&gt;
      &lt;apex:includeLightning /&gt;
      &lt;center&gt;&lt;div id="lightning" style="margin-left:1%;max-width:75%;margin-bottom:2%;"/&gt;&lt;/center&gt;
  &lt;script &gt;
      $Lightning.use("namespace:testHelloEsignPageApp", function() {
          $Lightning.createComponent("namespace:testHelloEsignLC",
          {},
          "lightning",
          function(component) {window.$Force = sforce;});
      });
  
  &lt;/script&gt;
  &lt;/apex:page&gt;
  </code></pre>
  
  <p>3) Create a Lightning app using below code and name it as testHelloEsignPageApp</p>
  
  <pre><code>&lt;aura:application access="GLOBAL" extends="ltng:outApp"&gt;
      &lt;aura:dependency resource="namespace:testHelloEsignLC"/&gt;
  &lt;/aura:application&gt;
  </code></pre>
  
  <p>4) Create Lightning component bundle using below component code and name it testHelloEsignLC</p>
  
  <pre><code>&lt;aura:component implements="force:appHostable,flexipage:availableForAllPageTypes,flexipage:availableForRecordHome,force:hasRecordId,forceCommunity:availableForAllPageTypes,force:lightningQuickAction" 
                  access="global" &gt;
  ########### This is a Test Component ###############
      &lt;br&gt;&lt;/br&gt;
      ***********   Hello ESign *************
  &lt;/aura:component&gt;
  </code></pre>
  
  <p>5) Now once we click on custom button that we have created in step one, it will show us this  Lightning page. No issues</p>
  
  <p>NOTE :- nameSpace in above code is domain name.</p>
  
  <p>BUT,</p>
  
  <p>Once we have created a Managed Beta or Managed package and install it in any Developer edition or any other domain orgs, We are getting BLANK page. 
  And the errors in INSPECT Element Console as follows. I am not getting any logs also.</p>
  
  <blockquote>
    <p>Failed to execute ‘postMessage’ on ‘DOMWindow’: The target origin
    provided (‘<a href="https://ashoktest-dev-ed.lightning.force.xn--com-to0a" rel="nofollow noreferrer">https://ashoktest-dev-ed.lightning.force.xn--com-to0a</a>) does
    not match the recipient window’s origin
    (‘<a href="https://ashoktest-dev-ed--blusign.ap15.visual.force.xn--com-to0a" rel="nofollow noreferrer">https://ashoktest-dev-ed--blusign.ap15.visual.force.xn--com-to0a</a>).</p>
  </blockquote>
  
  <p>And </p>
  
  <blockquote>
    <p>typeError - error is undefined</p>
  </blockquote>
  
  <p>And</p>
  
  <blockquote>
    <p>Uncaught TypeError: Cannot read property 'split' of undefined
        at displayErrorText (lightning.out.delegate.js?v=1558631590920:70)
        at lightning.out.delegate.js?v=1558631590920:178
        at XMLHttpRequest.xhr.onreadystatechange (lightning.out.delegate.js?v=1558631590920:112)</p>
  </blockquote>
  
  <p>Tried the following:</p>
  
  <ol>
  <li>checked if we are missing any namespaces and it is not an issue.</li>
  <li>Tried Hard coding origin URL in navigateToURL section to open the page from component - failed.</li>
  <li>Tried skipping the any sort of events which are firing in component for navigation and used window.open, did nothing.</li>
  <li>Tried opening this page in URL by adding IDs manually to bypass calling component(Sign with BluSign component in UI) and got the same error.</li>
  <li>Tried enabling Development Mode for user. </li>
  </ol>