locked
C# app with webview and Cordova for windows 8.1/10.0 RRS feed

  • Question

  • I am building a hybrid application in C# and am including a WebView. This WebView needs to include Cordova. This is port of something we already do in IOS (objective C and Cordova WebView) and Android. The problem is that the latest Cordova for Windows 8.1 and even Windows Phone 8.1 is all based on Windows JavaScript runtime. So I took cordova platform generated code and included in a WebView. The issue I ran into is that Windows JavaScript based store app somehow have access to "Windows" namespace in the browser. In case of a webview the "Windows" namespace is missing in JavaScript. Cordova depends on "Windows" runtime api being present in the browser.  

    My guess is that when Windows Javascript based store app is created, Microsoft framework is somehow creating a single WebView with IE and putting in the "Windows" namespace inside it. Is there a way I can add access to the "Windows" namespace inside the a WebView created from C#. In android there is webView.addJavascriptInterface (Windows, "Windows"). 

    I know that if the app is Windows JavaScript based, I can add a C# component that can be called from JavaScript. But that is not what I want, I want C# WebView with Cordova. 

    Any help is appreciated

     
    Wednesday, February 18, 2015 11:20 PM

All replies

  • This won't be possible. The Xaml WebView is strongly isolated from the system. You would need to plumb your own communication between the WebView contents and the Xaml host app to access the Windows Runtime. You'd essentially need to rewrite the entire Cordova app to host communications system.

    As you note, Cordova apps on Windows run in the JavaScript environment rather than being hosted in a WebView within the Xaml environment. On Windows HTML/JavaScript is a first class UI framework equal to other first class frameworks such as Xaml and DirectX. The HTML environment is not just a web browser hosted in another framework.

    --Rob

    Wednesday, February 18, 2015 11:30 PM
    Moderator
  • I appreciate your answer. The issue with adding my own communication between the WebView and the xaml host app to access the Windows Runtime is that Cordova will not work. None of the Cordova plugins will work either. We heavily depend on Cordova Plugins. The hybrid webview approach works well with IOS and Android. Looks like Cordova went down that route with WP8, but abounded it for WP8.1 in favor of JavaScript app.

    Any chance that WebView for Windows 10 will add support for it. We are actually targeting Windows 10.

    Thanks,

    Venkata

    Wednesday, February 18, 2015 11:58 PM
  • Why do you need to use the Xaml host? Can you write the main application in HTML/JavaScript? That's the only way you'll be able to have a Cordova app with OS integration as well as the surrounding native app.

    We can discuss only currently available versions here. The developer story for Windows 10 hasn't yet been announced.

    Thursday, February 19, 2015 12:17 AM
    Moderator
  • Writing the main application in HTML/JavaScript will also not work. We depend on multiple cordova weviews. So I run into the same problem by including "x-ms-webview" inside JavaScript/HTML page. 

    Thanks,

    Venkata

    Thursday, February 19, 2015 12:22 AM