mirror of
https://github.com/VSadov/Satori.git
synced 2025-06-10 01:50:53 +09:00
[wasm] Re-try when browser's WBT fail with System.TimeoutException
(#104481)
This commit is contained in:
parent
819826683d
commit
26b6161c6b
1 changed files with 30 additions and 11 deletions
|
@ -102,24 +102,43 @@ internal class BrowserRunner : IAsyncDisposable
|
||||||
|
|
||||||
public async Task<IBrowser> SpawnBrowserAsync(
|
public async Task<IBrowser> SpawnBrowserAsync(
|
||||||
string browserUrl,
|
string browserUrl,
|
||||||
bool headless = true
|
bool headless = true,
|
||||||
|
int timeout = 10000,
|
||||||
|
int maxRetries = 3
|
||||||
) {
|
) {
|
||||||
var url = new Uri(browserUrl);
|
var url = new Uri(browserUrl);
|
||||||
Playwright = await Microsoft.Playwright.Playwright.CreateAsync();
|
Playwright = await Microsoft.Playwright.Playwright.CreateAsync();
|
||||||
// codespaces: ignore certificate error -> Microsoft.Playwright.PlaywrightException : net::ERR_CERT_AUTHORITY_INVALID
|
// codespaces: ignore certificate error -> Microsoft.Playwright.PlaywrightException : net::ERR_CERT_AUTHORITY_INVALID
|
||||||
string[] chromeArgs = new[] { $"--explicitly-allowed-ports={url.Port}", "--ignore-certificate-errors" };
|
string[] chromeArgs = new[] { $"--explicitly-allowed-ports={url.Port}", "--ignore-certificate-errors" };
|
||||||
_testOutput.WriteLine($"Launching chrome ('{s_chromePath.Value}') via playwright with args = {string.Join(',', chromeArgs)}");
|
_testOutput.WriteLine($"Launching chrome ('{s_chromePath.Value}') via playwright with args = {string.Join(',', chromeArgs)}");
|
||||||
|
|
||||||
|
int attempt = 0;
|
||||||
|
while (attempt < maxRetries)
|
||||||
|
{
|
||||||
|
try
|
||||||
|
{
|
||||||
Browser = await Playwright.Chromium.LaunchAsync(new BrowserTypeLaunchOptions {
|
Browser = await Playwright.Chromium.LaunchAsync(new BrowserTypeLaunchOptions {
|
||||||
ExecutablePath = s_chromePath.Value,
|
ExecutablePath = s_chromePath.Value,
|
||||||
Headless = headless,
|
Headless = headless,
|
||||||
Args = chromeArgs
|
Args = chromeArgs,
|
||||||
|
Timeout = timeout
|
||||||
});
|
});
|
||||||
Browser.Disconnected += (sender, e) =>
|
Browser.Disconnected += (sender, e) =>
|
||||||
{
|
{
|
||||||
Browser = null;
|
Browser = null;
|
||||||
_testOutput.WriteLine("Browser has been disconnected");
|
_testOutput.WriteLine("Browser has been disconnected");
|
||||||
};
|
};
|
||||||
return Browser;
|
break;
|
||||||
|
}
|
||||||
|
catch (System.TimeoutException ex)
|
||||||
|
{
|
||||||
|
attempt++;
|
||||||
|
_testOutput.WriteLine($"Attempt {attempt} failed with TimeoutException: {ex.Message}");
|
||||||
|
}
|
||||||
|
}
|
||||||
|
if (attempt == maxRetries)
|
||||||
|
throw new Exception($"Failed to launch browser after {maxRetries} attempts");
|
||||||
|
return Browser!;
|
||||||
}
|
}
|
||||||
|
|
||||||
// FIXME: options
|
// FIXME: options
|
||||||
|
|
Loading…
Add table
Add a link
Reference in a new issue