thunder-webview-blazor
v1.9.6
Published
A basic JS wrapper around various webview messaging systems, allowing for an easy interface to interact with.
Downloads
4
Maintainers
Readme
This is a small library to integrate the thunder-webview library with Microsoft's Blazor Js Interop.
This extends the messenger in the thunder-webview library to automatically send the response to the interop system when the callback is triggered.
This project is part of the Thunder.WebView project which is C# library for writing a multi-platform webview in a more native manner without requiring node (aka Electron).
To use, in a hosted webview, you can either add the browser script manually:
//include script
<scripts src="/dist/thunder.webview.browser.js" />
<scripts src="/dist/thunder.webview.blazor.browser.js" />
//create request object
var request = {
RequestId: "requestId",
Message: {} // object to be parsed as the message handler args
};
//using callbacks
_webviewInterop.sendRequest(request);
//or using async/await
await _webviewInterop.sendRequestAsync(request)
If you don't want the global scope _webview (e.g. want to reference the module), you can reference the BlazorInteropWebViewMessenger
directly instead.
//import
import {BlazorInteropWebViewMessenger} from "thunder-webview/lib/BlazorInteropWebViewMessenger"
var messenger = new BlazorInteropWebViewMessenger();
//using callbacks
messenger.sendRequest(request);
//or using async/await
await messenger.sendRequestAsync(request)
Note that JS Interop needs a global/static reference to call, so it's suggested that your messenger is saved somewhere in the global scope.