-
Notifications
You must be signed in to change notification settings - Fork 1.9k
[HybridWebView] Fix some issues with the typescript #29873
New issue
Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.
By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.
Already on GitHub? Sign in to your account
Changes from all commits
File filter
Filter by extension
Conversations
Jump to
Diff view
Diff view
There are no files selected for viewing
| Original file line number | Diff line number | Diff line change | ||||
|---|---|---|---|---|---|---|
|
|
@@ -68,12 +68,12 @@ interface DotNetInvokeResult { | |||||
| } | ||||||
|
|
||||||
| // Determine the mechanism to receive messages from the host application. | ||||||
| if (window.chrome?.webview?.addEventListener) { | ||||||
| if (window.chrome && window.chrome.webview && window.chrome.webview.addEventListener) { | ||||||
| // Windows WebView2 | ||||||
| window.chrome.webview.addEventListener('message', (arg: any) => { | ||||||
| dispatchHybridWebViewMessage(arg.data); | ||||||
| }); | ||||||
| } else if (window.webkit?.messageHandlers?.webwindowinterop) { | ||||||
| } else if (window.webkit && window.webkit.messageHandlers && window.webkit.messageHandlers.webwindowinterop) { | ||||||
|
Comment on lines
+71
to
+76
|
||||||
| // iOS and MacCatalyst WKWebView | ||||||
| // @ts-ignore - We are extending the global object here | ||||||
| window.external = { | ||||||
|
|
@@ -89,10 +89,10 @@ interface DotNetInvokeResult { | |||||
| } | ||||||
|
|
||||||
| // Determine the function to use to send messages to the host application. | ||||||
| if (window.chrome?.webview) { | ||||||
| if (window.chrome && window.chrome.webview) { | ||||||
| // Windows WebView2 | ||||||
| sendMessageFunction = msg => window.chrome.webview.postMessage(msg); | ||||||
| } else if (window.webkit?.messageHandlers?.webwindowinterop) { | ||||||
| } else if (window.webkit && window.webkit.messageHandlers && window.webkit.messageHandlers.webwindowinterop) { | ||||||
| // iOS and MacCatalyst WKWebView | ||||||
| sendMessageFunction = msg => window.webkit.messageHandlers.webwindowinterop.postMessage(msg); | ||||||
| } else if (window.hybridWebViewHost) { | ||||||
|
|
@@ -160,89 +160,93 @@ interface DotNetInvokeResult { | |||||
| sendMessageToDotNet('__InvokeJavaScriptFailed', taskId + '|' + json); | ||||||
| } | ||||||
|
|
||||||
| const HybridWebView = { | ||||||
|
|
||||||
| /* | ||||||
| * Send a raw message to the .NET host application. | ||||||
| * The message is sent directly and not processed or serialized. | ||||||
| * | ||||||
| * @param message The message to send to the .NET host application. | ||||||
| */ | ||||||
| SendRawMessage: function (message: string) { | ||||||
| sendMessageToDotNet('__RawMessage', message); | ||||||
| }, | ||||||
|
|
||||||
| /* | ||||||
| * Invoke a .NET method on the InvokeJavaScriptTarget instance. | ||||||
| * The method name and parameters are serialized and sent to the .NET host application. | ||||||
| * | ||||||
| * @param methodName The name of the .NET method to invoke. | ||||||
| * @param paramValues The parameters to pass to the .NET method. If the method takes no parameters, this can be omitted. | ||||||
| * | ||||||
| * @returns A promise that resolves with the result of the .NET method invocation. | ||||||
| */ | ||||||
| InvokeDotNet: async function (methodName: string, paramValues?: any) { | ||||||
| const body: JSInvokeMethodData = { | ||||||
| MethodName: methodName | ||||||
| }; | ||||||
| /* | ||||||
| * Send a raw message to the .NET host application. | ||||||
| * The message is sent directly and not processed or serialized. | ||||||
| * | ||||||
| * @param message The message to send to the .NET host application. | ||||||
| */ | ||||||
| function sendRawMessage(message: string) { | ||||||
|
||||||
| function sendRawMessage(message: string) { | |
| export function sendRawMessage(message: string) { |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
[nitpick] The explicit property checks here replace optional chaining to support older environments. Consider a utility function if similar nested checks are needed in other parts of the codebase.