locked
Webview Scriptnotify in windows 8.1

    Question

  • Hi I am developing an epub reader application.

    I faced limitations in window 8 webview regarding the source of the data to be displayed.

    In 8.1 we are now able to show data from

    ms-appdata:///local/

    into webview but I found that I cannot apply scriptnotify over this. I do download .zip files into local storage,then unzip into a folder and loop over files to display on webview but I need scriptnotify to work in order to switch between html files inside unzipped folder.

    The files that I Want to display inside the application do change according to user. So I cannot place files inside application project. Also I cannot use navigateToString because my html files have css files and images with them.

    As I understood NavigateToStreamUri  can resolve this issue. But css files,images,js files are not the same for all files I display.

    They are inside the unzipped folder of each item (book) under local storage.

    How can I solve this?

    Friday, April 25, 2014 9:26 AM

Answers

  • From the documentation:

    Windows 8.1

    To enable an external web page to fire the ScriptNotify event when calling window.external.notify, you must include the page's URI in the ApplicationContentUriRules section of the app manifest. (You can do this in Visual Studio on the Content URIs tab of the Package.appxmanifest designer.) The URIs in this list must use HTTPS and may contain subdomain wildcards (for example, "https://*.microsoft.com"), but they can't contain domain wildcards (for example, "https://*.com" and "https://*.*"). The manifest requirement does not apply to content that originates from the app package, uses an ms-local-stream:// URI, or is loaded using NavigateToString.

    I don't know why you're having problems with ScriptNotify.


    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.

    Friday, April 25, 2014 12:45 PM
    Moderator
  • OK - you're right, this isn't going to work:

    http://msdn.microsoft.com/en-us/library/windows/apps/Hh781215.aspx

    App data

    Sometimes it is useful to refer to resources you have downloaded from the Internet to your app’s local ApplicationData storage (via Windows Runtime APIs). To refer to such content, you must use the scheme "ms-appdata:", with the path to the file within your ApplicationData local storage. Note that, for security reasons, you cannot navigate to HTML you have downloaded to this location and you cannot run any executable or potentially executable code, such as script or CSS. It is intended for media such as images or videos and the like.

    The only way this can work is with NavigateToStreamUri.  You'll have to decide how you're going to work around the different image Uri issues.


    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.

    Friday, April 25, 2014 7:03 PM
    Moderator
  • There definitely is no way to open a password-protected zip file using WinRT at this time.

    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.

    Tuesday, April 29, 2014 6:21 PM
    Moderator

All replies

  • From the documentation:

    Windows 8.1

    To enable an external web page to fire the ScriptNotify event when calling window.external.notify, you must include the page's URI in the ApplicationContentUriRules section of the app manifest. (You can do this in Visual Studio on the Content URIs tab of the Package.appxmanifest designer.) The URIs in this list must use HTTPS and may contain subdomain wildcards (for example, "https://*.microsoft.com"), but they can't contain domain wildcards (for example, "https://*.com" and "https://*.*"). The manifest requirement does not apply to content that originates from the app package, uses an ms-local-stream:// URI, or is loaded using NavigateToString.

    I don't know why you're having problems with ScriptNotify.


    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.

    Friday, April 25, 2014 12:45 PM
    Moderator
  • I did try

    string url = "ms-appdata:///local/" + filename + "/" + rootfolder + "/" + htmlfile.Name;
    webView1.Navigate(new Uri(url));
    webView1.ScriptNotify += MyWebview_ScriptNotify_1;


    file is displayed but the sub Mywebview_scriptnotify_1 doesn't get called.

    When I replace url value with this

     url = "ms-appx-web:///test.html";

    where test file is inside project it works. I did check the same behaviour in here

    http://social.msdn.microsoft.com/Forums/windowsapps/en-US/7a5caded-3d6f-4ff2-91c3-746dd03ca8eb/webview-scriptnotify-from-msappdata?forum=w81prevwCsharp

    I am working on epub files.

    And you were saying that

    To enable an external web page to fire the ScriptNotify event when calling window.external.notify, you must include the page's URI in the  ApplicationContentUriRules section of the app manifest.

    But my uris aren't fixed they do change for each user and for each epub file selected.


    • Edited by Mahagh Friday, April 25, 2014 2:00 PM
    Friday, April 25, 2014 1:58 PM
  • OK - you're right, this isn't going to work:

    http://msdn.microsoft.com/en-us/library/windows/apps/Hh781215.aspx

    App data

    Sometimes it is useful to refer to resources you have downloaded from the Internet to your app’s local ApplicationData storage (via Windows Runtime APIs). To refer to such content, you must use the scheme "ms-appdata:", with the path to the file within your ApplicationData local storage. Note that, for security reasons, you cannot navigate to HTML you have downloaded to this location and you cannot run any executable or potentially executable code, such as script or CSS. It is intended for media such as images or videos and the like.

    The only way this can work is with NavigateToStreamUri.  You'll have to decide how you're going to work around the different image Uri issues.


    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.

    Friday, April 25, 2014 7:03 PM
    Moderator
  • Is there any available code for a resolver that gets content from epub file or .zip file?

    I did try the following

    private async Task<IInputStream> GetZipEntryStream(string archiveElement)
            {
                string scheme = "ms-appdata://" + bookSourceName;
    
                    var f = scheme.Split('/');
                   string filename = f[f.Length - 1] ;
               
                var bookSourceFile = await  ApplicationData.Current.LocalFolder.GetFileAsync(filename);
                Stream bookZipStream = await bookSourceFile.OpenStreamForReadAsync();
                ZipArchive bookArchive = new ZipArchive(bookZipStream, ZipArchiveMode.Read);
                 ZipArchiveEntry bookContentFile = bookArchive.GetEntry(archiveElement);
    
                if (bookContentFile == null)
                   throw new Exception("Invalid archive entry");
                else
                    return bookContentFile.Open().AsInputStream();
    
            }
    It takes the html file name to open from the .zip file.

    While debugging it goes to return bookContentFile.Open().AsInputStream();

    and continue normally, once there is no more code the application closes on its own. Am not sure what is causing this. No error is shown as if the app breaks down. To be noted that my .zip files have password over them and in the code I didn't pass any password,could it be the reason for this behavior ?

    I need to view an example of a resolver that shows content of .zip file with password.

    Tuesday, April 29, 2014 7:25 AM
  • There definitely is no way to open a password-protected zip file using WinRT at this time.

    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.

    Tuesday, April 29, 2014 6:21 PM
    Moderator