feat: add eval_with_callback to Webview and WebviewWindow#14925
feat: add eval_with_callback to Webview and WebviewWindow#14925Legend-Master merged 3 commits intotauri-apps:devfrom
eval_with_callback to Webview and WebviewWindow#14925Conversation
Package Changes Through ecd94c1There are 9 changes which include tauri-macos-sign with patch, tauri-build with patch, tauri with minor, tauri-runtime with minor, tauri-runtime-wry with minor, tauri-bundler with minor, tauri-cli with minor, @tauri-apps/cli with minor, tauri-utils with minor Planned Package VersionsThe following package releases are the planned based on the context of changes in this pull request.
Add another change file through the GitHub UI by following this link. Read about change files or the docs at github.com/jbolda/covector |
|
There are two test failures in this run, but they appear to be flaky. I pushed the exact same commit to my fork and all tests passed there without issues. Could you please re-run the GitHub Actions? @FabianLars |
|
don't worry about it. the android builds regularly fail cause the cache breaks for some reason. meant to delete the caches for another PR but the mobile gh app is horrible x) will do now |
Legend-Master
left a comment
There was a problem hiding this comment.
Looking good from a glance, just some nitpicks on the docs, thanks!
Do you mind also adding a change file?
https://github.com/tauri-apps/tauri/blob/dev/.changes/README.md
close #5441
This PR adds a new method
eval_with_callbackto tauri::webview::Webview and tauri::webview::WebviewWindow, providing a way to evaluate JavaScript in the webview and receive the evaluation result (serialized as a JSON string) via a callback function.The feature addresses the long-standing request in #5441
The change is non-breaking, fully backward-compatible, and ready for integration.
Implementation Details
eval_script_with_callbackto the tauri_runtime::WebviewDispatch trait.handle_user_messageby forwarding towry::WebView::evaluate_script_with_callback.eval_with_callbackon both tauri::webview::Webview and tauri::webview::WebviewWindow.The implementation closely follows the existing pattern for
eval_scriptto ensure consistency, minimal code duplication, and proper tracing span propagation when thetracingfeature is enabled.Platform Support (Android)
The underlying wry::WebView::evaluate_script_with_callback method is documented as "Android: Not implemented yet."
In my own real-world testing on Android devices, the method actually works correctly — the callback is invoked with the expected JSON-serialized result, and no errors occur.
However, to respect the wry documentation and avoid promising unsupported behavior,
eval_with_callbackdocumentation includes the same warning: "Android: Not implemented yet." Users should be aware that while it may work in practice (as verified in testing), it is not officially guaranteed by wry.Tested Example
The following command was tested successfully on both Windows and Android, correctly returning the evaluated result on both platforms: