Skip to content

Commit b94ee79

Browse files
fix(macOS): add JavaScript error capture (window.onerror + unhandledrejection)
CRITICAL DISCOVERY: - index.html already has JSBI polyfills correctly applied (488 JSBI.BigInt calls) ✅ - JavaScript basic execution works (console.log confirmed in Player.log) ✅ - BUT game-bridge never initializes ('index.ts loaded' never appears) ❌ HYPOTHESIS: game-bridge code fails silently during execution. No errors visible because: 1. Errors aren't being logged to Unity console 2. Promise rejections may be swallowed FIX: Add comprehensive error handlers in ImmutableWebView.mm: 1. window.onerror - catches synchronous JavaScript errors 2. unhandledrejection event - catches unhandled promise rejections 3. Both forward errors to Unity console via messageHandlers.logHandler NEXT STEP: With error capture, we'll see EXACTLY where game-bridge fails in next test run.
1 parent 24878c1 commit b94ee79

2 files changed

Lines changed: 12 additions & 0 deletions

File tree

Plugins/Mac/Sources/ImmutableWebView.mm

Lines changed: 12 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -126,6 +126,18 @@ - (id)initWithUa:(const char *)ua
126126
originalLog.apply(console, arguments); \
127127
}; \
128128
})(); \
129+
window.onerror = function(msg, url, line, col, error) { \
130+
var errorMsg = 'JS ERROR: ' + msg + ' at ' + url + ':' + line + ':' + col; \
131+
if (error && error.stack) errorMsg += '\\nStack: ' + error.stack; \
132+
try { window.webkit.messageHandlers.logHandler.postMessage(errorMsg); } catch(e) {} \
133+
console.error(errorMsg); \
134+
return false; \
135+
}; \
136+
window.addEventListener('unhandledrejection', function(e) { \
137+
var errorMsg = 'UNHANDLED PROMISE REJECTION: ' + (e.reason ? e.reason.toString() : 'unknown'); \
138+
try { window.webkit.messageHandlers.logHandler.postMessage(errorMsg); } catch(ex) {} \
139+
console.error(errorMsg); \
140+
}); \
129141
";
130142

131143
WKUserScript *script

0 commit comments

Comments
 (0)