locked
ScriptNotfiy never fired

    Question

  • Hi,

    I have a webview with a local http server and I am loading an html file with the following content :

    <!DOCTYPE html>
    <html>
    <head>
        <title>Test</title>
        <script>
            function myFunction() {
                window.external.notify('notified');
                document.getElementById("demo").innerHTML = "Hello World";
            }
        </script>
    </head>
    <body>
        <p>Click the button to trigger a function.</p>
        <button onclick="myFunction()">Click me</button>
        <p id="demo"></p>
    </body>
    </html>
    public WebBasedView()
            {
                this.InitializeComponent();
    
                _objViewModel = new WebBasedViewModel();
                this.DataContext = _objViewModel;
    
                _objViewModel.NavigationHelper = new NavigationHelper(this);
                _objViewModel.NavigationHelper.LoadState += navigationHelper_LoadState;
                _objViewModel.NavigationHelper.SaveState += navigationHelper_SaveState;
    
    
                webView.NavigationCompleted += webView_NavigationCompleted;
                webView.NavigationStarting += webView_NavigationStarting;
                webView.ScriptNotify += webView_ScriptNotify;
            }
    protected async override void OnNavigatedTo(NavigationEventArgs e)
            {
                BookDataItem bdi = (BookDataItem)e.Parameter;
                _objViewModel.Container = bdi.Container;
                if (_objViewModel.Container != null)
                {
                    _objViewModel.Package = bdi.Package;
                    _objViewModel.Package2 = bdi.Package2;
     
                    mServer = new EpubServer(this, _objViewModel.Package, _objViewModel.Package2);
                    await mServer.Start();
    
                    webView.Navigate(new Uri(string.Format("http://127.0.0.1:{0}/{1}", mServer.Port, HTTP_READER_URI)));
                }
    
                _objViewModel.NavigationHelper.OnNavigatedTo(e);
            }

    void webView_ScriptNotify(object sender, NotifyEventArgs e)
            {
                DecodeReadiumNotifications(e.Value);
            }

    However I don't receive the ScriptNotify event.

    Any idea why ?



    • Edited by Vincent Rich Tuesday, February 11, 2014 3:58 PM a
    Tuesday, February 11, 2014 3:51 PM

Answers

All replies

  • Is your page registered in your ApplicationContentUriRules?

    See the remarks in the ScriptNotify event documentation.

    Also consider that local loopback connections are blocked for production code. Visual Studio enables them for debugging, but that connection should fail outside of VS.

    --Rob


    Tuesday, February 11, 2014 3:58 PM
    Owner
  • Argh you are kidding right ?

    And I cannot add a http ApplicationContentUriRules we have to declare a https ...

    You mean I cannot use a local http server(based on a StreamSocketListener) listening on 127.0.0.1 in a Windows Store app ?



    Tuesday, February 11, 2014 4:26 PM
  • Correct. You cannot make a local network connection to a process outside of your app package (you can loop back to your own package).

    --Rob

    Friday, February 14, 2014 10:56 PM
    Owner