Skip to content
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
1 change: 1 addition & 0 deletions v3/UNRELEASED_CHANGELOG.md
Original file line number Diff line number Diff line change
Expand Up @@ -24,6 +24,7 @@ After processing, the content will be moved to the main changelog and this file
## Fixed
<!-- Bug fixes -->
- Fix outdated Manager API references in documentation (31 files updated to use new pattern like `app.Window.New()`, `app.Event.Emit()`, etc.) by @leaanthony
- Fix Linux crash on panic in JS-bound Go methods due to WebKit overriding signal handlers (#3965) by @leaanthony

## Deprecated
<!-- Soon-to-be removed features -->
Expand Down
16 changes: 14 additions & 2 deletions v3/pkg/application/linux_cgo.go
Original file line number Diff line number Diff line change
Expand Up @@ -161,7 +161,16 @@ typedef struct Screen {
bool isPrimary;
} Screen;

// Signal handler fix for WebKit/GTK compatibility.
// CREDIT: https://github.com/rainycape/magick
//
// WebKit/GTK may install signal handlers without SA_ONSTACK, which causes
// Go to crash when handling signals (e.g., during panic recovery).
// This code adds SA_ONSTACK to signal handlers after WebKit initialization.
//
// Known limitation: Due to Go issue #7227 (golang/go#7227), signals may still
// be delivered on the wrong stack in some cases when C libraries are involved.
// This is a fundamental Go runtime limitation that cannot be fully resolved here.
#include <errno.h>
#include <signal.h>
#include <stdio.h>
Expand Down Expand Up @@ -489,6 +498,7 @@ var (
)

var registerURIScheme sync.Once
var fixSignalHandlers sync.Once

func init() {
gtkSignalToMenuItem = map[uint]*MenuItem{}
Expand Down Expand Up @@ -553,8 +563,6 @@ func appName() string {
}

func appNew(name string) pointer {
C.install_signal_handlers()

// Name is already sanitized by sanitizeAppName() in application_linux.go
appId := fmt.Sprintf("org.wails.%s", name)
nameC := C.CString(appId)
Expand Down Expand Up @@ -1344,6 +1352,10 @@ func windowNewWebview(parentId uint, gpuPolicy WebviewGpuPolicy) pointer {
C.webkit_user_content_manager_register_script_message_handler(manager, c.String("external"))
webView := C.webkit_web_view_new_with_user_content_manager(manager)

fixSignalHandlers.Do(func() {
C.install_signal_handlers()
})

C.save_webview_to_content_manager(unsafe.Pointer(manager), unsafe.Pointer(webView))

// attach window id to both the webview and contentmanager
Expand Down
Loading