Skip to content

[desktop_webview_window] Add support for registerJavaScriptMessageHandler on Linux#452

Merged
boyan01 merged 2 commits into
MixinNetwork:mainfrom
Carapacik:webview/linux
Nov 26, 2025
Merged

[desktop_webview_window] Add support for registerJavaScriptMessageHandler on Linux#452
boyan01 merged 2 commits into
MixinNetwork:mainfrom
Carapacik:webview/linux

Conversation

@Carapacik
Copy link
Copy Markdown
Contributor

@Carapacik Carapacik commented Nov 25, 2025

registerJavaScriptMessageHandler and unregisterJavaScriptMessageHandler on Linux

Example of usage

<button onclick="window.webkit.messageHandlers.onTokenReceived.postMessage('test-token')">
            Send Token
</button>

Reopen #428

Copy link
Copy Markdown
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 PR adds support for registerJavaScriptMessageHandler and unregisterJavaScriptMessageHandler on Linux, allowing JavaScript in webviews to communicate with Flutter code using the WebKit message handler API (window.webkit.messageHandlers.<handlerName>.postMessage()).

Key changes:

  • Implemented Linux platform support for JavaScript message handlers in C++ using WebKit's user content manager API
  • Updated Dart code to enable these methods on Linux in addition to macOS
  • Bumped package version from 0.2.4 to 0.2.5

Reviewed changes

Copilot reviewed 7 out of 8 changed files in this pull request and generated 7 comments.

Show a summary per file
File Description
packages/desktop_webview_window/lib/src/webview_impl.dart Modified platform checks to enable JavaScript message handlers on Linux; attempted to clean up null safety code
packages/desktop_webview_window/linux/webview_window.h Added method declarations for RegisterJavaScriptChannel and UnregisterJavaScriptChannel
packages/desktop_webview_window/linux/webview_window.cc Implemented JavaScript message handler registration/unregistration using WebKit APIs
packages/desktop_webview_window/linux/desktop_webview_window_plugin.cc Added method call handlers for registerJavaScripInterface and unregisterJavaScripInterface
packages/desktop_webview_window/pubspec.yaml Bumped version to 0.2.5 and relaxed flutter_lints constraint
packages/desktop_webview_window/CHANGELOG.md Documented the new Linux support for JavaScript message handlers
packages/desktop_webview_window/example/pubspec.lock Updated dependency versions
packages/desktop_webview_window/example/macos/Flutter/GeneratedPluginRegistrant.swift Updated plugin import from path_provider_macos to path_provider_foundation

💡 Add Copilot custom instructions for smarter, more guided reviews. Learn how to get started.

Comment thread packages/desktop_webview_window/lib/src/webview_impl.dart Outdated
Comment thread packages/desktop_webview_window/lib/src/webview_impl.dart Outdated
Comment thread packages/desktop_webview_window/lib/src/webview_impl.dart Outdated
Comment on lines +425 to +430
void WebviewWindow::UnregisterJavaScriptChannel(const std::string &name) {
WebKitUserContentManager *manager =
webkit_web_view_get_user_content_manager(WEBKIT_WEB_VIEW(webview_));

webkit_user_content_manager_unregister_script_message_handler(manager, name.c_str());
}
Copy link

Copilot AI Nov 25, 2025

Choose a reason for hiding this comment

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

When unregistering a JavaScript channel, the signal handler connected in RegisterJavaScriptChannel is not disconnected, leading to a memory leak. The HandlerData allocated on line 383 will never be freed after unregistration because the destroy notify callback on line 419-421 will not be invoked.

Consider storing the signal handler ID returned by g_signal_connect_data and calling g_signal_handler_disconnect in UnregisterJavaScriptChannel before unregistering the script message handler.

Copilot uses AI. Check for mistakes.
Comment thread packages/desktop_webview_window/linux/desktop_webview_window_plugin.cc Outdated
Comment thread packages/desktop_webview_window/linux/desktop_webview_window_plugin.cc Outdated
Comment thread packages/desktop_webview_window/linux/desktop_webview_window_plugin.cc Outdated
@boyan01 boyan01 merged commit 21bc41b into MixinNetwork:main Nov 26, 2025
@boyan01
Copy link
Copy Markdown
Contributor

boyan01 commented Nov 26, 2025

LGTM, Thanks for the PR

@Carapacik Carapacik deleted the webview/linux branch November 26, 2025 11:09
@Carapacik
Copy link
Copy Markdown
Contributor Author

@boyan01 When will you publish the version on pub.dev?

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment

Labels

None yet

Projects

None yet

Development

Successfully merging this pull request may close these issues.

3 participants