locked
How to get who sends window.external.notify command?

    Question

  • We'd like to restrict the sender of "window.external.notify" command to our WinRT component to JS level. Is there a way that we can get which JS file issued this command in our WinRT comoponent?

    Friday, February 22, 2013 8:43 PM

Answers

  • Can you please explain what you mean in more detail? Are you writing a Windows Runtime Component to host in a WinJS app that you want to handle window.external.notify? Or are you hosting sites in a Xaml WebView and handling the ScriptNotify event? In the latter case, you can limit the URI's which can call notify with the AllowedScriptNotifyUris property.

    • Marked as answer by Jesse Jiang Thursday, February 28, 2013 2:51 AM
    Saturday, February 23, 2013 2:53 AM
    Owner
  • No, there isn't a way to detect which file generated the notify, nor to block it more finely than by URI.

    The only information passed along with the notification is in the NotifyEventArgs, under the control of the caller.

    --Rob

    • Marked as answer by Jesse Jiang Thursday, February 28, 2013 2:51 AM
    Monday, February 25, 2013 2:39 AM
    Owner

All replies

  • Can you please explain what you mean in more detail? Are you writing a Windows Runtime Component to host in a WinJS app that you want to handle window.external.notify? Or are you hosting sites in a Xaml WebView and handling the ScriptNotify event? In the latter case, you can limit the URI's which can call notify with the AllowedScriptNotifyUris property.

    • Marked as answer by Jesse Jiang Thursday, February 28, 2013 2:51 AM
    Saturday, February 23, 2013 2:53 AM
    Owner
  • We have a SDK that contains two parts: one JS file that developer can use in their website (or WebView in windows 8 app) and one WinRT component that can be loaded into Windows 8 app. The WinRT component handles the ScriptNotify event from the WebView. Since the JS file is loaded into the WebView, the JS file and WinRT component can communicate with each other through window.external.notify and InvokeScript.

    Since the developer using our SDK may need to send window.external.notify to their own component from the same WebView, limiting the AllowedScriptNotifyUris to ours won't work. And also adding our JS file which will be loaded to the WebView to AllowedScriptNotifyUris basically allows the webpage (including other JS files) that loads the JS file to send the window.external.notify command. What we need may be to detect who send "window.external.notify" command to us (WinRT component), if it is our, handle it, otherwise, ignore it. Is this possible? Or is there another way we can prevent others sending "window.external.notify" to our WinRT component?

    Monday, February 25, 2013 1:17 AM
  • No, there isn't a way to detect which file generated the notify, nor to block it more finely than by URI.

    The only information passed along with the notification is in the NotifyEventArgs, under the control of the caller.

    --Rob

    • Marked as answer by Jesse Jiang Thursday, February 28, 2013 2:51 AM
    Monday, February 25, 2013 2:39 AM
    Owner