BarakShriky opened a new issue #756: Unable to post message to file://. 
Recipient has origin null, on Cordova WKWebView engine page
URL: https://github.com/apache/cordova-ios/issues/756
 
 
   I'm trying to load a WKWebView page inside swift application using Cordova. 
The page contains some javascript code which runs `window.postMessage("some 
message", self.location.href);` and fails with - `Unable to post message to 
file://. Recipient has origin null`. I've noticed that `window.origin` returned 
`null`, while comparing to UIWebview engine in which `window.origin` returned 
`file://.`
   
   CordovaVC.swift:
   ```swift
   import UIKit
   
   class CordovaVC: CDVViewController {
   
       override func viewDidLoad() {
           self.wwwFolderName = "./"
           self.startPage = "/index.html"
   
           super.viewDidLoad()
   
           // Do any additional setup after loading the view.
       }
   
       override func didReceiveMemoryWarning() {
           super.didReceiveMemoryWarning()
           // Dispose of any resources that can be recreated.
       }
   }
   ```
   
   config.xml:
   ```xml
   <?xml version='1.0' encoding='utf-8'?>
   <widget id="com.example.hello" version="1.0.0" 
xmlns="http://www.w3.org/ns/widgets"; 
xmlns:cdv="http://cordova.apache.org/ns/1.0";>
       <name>HelloWorld</name>
       <description>
           A sample Apache Cordova application that responds to the deviceready 
event.
       </description>
       <feature name="CDVWKWebViewEngine">
           <param name="ios-package" value="CDVWKWebViewEngine" />
       </feature>
       <preference name="CordovaWebViewEngine" value="CDVWKWebViewEngine" />
       <feature name="Console">
              <param name="ios-package" value="CDVLogger" />
              <param name="onload" value="true" />
      </feature>
       <author email="[email protected]" href="http://cordova.io";>
           Apache Cordova Team
       </author>
       <content src="index.html" />
       <plugin name="cordova-plugin-whitelist" spec="1" />
       <access origin="*" />
       <allow-navigation href="*"/>
       <allow-intent href="http://*/*"; />
       <allow-intent href="https://*/*"; />
       <allow-intent href="tel:*" />
       <allow-intent href="sms:*" />
       <allow-intent href="mailto:*"; />
       <allow-intent href="geo:*" />
       <platform name="android">
           <allow-intent href="market:*" />
       </platform>
       <platform name="ios">
           <allow-intent href="itms:*" />
           <allow-intent href="itms-apps:*" />
       </platform>
       <engine name="ios" spec="^4.5.4" />
   </widget>
   ```
   
   index.html
   ```html
   <html>
       <head>
           <meta name="format-detection" content="telephone=no">
               <meta name="msapplication-tap-highlight" content="no">
                   <meta name="page_hybrid">
                       <meta name="viewport" content="user-scalable=no, 
initial-scale=1, maximum-scale=1, minimum-scale=1, width=device-width">
                           <meta http-equiv="Content-Security-Policy" 
content="default-src *; script-src 'self' 'unsafe-inline'; style-src 'self' 
'unsafe-inline'; media-src *; img-src 'self' data:">
                           <link rel="stylesheet" type="text/css" 
href="index.css">
                               <title>Hello World</title>
                               </head>
       <body>
           <div class="app">
               <h1>Cordova</h1>
               <form>
                   <input type="text" name="txt1" id="txt1">
                       <input type="text" name="txt2" value="this is a text" 
id=txt2>
                           <br><br>Gender Blender:
                           <br><br><input id="male" type="radio" name="gender" 
value="male" checked> Male
                               <br><br><input id="female" type="radio" 
name="gender" value="female"> Female
                                   <br><br><input id="other" type="radio" 
name="gender" value="other"> Other
                                       <br><br>checkbox: <input id="checkbox" 
type="checkbox" name="vehicle1" value="Bike">I have a bike<br>
                                           <br><br>button: <input id="button1" 
type="button" onclick="alert('Hello World!')" value="Click Me!">
                                               <br><br>date: <input 
id="dateBday" type="date" name="bday">
                                                   <br><br>email: <input 
id="email" type="email" name="email">
                                                       <br><br>number: <input 
id="number1" type="number" name="quantity" min="1" max="5">
                                                           <br><br>button: 
<input id="button2" type="button" onclick="window.location = 'test.html';" 
value="navigate">
                                                               
<br><br>password: <input id="password1" type="password" name="pwd">
                                                                   </form>
           </div>
           <script type="text/javascript" src="cordova.js"></script>
           <script type="text/javascript" src="index.js"></script>
           <script type="text/javascript" src="slave.js"></script>
           <script type="text/javascript" src="jsBridge.js"></script>
       </body>
   </html>
   ```
   
   Does anyone have an idea about this issue?
   
   Thanks in advance.

----------------------------------------------------------------
This is an automated message from the Apache Git Service.
To respond to the message, please log on to GitHub and use the
URL above to go to the specific comment.
 
For queries about this service, please contact Infrastructure at:
[email protected]


With regards,
Apache Git Services

---------------------------------------------------------------------
To unsubscribe, e-mail: [email protected]
For additional commands, e-mail: [email protected]

Reply via email to