locked
C# WebView InvokeScriptAsync fails to execute when called during DOMContent_Loaded event when using ms-appx-web or ms-appdata

    Question

  • C# WebView InvokeScriptAsync fails to execute when called during DOMContent_Loaded event when using ms-appx-web or ms-appdata

    I have a script that I want to execute immediately after the content loads and I need to pass a parameter to the script using InvokeScriptAsync("doSomething",new string[]{ specialValue }); It makes sense that we would wait until the DOM content has loaded before attempting to InvokeScriptAsync(), so I put that call inside of the DOMContent_Loaded event. It works fine if I use NavigateToString, but it fails if I use ms-appx-web or ms-appdata content. I can't seem to find anywhere that documents that this is expected behavior.

    I have posted a sample file in onedrive here:  https://onedrive.live.com/redir?resid=8E51ECA011D55300!39875&authkey=!AFHOKzfk_KECaL4&ithint=file%2c.zip

    If you run the InvokeScript sample (which I have modified) it works.

    If you run the NavigateToPackage sample (which I have also similarly modified) it fails.

    Any ideas?

    Monday, June 02, 2014 4:00 AM

Answers

  • Interesting. It also fails with NavigationCompleted.  Since you're doing this on load, perhaps you can do it directly in javascript in the body onload event?

    Matt Small - Microsoft Escalation Engineer - Forum Moderator
    If my reply answers your question, please mark this post as answered.

    NOTE: If I ask for code, please provide something that I can drop directly into a project and run (including XAML), or an actual application project. I'm trying to help a lot of people, so I don't have time to figure out weird snippets with undefined objects and unknown namespaces.

    Monday, June 02, 2014 2:30 PM
    Moderator