Issue with UWP getHtmlPrintDocumentSourceAsync( when used along with x-ms-webview)

0

My app uses x-ms-webview for other requirements. We create the HTML element x-ms-webview and add it to DOM. After its functionality is done, we remove it from DOM.

My app also uses Windows document Printing. It uses Windows.Graphics.Printing(PrintManager.ShowPrintUIAsync). The data to printed is converted to HTMLDocumnentSource using the API MSApp.getHtmlPrintDocumentSourceAsync(page)

I notice this error, that whenever the x-ms-webview is removed from DOM, the MSApp.getHtmlPrintDocumentSourceAsync(page) throws the below error
Unhandled exception at line 357, column 1 in res://edgehtml.dll/preview.js​ ​0x8000ffff - JavaScript runtime error: Unexpected call to method or property access

This is sample code

1. Create a sample Cordova UWP app.
2. Add the x-ms-webview for example on button click as shown below


     var wv =  document.createElement('x-ms-webview'); // Use CSS to  set width, height and other styles
        wv.navigate("https://www.example.com");
         wv.id = "test145";
3. Now remove the web view on another action as shown below:
    var obj1=  document.getElementById(“test145”)
    obj1.parentNode.removeChild(obj1)
4. Try to perform printing, invoke as shown below:
    Windows.Graphics.Printing.PrintManager.showPrintUIAsync()

The removal of x-ms-webview from the DOM causes this issue. If I hide the webview, the issue is not seen. Does anybody know what the dependency of the webview with these Printer API. Is there any workaround for this?

javascript
windows
cordova
webview
uwp
asked on Stack Overflow Jul 17, 2019 by Sandeep Nagaraj • edited Jul 18, 2019 by Xie Steven

0 Answers

Nobody has answered this question yet.


User contributions licensed under CC BY-SA 3.0