Skip to content

Commit 83bd2fa

Browse files
chore: add extensive logging and timeout to UWB initialization
Add detailed debug logs throughout UwbWebView and GameBridgeServer initialization: - Log each initialization step to pinpoint where process hangs - Add 30-second timeout to WaitForClientConnected with clear error message - Add try-catch to capture any silent exceptions - Log HTTP requests received by GameBridgeServer - Log CEF engine configuration loading - Log communication layer port configuration This will help diagnose why the app gets stuck in "Initialisation" scene.
1 parent f56cf5a commit 83bd2fa

2 files changed

Lines changed: 126 additions & 61 deletions

File tree

src/Packages/Passport/Runtime/Scripts/Private/Uwb/UwbWebView.cs

Lines changed: 104 additions & 60 deletions
Original file line numberDiff line numberDiff line change
@@ -36,80 +36,124 @@ public class UwbWebView : MonoBehaviour, IWebBrowserClient
3636

3737
public async UniTask Init(int engineStartupTimeoutMs, bool redactTokensInLogs, Func<string, string> redactionHandler)
3838
{
39-
GameObject persistentObject = new GameObject("UWB_Bridge");
40-
41-
var rawImage = persistentObject.AddComponent<RawImage>();
42-
rawImage.color = Color.clear;
43-
44-
var ui = persistentObject.AddComponent<WebBrowserUIFull>();
45-
46-
// Assign a basic input handler so UWB doesn't throw
47-
var inputHandler = ScriptableObject.CreateInstance<WebBrowserOldInputHandler>();
48-
ui.inputHandler = inputHandler;
49-
50-
DontDestroyOnLoad(persistentObject);
51-
52-
WebBrowserClient browserClient = ui.browserClient;
53-
browserClient.engineStartupTimeout = engineStartupTimeoutMs;
54-
55-
// Disable sandbox for Windows VM compatibility
56-
browserClient.noSandbox = true;
57-
58-
// Apply Passport logging preferences to the UWB client
59-
UwbLogConfig.ApplyTo(browserClient);
60-
61-
// Js
62-
browserClient.jsMethodManager = new JsMethodManager { jsMethodsEnable = true };
63-
browserClient.RegisterJsMethod<string>("callback",
64-
(message) => { OnUnityPostMessage?.Invoke(message); });
65-
66-
// Cache
67-
var browserEngineMainDir = WebBrowserUtils.GetAdditionFilesDirectory();
68-
browserClient.CachePath = new FileInfo(Path.Combine(browserEngineMainDir, "ImmutableSDK/UWBCache"));
69-
70-
// Start local HTTP server to serve index.html
71-
gameBridgeServer = new GameBridgeServer(GameBridge.GetFileSystemPath());
72-
browserClient.initialUrl = gameBridgeServer.Start();
73-
74-
// Set up engine from standard UWB configuration asset
75-
var engineConfigAsset = Resources.Load<EngineConfiguration>("Cef Engine Configuration");
76-
if (engineConfigAsset == null)
39+
try
7740
{
78-
Debug.LogError("[UwbWebView] Could not find 'Cef Engine Configuration' Resources asset. " +
79-
"Ensure the UnityWebBrowser engine package is installed.");
41+
Debug.Log("[UwbWebView] Init started...");
42+
43+
GameObject persistentObject = new GameObject("UWB_Bridge");
44+
Debug.Log("[UwbWebView] GameObject created");
45+
46+
var rawImage = persistentObject.AddComponent<RawImage>();
47+
rawImage.color = Color.clear;
48+
49+
var ui = persistentObject.AddComponent<WebBrowserUIFull>();
50+
Debug.Log("[UwbWebView] WebBrowserUIFull component added");
51+
52+
// Assign a basic input handler so UWB doesn't throw
53+
var inputHandler = ScriptableObject.CreateInstance<WebBrowserOldInputHandler>();
54+
ui.inputHandler = inputHandler;
55+
56+
DontDestroyOnLoad(persistentObject);
57+
58+
WebBrowserClient browserClient = ui.browserClient;
59+
browserClient.engineStartupTimeout = engineStartupTimeoutMs;
60+
Debug.Log($"[UwbWebView] Engine startup timeout set to {engineStartupTimeoutMs}ms");
61+
62+
// Disable sandbox for Windows VM compatibility
63+
browserClient.noSandbox = true;
64+
65+
// Apply Passport logging preferences to the UWB client
66+
UwbLogConfig.ApplyTo(browserClient);
67+
68+
// Js
69+
browserClient.jsMethodManager = new JsMethodManager { jsMethodsEnable = true };
70+
browserClient.RegisterJsMethod<string>("callback",
71+
(message) => { OnUnityPostMessage?.Invoke(message); });
72+
Debug.Log("[UwbWebView] JavaScript callback method registered");
73+
74+
// Cache
75+
var browserEngineMainDir = WebBrowserUtils.GetAdditionFilesDirectory();
76+
browserClient.CachePath = new FileInfo(Path.Combine(browserEngineMainDir, "ImmutableSDK/UWBCache"));
77+
Debug.Log($"[UwbWebView] Cache path set to: {browserClient.CachePath.FullName}");
78+
79+
// Start local HTTP server to serve index.html
80+
Debug.Log("[UwbWebView] Starting GameBridgeServer...");
81+
gameBridgeServer = new GameBridgeServer(GameBridge.GetFileSystemPath());
82+
string serverUrl = gameBridgeServer.Start();
83+
browserClient.initialUrl = serverUrl;
84+
Debug.Log($"[UwbWebView] GameBridgeServer started at: {serverUrl}");
85+
86+
// Set up engine from standard UWB configuration asset
87+
var engineConfigAsset = Resources.Load<EngineConfiguration>("Cef Engine Configuration");
88+
if (engineConfigAsset == null)
89+
{
90+
Debug.LogError("[UwbWebView] Could not find 'Cef Engine Configuration' Resources asset. " +
91+
"Ensure the UnityWebBrowser engine package is installed.");
92+
}
93+
else
94+
{
95+
var engineConfig = ScriptableObject.Instantiate(engineConfigAsset);
96+
browserClient.engine = engineConfig;
97+
Debug.Log("[UwbWebView] CEF Engine configuration loaded");
98+
}
99+
100+
// Find available ports
101+
TCPCommunicationLayer tcpCommunicationLayer = ScriptableObject.CreateInstance<TCPCommunicationLayer>();
102+
var rnd = new System.Random();
103+
do
104+
{
105+
tcpCommunicationLayer.inPort = rnd.Next(1024, 65353);
106+
tcpCommunicationLayer.outPort = tcpCommunicationLayer.inPort + 1;
107+
} while (!CheckAvailableServerPort(tcpCommunicationLayer.inPort) || !CheckAvailableServerPort(tcpCommunicationLayer.outPort));
108+
109+
browserClient.communicationLayer = tcpCommunicationLayer;
110+
Debug.Log($"[UwbWebView] Communication layer configured - inPort: {tcpCommunicationLayer.inPort}, outPort: {tcpCommunicationLayer.outPort}");
111+
112+
Debug.Log("[UwbWebView] Waiting for browser client to connect...");
113+
await WaitForClientConnected(browserClient);
114+
Debug.Log("[UwbWebView] Browser client connected successfully!");
115+
116+
this.webBrowserClient = browserClient;
117+
Debug.Log("[UwbWebView] Init completed successfully");
80118
}
81-
else
119+
catch (Exception ex)
82120
{
83-
var engineConfig = ScriptableObject.Instantiate(engineConfigAsset);
84-
browserClient.engine = engineConfig;
121+
Debug.LogError($"[UwbWebView] Init failed with exception: {ex.GetType().Name}: {ex.Message}");
122+
Debug.LogError($"[UwbWebView] Stack trace: {ex.StackTrace}");
123+
throw;
85124
}
86-
87-
// Find available ports
88-
TCPCommunicationLayer tcpCommunicationLayer = ScriptableObject.CreateInstance<TCPCommunicationLayer>();
89-
var rnd = new System.Random();
90-
do
91-
{
92-
tcpCommunicationLayer.inPort = rnd.Next(1024, 65353);
93-
tcpCommunicationLayer.outPort = tcpCommunicationLayer.inPort + 1;
94-
} while (!CheckAvailableServerPort(tcpCommunicationLayer.inPort) || !CheckAvailableServerPort(tcpCommunicationLayer.outPort));
95-
96-
browserClient.communicationLayer = tcpCommunicationLayer;
97-
98-
await WaitForClientConnected(browserClient);
99-
100-
this.webBrowserClient = browserClient;
101125
}
102126

