-
-
Notifications
You must be signed in to change notification settings - Fork 1.5k
[V3] Add origin to raw message handler #4710
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
base: v3-alpha
Are you sure you want to change the base?
[V3] Add origin to raw message handler #4710
Conversation
- Implemented origin and top origin tracking for web messages from JavaScript. - Updated `RawMessageHandler` to include `originInfo`. - Added cross-platform support for retrieving the origin of messages in macOS, Windows, and Linux.
WalkthroughThe PR adds an OriginInfo struct and propagates origin/top-origin/isMainFrame metadata from platform WebView layers into window messages, updating the RawMessageHandler callback signature to accept a third parameter Changes
Sequence Diagram(s)sequenceDiagram
participant WebView as WebView (platform)
participant Native as Native Bridge
participant Go as Go Runtime
participant Handler as RawMessageHandler
WebView->>Native: emit script message (body + frame info)
activate Native
Note right of Native: extract origin/top-origin,\nisMainFrame (platform-specific)
Native->>Go: processMessage(windowID, msg, origin, isMainFrame)
deactivate Native
activate Go
Note right of Go: construct windowMessage with originInfo
Go->>Handler: RawMessageHandler(window, msg, originInfo)
deactivate Go
activate Handler
Handler->>Handler: consume/log/process message + originInfo
deactivate Handler
Estimated code review effort🎯 3 (Moderate) | ⏱️ ~20 minutes
Possibly related PRs
Suggested labels
Suggested reviewers
Poem
Pre-merge checks and finishing touches❌ Failed checks (1 warning)
✅ Passed checks (2 passed)
✨ Finishing touches
🧪 Generate unit tests (beta)
Thanks for using CodeRabbit! It's free for OSS, and your support helps us grow. If you like it, consider giving us a shout-out. Comment |
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.
Actionable comments posted: 4
🧹 Nitpick comments (3)
v3/pkg/application/application_options.go (1)
89-92: Clarify originInfo semantics in docs and note the breaking change.Document that originInfo may be nil and that fields are platform-dependent (Linux: Origin only; macOS: Origin+IsMainFrame; Windows: Origin+TopOrigin). Also update changelog and user docs accordingly.
Apply this doc tweak near RawMessageHandler:
// RawMessageHandler is called when the frontend sends a raw message. // This is useful for implementing custom frontend-to-backend communication. - RawMessageHandler func(window Window, message string, originInfo *OriginInfo) + // originInfo: + // - May be nil if unavailable. + // - Linux: Origin only; macOS: Origin + IsMainFrame; Windows: Origin + TopOrigin. + RawMessageHandler func(window Window, message string, originInfo *OriginInfo)Would you like me to open a follow-up PR to update the v3 docs and changelog?
v3/pkg/application/linux_cgo.go (1)
1661-1671: Origin extraction returns full URL; consider canonical origin (scheme+host[:port]).Optional: normalize to the origin (no path/query/fragment) for parity with browser origin checks. Current behavior is consistent across platforms, so this is a nicety, not a blocker.
Example (C side):
// After obtaining currentUri: GUri *guri = g_uri_parse(currentUri, G_URI_FLAGS_NONE, NULL); if (guri) { gchar *originStr = g_uri_to_string_partial(guri, G_URI_HIDE_USERINFO|G_URI_HIDE_QUERY|G_URI_HIDE_FRAGMENT|G_URI_HIDE_PATH); origin = g_strdup(originStr); g_free(originStr); g_uri_unref(guri); }Also applies to: 1680-1683
v3/pkg/application/application.go (1)
214-223: Add a short doc comment to OriginInfo for API consumers.Helps clarify OS-specific population and intent.
Apply:
-type OriginInfo struct { +// OriginInfo carries message provenance. Fields are platform-dependent: +// - Linux: Origin only +// - macOS: Origin + IsMainFrame +// - Windows: Origin + TopOrigin +// Any field may be an empty string/false when unavailable. +type OriginInfo struct { Origin string TopOrigin string IsMainFrame bool }
📜 Review details
Configuration used: Path: .coderabbit.yaml
Review profile: CHILL
Plan: Pro
📒 Files selected for processing (7)
v3/examples/raw-message/main.go(2 hunks)v3/pkg/application/application.go(2 hunks)v3/pkg/application/application_darwin.go(1 hunks)v3/pkg/application/application_options.go(1 hunks)v3/pkg/application/linux_cgo.go(4 hunks)v3/pkg/application/webview_window_darwin.m(11 hunks)v3/pkg/application/webview_window_windows.go(1 hunks)
🧰 Additional context used
🧠 Learnings (7)
📓 Common learnings
Learnt from: APshenkin
Repo: wailsapp/wails PR: 4480
File: v2/internal/frontend/desktop/darwin/message.h:17-19
Timestamp: 2025-08-08T09:13:16.916Z
Learning: In Wails v2 bindings origin verification, processBindingMessage intentionally has different signatures across platforms: Darwin includes an isMainFrame bool (WKWebKit provides it), Linux uses two params (message, source) as WebKitGTK doesn’t expose main-frame info there, and Windows handles origin checks in Go via WebView2 sender/args without a C bridge. This divergence is acceptable/expected per maintainer (APshenkin).
📚 Learning: 2025-08-08T09:13:16.916Z
Learnt from: APshenkin
Repo: wailsapp/wails PR: 4480
File: v2/internal/frontend/desktop/darwin/message.h:17-19
Timestamp: 2025-08-08T09:13:16.916Z
Learning: In Wails v2 bindings origin verification, processBindingMessage intentionally has different signatures across platforms: Darwin includes an isMainFrame bool (WKWebKit provides it), Linux uses two params (message, source) as WebKitGTK doesn’t expose main-frame info there, and Windows handles origin checks in Go via WebView2 sender/args without a C bridge. This divergence is acceptable/expected per maintainer (APshenkin).
Applied to files:
v3/pkg/application/application_darwin.gov3/pkg/application/application_options.gov3/pkg/application/webview_window_darwin.mv3/pkg/application/webview_window_windows.gov3/pkg/application/application.gov3/pkg/application/linux_cgo.gov3/examples/raw-message/main.go
📚 Learning: 2024-09-21T13:34:24.145Z
Learnt from: nixpare
Repo: wailsapp/wails PR: 3763
File: v3/pkg/application/webview_window_bindings_darwin.h:0-0
Timestamp: 2024-09-21T13:34:24.145Z
Learning: In this codebase, typedefs for window references (like replacing `void *` with `WindowRef`) are not preferred; using `void *` is acceptable.
Applied to files:
v3/pkg/application/webview_window_darwin.m
📚 Learning: 2025-08-24T03:55:43.103Z
Learnt from: leaanthony
Repo: wailsapp/wails PR: 4534
File: v3/examples/liquid-glass/README.md:44-46
Timestamp: 2025-08-24T03:55:43.103Z
Learning: macOS 26 is the version that introduces native NSGlassEffectView support for Liquid Glass effects, representing a new internal/development versioning scheme beyond the publicly documented macOS 15 Sequoia.
Applied to files:
v3/pkg/application/webview_window_darwin.m
📚 Learning: 2024-09-21T09:56:48.126Z
Learnt from: nixpare
Repo: wailsapp/wails PR: 3763
File: v3/pkg/application/webview_panel_darwin.go:88-89
Timestamp: 2024-09-21T09:56:48.126Z
Learning: Safety checks for `p.nsPanel` are performed in the `SetFloating` method of `WebviewPanel`, following the `WebviewWindow` and `macosWebviewWindow` implementations and code style.
Applied to files:
v3/pkg/application/webview_window_darwin.m
📚 Learning: 2025-10-17T23:16:11.570Z
Learnt from: Sammy-T
Repo: wailsapp/wails PR: 4570
File: v2/internal/frontend/desktop/linux/window_webkit6.go:97-108
Timestamp: 2025-10-17T23:16:11.570Z
Learning: For webkit_6/GTK4 builds in v2/internal/frontend/desktop/linux/window_webkit6.go, GTK widget creation should not be wrapped in invokeOnMainThread. The activation mechanism (activateWg + onActivate export) already handles thread safety, and additional wrapping would cause issues.
Applied to files:
v3/pkg/application/webview_window_windows.gov3/pkg/application/linux_cgo.go
📚 Learning: 2024-09-20T23:34:29.841Z
Learnt from: nixpare
Repo: wailsapp/wails PR: 3763
File: v3/examples/keybindings/main.go:16-17
Timestamp: 2024-09-20T23:34:29.841Z
Learning: In the codebase, `application.Options.KeyBindings` uses the `application.Window` type, whereas `application.WebviewWindowOptions.KeyBindings` uses `*application.WebviewWindow`. This is intentional and acceptable.
Applied to files:
v3/pkg/application/linux_cgo.go
🧬 Code graph analysis (5)
v3/pkg/application/application_darwin.go (1)
v3/pkg/application/application.go (1)
OriginInfo(219-223)
v3/pkg/application/application_options.go (2)
v3/pkg/application/window.go (1)
Window(16-112)v3/pkg/application/application.go (1)
OriginInfo(219-223)
v3/pkg/application/webview_window_windows.go (1)
v3/pkg/application/application.go (1)
OriginInfo(219-223)
v3/pkg/application/linux_cgo.go (1)
v3/pkg/application/application.go (1)
OriginInfo(219-223)
v3/examples/raw-message/main.go (1)
v3/pkg/application/application.go (1)
OriginInfo(219-223)
⏰ Context from checks skipped due to timeout of 90000ms. You can increase the timeout in your CodeRabbit configuration to a maximum of 15 minutes (900000ms). (4)
- GitHub Check: Run Go Tests v3 (windows-latest, 1.24)
- GitHub Check: Run Go Tests v3 (ubuntu-latest, 1.24)
- GitHub Check: Run Go Tests v3 (macos-latest, 1.24)
- GitHub Check: semgrep-cloud-platform/scan
🔇 Additional comments (3)
v3/pkg/application/linux_cgo.go (1)
65-74: Storing WebView pointer on content manager: confirm lifetime relationship.Looks fine, but this assumes the content manager outlives (or shares lifetime with) the WebView. If destruction ordering can differ, consider a weak reference (GWeakRef) or clearing the data on teardown.
If helpful, I can add a teardown hook to clear "webview" when the WebView is finalized.
Also applies to: 1122-1123
v3/pkg/application/application.go (1)
718-719: LGTM: RawMessageHandler now receives originInfo.Callback propagation looks correct.
v3/pkg/application/webview_window_darwin.m (1)
7-7: Extern signature is correct and matches the Go export.The C extern declaration at line 7 matches the cgo-exported Go function exactly: both have 4 parameters with corresponding types (unsigned int ↔ C.uint, const char* ↔ *C.char, bool ↔ bool), and no conflicting declarations exist in v3 headers.
Note: The original review also flagged a potential NULL string concern (origin could be nil when passed to UTF8String, which may cause C.GoString to panic on the Go side). While the signature itself is correct, that safety issue should still be addressed—consider guarding with a default empty string if origin is nil.
- Ensure proper fallback to empty strings for `origin` and `topOrigin` when errors or nil values are encountered. - Normalize handling of `message.body` to account for non-NSString values in macOS.
|
@coderabbitai generate docstrings |
✅ Actions performedInitiated docstring generation; will generate only if new commits exist. |
|
Note Docstrings generation - SUCCESS |
Docstrings generation was requested by @leaanthony. * #4710 (comment) The following files were modified: * `v3/examples/raw-message/main.go` * `v3/pkg/application/application_darwin.go` * `v3/pkg/application/linux_cgo.go`
|
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.
Actionable comments posted: 0
🧹 Nitpick comments (1)
v3/pkg/application/webview_window_windows.go (1)
1805-1815: Consider using warning() log level for graceful degradation.Since the code now degrades gracefully by continuing with empty strings when origin retrieval fails,
warning()would be more appropriate thanerror()for these log messages.Apply this diff:
topSource, err := sender.GetSource() if err != nil { - globalApplication.error(fmt.Sprintf("Unable to get source from sender: %s", err.Error())) + globalApplication.warning("Unable to get source from sender: %v", err) topSource = "" } senderSource, err := args.GetSource() if err != nil { - globalApplication.error(fmt.Sprintf("Unable to get source from args: %s", err.Error())) + globalApplication.warning("Unable to get source from args: %v", err) senderSource = "" }
📜 Review details
Configuration used: Path: .coderabbit.yaml
Review profile: CHILL
Plan: Pro
📒 Files selected for processing (4)
v3/examples/raw-message/main.go(2 hunks)v3/pkg/application/application_darwin.go(1 hunks)v3/pkg/application/webview_window_darwin.m(11 hunks)v3/pkg/application/webview_window_windows.go(1 hunks)
🚧 Files skipped from review as they are similar to previous changes (1)
- v3/pkg/application/webview_window_darwin.m
🧰 Additional context used
🧠 Learnings (4)
📓 Common learnings
Learnt from: APshenkin
Repo: wailsapp/wails PR: 4480
File: v2/internal/frontend/desktop/darwin/message.h:17-19
Timestamp: 2025-08-08T09:13:16.916Z
Learning: In Wails v2 bindings origin verification, processBindingMessage intentionally has different signatures across platforms: Darwin includes an isMainFrame bool (WKWebKit provides it), Linux uses two params (message, source) as WebKitGTK doesn’t expose main-frame info there, and Windows handles origin checks in Go via WebView2 sender/args without a C bridge. This divergence is acceptable/expected per maintainer (APshenkin).
📚 Learning: 2025-08-08T09:13:16.916Z
Learnt from: APshenkin
Repo: wailsapp/wails PR: 4480
File: v2/internal/frontend/desktop/darwin/message.h:17-19
Timestamp: 2025-08-08T09:13:16.916Z
Learning: In Wails v2 bindings origin verification, processBindingMessage intentionally has different signatures across platforms: Darwin includes an isMainFrame bool (WKWebKit provides it), Linux uses two params (message, source) as WebKitGTK doesn’t expose main-frame info there, and Windows handles origin checks in Go via WebView2 sender/args without a C bridge. This divergence is acceptable/expected per maintainer (APshenkin).
Applied to files:
v3/examples/raw-message/main.gov3/pkg/application/webview_window_windows.gov3/pkg/application/application_darwin.go
📚 Learning: 2025-02-24T06:08:55.645Z
Learnt from: popaprozac
Repo: wailsapp/wails PR: 4098
File: v3/pkg/services/notifications/notifications_windows.go:91-113
Timestamp: 2025-02-24T06:08:55.645Z
Learning: The JSON quote handling in Windows notifications' activation arguments (v3/pkg/services/notifications/notifications_windows.go) has a known limitation with single-quote collisions that needs to be addressed after initial testing.
Applied to files:
v3/pkg/application/webview_window_windows.go
📚 Learning: 2025-10-17T23:16:11.570Z
Learnt from: Sammy-T
Repo: wailsapp/wails PR: 4570
File: v2/internal/frontend/desktop/linux/window_webkit6.go:97-108
Timestamp: 2025-10-17T23:16:11.570Z
Learning: For webkit_6/GTK4 builds in v2/internal/frontend/desktop/linux/window_webkit6.go, GTK widget creation should not be wrapped in invokeOnMainThread. The activation mechanism (activateWg + onActivate export) already handles thread safety, and additional wrapping would cause issues.
Applied to files:
v3/pkg/application/webview_window_windows.go
🧬 Code graph analysis (3)
v3/examples/raw-message/main.go (1)
v3/pkg/application/application.go (1)
OriginInfo(219-223)
v3/pkg/application/webview_window_windows.go (1)
v3/pkg/application/application.go (1)
OriginInfo(219-223)
v3/pkg/application/application_darwin.go (1)
v3/pkg/application/application.go (1)
OriginInfo(219-223)
⏰ Context from checks skipped due to timeout of 90000ms. You can increase the timeout in your CodeRabbit configuration to a maximum of 15 minutes (900000ms). (3)
- GitHub Check: Run Go Tests v3 (macos-latest, 1.24)
- GitHub Check: Run Go Tests v3 (ubuntu-latest, 1.24)
- GitHub Check: Run Go Tests v3 (windows-latest, 1.24)
🔇 Additional comments (2)
v3/pkg/application/webview_window_windows.go (1)
1821-1824: LGTM! Origin information properly populated.The OriginInfo struct is correctly populated with the retrieved origin values. IsMainFrame defaults to false, which is acceptable for Windows since the platform doesn't easily expose main-frame information through WebView2 compared to Darwin's WKWebKit.
Based on learnings
v3/pkg/application/application_darwin.go (1)
347-359: LGTM! Nil origin properly guarded.The nil check before
C.GoString(origin)correctly prevents crashes when origin is NULL from Objective-C. The OriginInfo is properly populated with Origin and IsMainFrame fields, which are the platform-specific data available from WKWebKit on macOS.Based on learnings



Description
This PR ports #4480 to V3. RawMessageHandler will provide available origin info to handler, so that application can decide what to do with a message.
On Mac: Origin and IsMainFrame provided
On Windows: Origin and TopOrigin provided
On Linux: Origin only provided
Fixes # (issue) related to #4686
Type of change
Please select the option that is relevant.
How Has This Been Tested?
Please describe the tests that you ran to verify your changes. Provide instructions so we can reproduce. Please also list any relevant details for your test configuration using
wails doctor.If you checked Linux, please specify the distro and version.
Test Configuration
Checklist:
website/src/pages/changelog.mdxwith details of this PRSummary by CodeRabbit
✏️ Tip: You can customize this high-level summary in your review settings.