Cannot launch playwright chromium

  .net, docker, dockerfile, linux, playwright

I m trying to create .net 5.0 docker image with playwright, my image build properly but when i run my app using

dotnet run 'ProjectName' it fails while executing command:

 await using var browser = await playwright.Chromium.LaunchAsync(new BrowserTypeLaunchOptions 
            {
                Headless = false,
                Args = new[] { "--disable-dev-shm-usage" }
            });

Received error:

    Unhandled exception. Microsoft.Playwright.PlaywrightException: Browser closed.
==================== Browser output: ====================
[pid=226][err]   "switch-12" = "--allow-pre-commit-input"
[pid=226][err]   "switch-11" = "--disable-features=ImprovedCookieControls,LazyFrameLoading,Globa"
[pid=226][err]   "switch-10" = "--disable-extensions"
[pid=226][err]   "switch-9" = "--disable-dev-shm-usage"
[pid=226][err]   "switch-8" = "--disable-default-apps"
[pid=226][err]   "switch-7" = "--disable-component-extensions-with-background-pages"
[pid=226][err]   "switch-6" = "--disable-client-side-phishing-detection"
[pid=226][err]   "switch-5" = "--disable-breakpad"
[pid=226][err]   "switch-4" = "--disable-backgrounding-occluded-windows"
[pid=226][err]   "switch-3" = "--disable-background-timer-throttling"
[pid=226][err]   "switch-2" = "--enable-features=NetworkService,NetworkServiceInProcess"
[pid=226][err]   "switch-1" = "--disable-background-networking"
[pid=226][err]   "num-switches" = "31"
[pid=226][err]   "osarch" = "x86_64"
[pid=226][err]   "pid" = "226"
[pid=226][err]   "ptype" = "browser"
[pid=226][err]
[pid=226][err] [1028/195405.736318:ERROR:file_io_posix.cc(144)] open /sys/devices/system/cpu/cpu0/cpufreq/scaling_cur_freq: No such file or directory (2)
[pid=226][err] [1028/195405.736388:ERROR:file_io_posix.cc(144)] open /sys/devices/system/cpu/cpu0/cpufreq/scaling_max_freq: No such file or directory (2)

Below you can find my DockerFile, I am also installing manually missing dependencies for my docker image.

#See https://aka.ms/containerfastmode to understand how Visual Studio uses this Dockerfile to build your images for faster debugging.
FROM mcr.microsoft.com/dotnet/runtime:5.0-buster-slim AS base
WORKDIR /app

FROM mcr.microsoft.com/dotnet/sdk:5.0-buster-slim AS build
WORKDIR /src
COPY ["Agent.csproj", "Agent/"]
RUN dotnet restore "Agent/Agent.csproj"
COPY . "/src/Agent"
WORKDIR "/src/Agent"
RUN apt-get update -yq && apt-get upgrade -yq && apt-get install -yq curl git nano
RUN curl -sL https://deb.nodesource.com/setup_16.x | bash - && apt-get install -yq nodejs build-essential
RUN npm install -g npm
RUN apt-get install -y gstreamer1.0-libav libnss3-tools libatk-bridge2.0-0 libcups2-dev libxkbcommon-x11-0 libxcomposite-dev libxrandr2 libgbm-dev libgtk-3-0
    
RUN dotnet add package Microsoft.Playwright --version 1.15.2
RUN dotnet build "Agent.csproj" -c Release -o /app/build
RUN npm add [email protected]

FROM build AS publish
RUN dotnet publish "Agent.csproj" -c Release -o /app/publish

Source: Docker Questions

LEAVE A COMMENT