103-
private UniTask WaitForClientConnected(WebBrowserClient webBrowserClient)
127+
private async UniTask WaitForClientConnected(WebBrowserClient webBrowserClient)
104128
{
105129
var tcs = new TaskCompletionSource<bool>();
130+
var timeoutSeconds = 30;
106131

107132
webBrowserClient.OnLoadFinish += OnLoadFinish;
108133

109-
return tcs.Task.AsUniTask();
134+
// Create timeout task
135+
var timeoutTask = UniTask.Delay(TimeSpan.FromSeconds(timeoutSeconds));
136+
var completionTask = tcs.Task.AsUniTask();
137+
138+
Debug.Log($"[UwbWebView] Waiting up to {timeoutSeconds} seconds for OnLoadFinish event...");
139+
140+
// Race between completion and timeout
141+
var completedTask = await UniTask.WhenAny(completionTask, timeoutTask);
142+
143+
if (completedTask == 1) // Timeout won
144+
{
145+
webBrowserClient.OnLoadFinish -= OnLoadFinish;
146+
var errorMsg = $"[UwbWebView] Timeout after {timeoutSeconds} seconds waiting for browser OnLoadFinish event. " +
147+
$"The browser failed to load the initial URL. This may indicate a CEF initialization failure.";
148+
Debug.LogError(errorMsg);
149+
throw new TimeoutException(errorMsg);
150+
}
151+
152+
Debug.Log($"[UwbWebView] OnLoadFinish event received successfully");
110153

111154
void OnLoadFinish(string url)
112155
{
156+
Debug.Log($"[UwbWebView] OnLoadFinish fired for URL: {url}");
113157
webBrowserClient.OnLoadFinish -= OnLoadFinish;
114158
tcs.SetResult(true);
115159
}

src/Packages/Passport/Runtime/ThirdParty/ImmutableBrowserCore/GameBridgeServer.cs

Lines changed: 22 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -52,13 +52,28 @@ public string Start()
5252
throw new ObjectDisposedException(nameof(GameBridgeServer));
5353

5454
if (_listener?.IsListening == true)
55+
{
56+
Debug.Log($"{TAG} Already running on {URL}");
5557
return URL;
58+
}
5659

60+
Debug.Log($"{TAG} Checking if port {PORT} is available...");
5761
EnsurePortAvailable();
62+
Debug.Log($"{TAG} Port {PORT} is available");
5863

5964
_listener = new HttpListener();
6065
_listener.Prefixes.Add(URL);
61-
_listener.Start();
66+
67+
try
68+
{
69+
_listener.Start();
70+
Debug.Log($"{TAG} HttpListener started successfully");
71+
}
72+
catch (Exception ex)
73+
{
74+
Debug.LogError($"{TAG} Failed to start HttpListener: {ex.GetType().Name}: {ex.Message}");
75+
throw;
76+
}
6277

6378
Debug.Log($"{TAG} Started on {URL}");
6479

@@ -68,6 +83,7 @@ public string Start()
6883
IsBackground = true
6984
};
7085
_listenerThread.Start();
86+
Debug.Log($"{TAG} Listener thread started");
7187

7288
return URL;
7389
}
@@ -99,13 +115,18 @@ private void ListenerLoop()
99115

100116
private void HandleRequest(HttpListenerContext context)
101117
{
118+
var request = context.Request;
102119
var response = context.Response;
120+
121+
Debug.Log($"{TAG} Received request: {request.HttpMethod} {request.Url} from {request.UserAgent}");
122+
103123
try
104124
{
105125
response.StatusCode = 200;
106126
response.ContentType = "text/html; charset=utf-8";
107127
response.ContentLength64 = _indexHtmlContent!.Length;
108128
response.OutputStream.Write(_indexHtmlContent, 0, _indexHtmlContent.Length);
129+
Debug.Log($"{TAG} Sent {_indexHtmlContent.Length} bytes response");
109130
}
110131
catch (Exception ex)
111132
{

0 commit comments

Comments
 (0)