diff --git a/Dockerfile b/Dockerfile index e276ad7..973bc4f 100644 --- a/Dockerfile +++ b/Dockerfile @@ -32,7 +32,7 @@ RUN apt-get update \ npm \ && rm -rf /var/lib/apt/lists/* -RUN npx playwright install --with-deps chromium +RUN npx playwright install-deps RUN apt-get remove --purge -y npm \ && apt-get autoremove -y @@ -54,10 +54,12 @@ COPY docker/supervisord.conf /etc/supervisor/conf.d/supervisord.conf COPY docker/entrypoint.sh /app/entrypoint.sh RUN chmod +x /app/entrypoint.sh -ENV DISPLAY=:0.0 \ - DISPLAY_WIDTH=1024 \ +ENV DEBIAN_FRONTEND="noninteractive" \ + DISPLAY=:0.0 \ + DISPLAY_WIDTH=1366 \ DISPLAY_HEIGHT=768 \ - OFDL_DOCKER=true + OFDL_DOCKER=true \ + PLAYWRIGHT_BROWSERS_PATH=/config/chromium EXPOSE 8080 WORKDIR /config diff --git a/OF DL/Helpers/AuthHelper.cs b/OF DL/Helpers/AuthHelper.cs index b996f97..a694be1 100644 --- a/OF DL/Helpers/AuthHelper.cs +++ b/OF DL/Helpers/AuthHelper.cs @@ -26,21 +26,32 @@ public class AuthHelper private const float LoginTimeout = 600000f; // 10 minutes private const float FeedLoadTimeout = 60000f; // 1 minute - public async Task SetupBrowser(bool runningInDocker) + public Task SetupBrowser(bool runningInDocker) { if (runningInDocker) { Log.Information("Running in Docker. Disabling sandbox and GPU."); _options.Args = ["--no-sandbox", "--disable-setuid-sandbox", "--disable-gpu", "--disable-blink-features=AutomationControlled", "--disable-infobars"]; - } - else - { - var exitCode = Microsoft.Playwright.Program.Main(new[] {"install", "--with-deps", "chromium"}); - if (exitCode != 0) + + // If chromium is already downloaded, skip installation + string? playwrightBrowsersPath = Environment.GetEnvironmentVariable("PLAYWRIGHT_BROWSERS_PATH"); + IEnumerable folders = Directory.GetDirectories(playwrightBrowsersPath ?? "/config/chromium") + .Where(folder => folder.Contains("chromium-")); + + if (folders.Any()) { - throw new Exception($"Playwright chromium download failed. Exited with code {exitCode}"); + Log.Information("chromium already downloaded. Skipping install step."); + return Task.CompletedTask; } } + + var exitCode = Microsoft.Playwright.Program.Main(["install", "--with-deps", "chromium"]); + if (exitCode != 0) + { + throw new Exception($"Playwright chromium download failed. Exited with code {exitCode}"); + } + + return Task.CompletedTask; } private async Task GetBcToken(IPage page) @@ -60,9 +71,12 @@ public class AuthHelper } catch (Exception e) { - if (e.Message.Contains("An error occurred trying to start process") && Directory.Exists(_userDataDir)) + if (( + e.Message.Contains("An error occurred trying to start process") || + e.Message.Contains("The profile appears to be in use by another Chromium process") + ) && Directory.Exists(_userDataDir)) { - Log.Error("Failed to launch browser. Deleting chrome-data directory and trying again."); + Log.Error("Failed to launch browser. Deleting chromium-data directory and trying again."); Directory.Delete(_userDataDir, true); IPlaywright playwright = await Playwright.CreateAsync(); browser = await playwright.Chromium.LaunchPersistentContextAsync(_userDataDir, _options); diff --git a/OF DL/OF DL.csproj b/OF DL/OF DL.csproj index 3c7620d..6e3d347 100644 --- a/OF DL/OF DL.csproj +++ b/OF DL/OF DL.csproj @@ -18,7 +18,7 @@ - + diff --git a/OF DL/Program.cs b/OF DL/Program.cs index 70d66cd..51d8ad8 100644 --- a/OF DL/Program.cs +++ b/OF DL/Program.cs @@ -3142,10 +3142,10 @@ public class Program } break; case "[red]Logout and Exit[/]": - if (Directory.Exists("chrome-data")) + if (Directory.Exists("chromium-data")) { - Log.Information("Deleting chrome-data folder"); - Directory.Delete("chrome-data", true); + Log.Information("Deleting chromium-data folder"); + Directory.Delete("chromium-data", true); } if (File.Exists("auth.json")) { diff --git a/docker/entrypoint.sh b/docker/entrypoint.sh index f9e9e37..18dca29 100644 --- a/docker/entrypoint.sh +++ b/docker/entrypoint.sh @@ -2,6 +2,7 @@ mkdir -p /config/cdm/devices/chrome_1610 mkdir -p /config/logs/ +mkdir -p /config/chromium if [ ! -f /config/config.conf ] && [ ! -f /config/config.json ]; then cp /default-config/config.conf /config/config.conf