Skip to content

Commit f97bfb9

Browse files
committed
Standalone browser timeout and catch
1 parent 2c76b64 commit f97bfb9

File tree

2 files changed

+19
-4
lines changed

2 files changed

+19
-4
lines changed

Assets/Thirdweb/Core/Scripts/WalletsUI/EmbeddedWalletUI.cs

Lines changed: 10 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -171,9 +171,16 @@ public void OpenURL(string url)
171171
#else
172172
public async void OpenURL(string url)
173173
{
174-
var standaloneBrowser = new StandaloneBrowser();
175-
var res = await standaloneBrowser.StartAsync(url, "http://localhost:8789/");
176-
_redirectUrl = res.redirectUrl;
174+
try
175+
{
176+
var standaloneBrowser = new StandaloneBrowser();
177+
var res = await standaloneBrowser.StartAsync(url, "http://localhost:8789/");
178+
_redirectUrl = res.redirectUrl;
179+
}
180+
catch (System.Exception e)
181+
{
182+
_exception = e;
183+
}
177184
}
178185
#endif
179186

Assets/Thirdweb/Plugins/Authentication for Unity/Runtime/Browser/StandaloneBrowser.cs

Lines changed: 9 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -75,7 +75,15 @@ public async Task<BrowserResult> StartAsync(string loginUrl, string redirectUrl,
7575

7676
Application.OpenURL(loginUrl);
7777

78-
return await _taskCompletionSource.Task;
78+
var completedTask = await Task.WhenAny(_taskCompletionSource.Task, Task.Delay(TimeSpan.FromSeconds(60)));
79+
if (completedTask == _taskCompletionSource.Task)
80+
{
81+
return await _taskCompletionSource.Task;
82+
}
83+
else
84+
{
85+
throw new TimeoutException("The operation timed out.");
86+
}
7987
}
8088
finally
8189
{

0 commit comments

Comments
 (0)