Skip to content

Commit 4f2c6e8

Browse files
fix: add WebView to view hierarchy to enable JavaScript execution
CRITICAL FIX: WKWebView on macOS requires being in the view hierarchy to properly execute JavaScript. The WebView was created but never added to any view, causing JavaScript (including the game-bridge callbacks) to never execute. Changes: - Set webView.hidden = NO (was YES) - Position WebView offscreen (-10000, -10000) with minimal size (1x1) - Add WebView to main window's content view - Add logging for debugging This ensures JavaScript runs even though the WebView UI is not visible to the user.
1 parent 2ef106b commit 4f2c6e8

2 files changed

Lines changed: 15 additions & 1 deletion

File tree

Plugins/Mac/Sources/ImmutableWebView.mm

Lines changed: 15 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -143,7 +143,21 @@ - (id)initWithUa:(const char *)ua
143143
webView = wkwebView;
144144
webView.UIDelegate = self;
145145
webView.navigationDelegate = self;
146-
webView.hidden = YES;
146+
147+
// CRITICAL: WebView must be in view hierarchy and not hidden to execute JavaScript
148+
// Even though we don't need UI, we add it offscreen to ensure JavaScript runs
149+
webView.hidden = NO;
150+
webView.frame = CGRectMake(-10000, -10000, 1, 1); // Position offscreen
151+
152+
// Add to main window to ensure JavaScript execution
153+
NSArray *windows = [[NSApplication sharedApplication] windows];
154+
if ([windows count] > 0) {
155+
NSWindow *mainWindow = [windows objectAtIndex:0];
156+
[[mainWindow contentView] addSubview:webView];
157+
NSLog(@"[ImmutableWebView] WebView added to main window for JavaScript execution");
158+
} else {
159+
NSLog(@"[ImmutableWebView] WARNING: No window available, WebView may not execute JavaScript");
160+
}
147161

148162
if (ua != NULL && strcmp(ua, "") != 0) {
149163
((WKWebView *)webView).customUserAgent = [[NSString alloc] initWithUTF8String:ua];

0 commit comments

Comments
 (0)