<html>
    <head>
      <base href="https://bugs.webkit.org/" />
    </head>
    <body><table border="1" cellspacing="0" cellpadding="8">
        <tr>
          <th>Bug ID</th>
          <td><a class="bz_bug_link 
          bz_status_NEW "
   title="NEW - window.postMessage error with iframe and file:// protocol"
   href="https://bugs.webkit.org/show_bug.cgi?id=162512">162512</a>
          </td>
        </tr>

        <tr>
          <th>Summary</th>
          <td>window.postMessage error with iframe and file:// protocol
          </td>
        </tr>

        <tr>
          <th>Classification</th>
          <td>Unclassified
          </td>
        </tr>

        <tr>
          <th>Product</th>
          <td>WebKit
          </td>
        </tr>

        <tr>
          <th>Version</th>
          <td>Safari 10
          </td>
        </tr>

        <tr>
          <th>Hardware</th>
          <td>Unspecified
          </td>
        </tr>

        <tr>
          <th>OS</th>
          <td>iOS 10
          </td>
        </tr>

        <tr>
          <th>Status</th>
          <td>NEW
          </td>
        </tr>

        <tr>
          <th>Severity</th>
          <td>Normal
          </td>
        </tr>

        <tr>
          <th>Priority</th>
          <td>P2
          </td>
        </tr>

        <tr>
          <th>Component</th>
          <td>HTML Events
          </td>
        </tr>

        <tr>
          <th>Assignee</th>
          <td>webkit-unassigned&#64;lists.webkit.org
          </td>
        </tr>

        <tr>
          <th>Reporter</th>
          <td>pierbover11&#64;gmail.com
          </td>
        </tr></table>
      <p>
        <div>
        <pre>On iOS when trying to use window.postMessage I get 11 errors saying:

Blocked a frame with origin &quot;null&quot; from accessing a frame with origin &quot;null&quot;. Protocols, domains, and ports must match.

See this screenshot: <a href="http://i.imgur.com/JJkIEy5.jpg">http://i.imgur.com/JJkIEy5.jpg</a>

This happens when using WKWebView in a Cordova project or in the Safari browser when using the file:// protocol. The error doesn't happen when using UIWebView or when using the HTTP(s) protocol.

I have tested it in iOS 9 and 10 with the same result.

I have attached 2 HTMLs files. Open index.html in the Simulator with Safari iOS using a file:// protocol and click the buttons.

Here is a simple cordova project that you can test too for WKWebView.
<a href="https://github.com/PierBover/cordova-wkwebview-iframe-bug">https://github.com/PierBover/cordova-wkwebview-iframe-bug</a>

To reproduce in the cordova project you need to install the cordova CLI and then:
1) go to the cordova folder
2) cordova emulate ios --target=&quot;iPad-Air-2, 9.3&quot;
3) Open Safari. On the Developer menu open the JS console for the webview.
4) Click the buttons on the webview.

If you test this URL in Safari for iOS you will see the error doesn't reproduce which confirms it only happens when using file://
<a href="http://pierbover.com/pub/iframe-bug/">http://pierbover.com/pub/iframe-bug/</a></pre>
        </div>
      </p>
      <hr>
      <span>You are receiving this mail because:</span>
      
      <ul>
          <li>You are the assignee for the bug.</li>
      </ul>
    </body>
</html>