You signed in with another tab or window. Reload to refresh your session.You signed out in another tab or window. Reload to refresh your session.You switched accounts on another tab or window. Reload to refresh your session.Dismiss alert
When opening web page from the application local folder ms-appdata:///local/some.html, is messaging from the web to the react native app impossible.
Read more from social.msdn.microsoft.com
DOM7010: Unable to receive a ScriptNotify event from: ‘ms-local-stream://xyz.xyz_local_7573657273/some.html’.
The website attempted to send a ScriptNotify event to the app from a WebView URI that is not included in the ApplicationContentUriRules
for this app. To permit this event, add the URI to the ApplicationContentUriRules section of the package manifest.
(In Visual Studio, add this URI to the Content URIs tab of the Manifest Designer.)
Reason is that window.external.notify = window.ReactNativeWebView.postMessage is not allowed from local file ms-appdata:///local/some.html.
ApplicationContentUriRules is not possible to set ms-appdata scheme. See more from interacting-with-web-view-content that says 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
// UriToStreamResolver.h
#pragma once
#include <winrt/Windows.Web.h>
#include <winrt/Windows.Storage.h>
#include <winrt/Windows.Storage.Streams.h>
namespace winrt::ReactNativeWebView::implementation {
class UriToStreamResolver : public winrt::implements<UriToStreamResolver, winrt::Windows::Web::IUriToStreamResolver>
{
public:
UriToStreamResolver();
winrt::Windows::Foundation::IAsyncOperation<winrt::Windows::Storage::Streams::IInputStream> UriToStreamAsync(const winrt::Windows::Foundation::Uri& uri);
};
}
// UriToStreamResolver.cpp
#include "pch.h"
#include "UriToStreamResolver.h"
using namespace winrt::Windows::Storage;
namespace winrt::ReactNativeWebView::implementation {
UriToStreamResolver::UriToStreamResolver()
{}
winrt::Windows::Foundation::IAsyncOperation<winrt::Windows::Storage::Streams::IInputStream> UriToStreamResolver::UriToStreamAsync(const winrt::Windows::Foundation::Uri& uri)
{
auto safe_uri = uri;
auto file = co_await StorageFile::GetFileFromApplicationUriAsync(safe_uri);
auto stream = co_await file.OpenAsync(FileAccessMode::Read);
auto inputStream = stream.GetInputStreamAt(0);
co_return inputStream;
}
}
And using UriToStreamResolver in ReactWebViewManager::UpdateProperties() function
...
if (uriString.find("ms-appdata:///local/") == 0) {
auto streamResolver = UriToStreamResolver();
webView.NavigateToLocalStreamUri(winrt::Uri(to_hstring(uriString)), streamResolver);
}
...
but i did not manage to implement it right. I got error Microsoft C++ exception: winrt::hresult_invalid_argument at memory location 0x00000052B94FC158. and did not manage to find solution for that or right implementation.
Is someone found solution for that?
Environment:
OS: Windows 10
react-native version: 0.62.2
react-native-windows version: 0.62.5
react-native-webview version: 10.8.2
The text was updated successfully, but these errors were encountered:
I have implementation that has Bridge and window.external.notify is changed to use bridge __REACT_WEB_VIEW_BRIDGE.postMessage like old C# implementatio has. I will make PR later
Bug description:
When opening web page from the application local folder
ms-appdata:///local/some.html
, is messaging from the web to the react native app impossible.Read more from social.msdn.microsoft.com
Reason is that
window.external.notify
=window.ReactNativeWebView.postMessage
is not allowed from local filems-appdata:///local/some.html
.ApplicationContentUriRules is not possible to set ms-appdata scheme. See more from interacting-with-web-view-content that says
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
Solution:
Solution seems to be use WebView.NavigateToLocalStreamUri
Am I right?
Code
I tried to implement IUriToStreamResolver using C++
And using
UriToStreamResolver
inReactWebViewManager::UpdateProperties()
functionbut i did not manage to implement it right. I got error
Microsoft C++ exception: winrt::hresult_invalid_argument at memory location 0x00000052B94FC158.
and did not manage to find solution for that or right implementation.Is someone found solution for that?
Environment:
The text was updated successfully, but these errors were encountered: