Any Url script to notify windows 10 webview

1.7k Views Asked by At

From windows 8.1, AllowedScriptNotifyUris property of webview get obsoleted and intenseness asked to set URLs in ApplicationContentUriRules under package manifest file.

It wont allow to write * in the url matching criteria as mentioned below.

<uap:ApplicationContentUriRules>
    <uap:Rule Match="*" Type="include" WindowsRuntimeAccess="all" />
</uap:ApplicationContentUriRules>

I am not sure what URL will be loaded in webview, i want either all url to notify the script or any other way of dynamically adding URL in manifest file.

3

There are 3 best solutions below

0
On

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 Microsoft 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 cannot 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.

From https://msdn.microsoft.com/en-us/library/windows/apps/windows.ui.xaml.controls.webview.aspx

0
On

As was written above reason is in URI rules. Here is the answer as well.

Here is my working example for localhost: enter image description here

1
On

You should add wildcard for all sub domains as well. Something like this:

<uap:Rule Match="https://*" Type="include" WindowsRuntimeAccess="all" />
<uap:Rule Match="https://*.*" Type="include" WindowsRuntimeAccess="all" />
<uap:Rule Match="https://*.*.*" Type="include" WindowsRuntimeAccess="all" />
<uap:Rule Match="https://*.*.*.*" Type="include" WindowsRuntimeAccess="all" />
<uap:Rule Match="https://*.*.*.*.*" Type="include" WindowsRuntimeAccess="all" />
<uap:Rule Match="https://*.*.*.*.*.*" Type="include" WindowsRuntimeAccess="all" />
<uap:Rule Match="https://*.*.*.*.*.*.*" Type="include" WindowsRuntimeAccess="all" />

Be careful with this since it will expose all WinRT APIs to any url opens inside your app (webview). You may use MSWebViewNavigationStarting event on webview to monitor all navigations inside your webview.