KEMBAR78
[HybridWebView] Fix some issues with the typescript by mattleibow · Pull Request #29873 · dotnet/maui · GitHub
Skip to content

Conversation

@mattleibow
Copy link
Member

Description of Change

The older Android versions have a weird Chrome version with weird JS support.

See also #29829

@Copilot Copilot AI review requested due to automatic review settings June 6, 2025 22:15
@mattleibow mattleibow requested a review from a team as a code owner June 6, 2025 22:15
@mattleibow mattleibow requested review from jfversluis and rmarinho June 6, 2025 22:15
Copy link
Contributor

Copilot AI left a comment

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Pull Request Overview

This pull request addresses TypeScript issues in the HybridWebView implementation to improve compatibility with older Android versions that exhibit unusual Chrome behavior. The changes include replacing optional chaining with explicit property checks and refactoring the public API functions from inline object literal methods to standalone function declarations that are then assembled into the HybridWebView object.

Reviewed Changes

Copilot reviewed 2 out of 2 changed files in this pull request and generated 3 comments.

File Description
src/Core/src/Handlers/HybridWebView/HybridWebView.ts Replaced optional chaining with explicit null checks and refactored inline method declarations into standalone functions for clarity and compatibility.
src/Core/src/Handlers/HybridWebView/HybridWebView.js Applied similar changes as in TypeScript for consistent behavior on multiple platforms, with improved compatibility checks and API refactoring.
Comments suppressed due to low confidence (1)

src/Core/src/Handlers/HybridWebView/HybridWebView.js:117

  • [nitpick] Moving from inline method definitions to standalone functions improves the structure of the API. Verify that the new function names are used consistently throughout the code.
function sendRawMessage(message) {

Comment on lines +71 to +76
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) {
Copy link

Copilot AI Jun 6, 2025

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

[nitpick] Explicitly checking for each nested property improves compatibility with older platforms. If this pattern recurs, consider extracting it into a helper function to improve readability and maintainability.

Copilot uses AI. Check for mistakes.

*
* @param message The message to send to the .NET host application.
*/
function sendRawMessage(message: string) {
Copy link

Copilot AI Jun 6, 2025

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

[nitpick] Refactoring inline object literal methods into standalone function declarations enhances clarity and modularity. Please ensure consistency in naming and ordering across similar functions for a uniform API.

Suggested change
function sendRawMessage(message: string) {
export function sendRawMessage(message: string) {

Copilot uses AI. Check for mistakes.

Comment on lines +21 to +27
if (window.chrome && window.chrome.webview && window.chrome.webview.addEventListener) {
// Windows WebView2
window.chrome.webview.addEventListener('message', (arg) => {
dispatchHybridWebViewMessage(arg.data);
});
}
else if (window.webkit?.messageHandlers?.webwindowinterop) {
else if (window.webkit && window.webkit.messageHandlers && window.webkit.messageHandlers.webwindowinterop) {
Copy link

Copilot AI Jun 6, 2025

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.

Copilot uses AI. Check for mistakes.

@rmarinho rmarinho merged commit 8108c34 into main Jun 7, 2025
121 of 130 checks passed
@rmarinho rmarinho deleted the dev/hybridwebview-fixes branch June 7, 2025 13:16
@github-actions github-actions bot locked and limited conversation to collaborators Jul 8, 2025
Sign up for free to subscribe to this conversation on GitHub. Already have an account? Sign in.

Labels

None yet

Projects

None yet

Development

Successfully merging this pull request may close these issues.

2 participants