Skip to content

Commit 749e700

Browse files
fix(macOS): add comprehensive WebView debugging and navigation delegates
WINDOWS FIX (UwbWebView.cs): - Corrected UniTask.WhenAny return type handling - Fixed: error CS0019 'bool' vs 'int' comparison - Changed to: int winIndex = await UniTask.WhenAny(...) MACOS IMPROVEMENTS (ImmutableWebView.mm): 1. Enable developer extras and Safari debugging (always on, not just #ifdef) - Allows remote debugging of WebView content 2. Add didFinishNavigation delegate - Logs successful page loads - Tests JavaScript execution immediately after load - Helps diagnose if JS is running 3. Improve error delegates (didFailNavigation, didFailProvisionalNavigation) - Add detailed NSLog with error code - Helps diagnose navigation failures 4. Recompile ImmutableWebView.bundle with all changes GOAL: Get detailed logs to understand why JavaScript is not executing in CI/CD
1 parent 3efb516 commit 749e700

2 files changed

Lines changed: 22 additions & 5 deletions

File tree

Plugins/Mac/Sources/ImmutableWebView.mm

Lines changed: 22 additions & 5 deletions
Original file line numberDiff line numberDiff line change
@@ -137,14 +137,14 @@ - (id)initWithUa:(const char *)ua
137137
configuration.processPool = _sharedProcessPool;
138138

139139
WKWebView *wkwebView = [[WKWebView alloc] initWithFrame:frame configuration:configuration];
140-
#if UNITYWEBVIEW_DEVELOPMENT
141-
[[[webView configuration] preferences] setValue:@YES forKey:@"developerExtrasEnabled"];
142140

143-
// enable Safari debugging if exists
141+
// ALWAYS enable developer extras and inspectable for debugging JavaScript issues
142+
[[[wkwebView configuration] preferences] setValue:@YES forKey:@"developerExtrasEnabled"];
143+
144+
// Enable Safari debugging (macOS 13.3+)
144145
if ([wkwebView respondsToSelector:@selector(setInspectable:)]) {
145-
[wkwebView performSelector:@selector(setInspectable:) withObject:@true];
146+
[wkwebView performSelector:@selector(setInspectable:) withObject:@YES];
146147
}
147-
#endif
148148

149149
webView = wkwebView;
150150
webView.UIDelegate = self;
@@ -264,13 +264,30 @@ - (void)webViewWebContentProcessDidTerminate:(WKWebView *)webView
264264
[self sendUnityCallback:"CallOnError" message:"webViewWebContentProcessDidTerminate"];
265265
}
266266

267+
- (void)webView:(WKWebView *)webView didFinishNavigation:(WKNavigation *)navigation
268+
{
269+
NSLog(@"[ImmutableWebView] didFinishNavigation - URL: %@", webView.URL.absoluteString);
270+
271+
// Test JavaScript execution immediately after page load
272+
[webView evaluateJavaScript:@"console.log('ImmutableWebView: JS test after load'); 'JS_READY';"
273+
completionHandler:^(id result, NSError *error) {
274+
if (error) {
275+
NSLog(@"[ImmutableWebView] ERROR: JS test failed: %@", error.localizedDescription);
276+
} else {
277+
NSLog(@"[ImmutableWebView] JS test OK, result: %@", result);
278+
}
279+
}];
280+
}
281+
267282
- (void)webView:(WKWebView *)webView didFailProvisionalNavigation:(WKNavigation *)navigation withError:(NSError *)error
268283
{
284+
NSLog(@"[ImmutableWebView] didFailProvisionalNavigation - Error: %@ (code: %ld)", error.localizedDescription, (long)error.code);
269285
[self sendUnityCallback:"CallOnError" message:[[error description] UTF8String]];
270286
}
271287

272288
- (void)webView:(WKWebView *)webView didFailNavigation:(WKNavigation *)navigation withError:(NSError *)error
273289
{
290+
NSLog(@"[ImmutableWebView] didFailNavigation - Error: %@ (code: %ld)", error.localizedDescription, (long)error.code);
274291
[self sendUnityCallback:"CallOnError" message:[[error description] UTF8String]];
275292
}
276293

0 commit comments

Comments
 (0)